:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --income: #22c55e;
  --expense: #ef4444;
  --accent: #6366f1;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.balance-card {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.3);
}

.balance-label { color: rgba(255, 255, 255, 0.75); font-size: 15px; }

.balance {
  font-size: 44px;
  font-weight: 700;
  margin: 8px 0 12px;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.balance.negative { color: #fecaca; }

.totals {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.action {
  height: 72px;
  border: none;
  border-radius: 20px;
  font-size: 40px;
  font-weight: 300;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, filter 0.1s;
}

.action:active { transform: scale(0.96); filter: brightness(0.9); }
.action-income { background: var(--income); }
.action-expense { background: var(--expense); }

.history h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-date {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 4px 0;
}

.op {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 16px;
  padding: 12px 14px;
}

.op-icon {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 600;
}

.op.income .op-icon { background: rgba(34, 197, 94, 0.15); color: var(--income); }
.op.expense .op-icon { background: rgba(239, 68, 68, 0.15); color: var(--expense); }

.op-body { flex: 1; min-width: 0; }

.op-comment {
  overflow-wrap: anywhere;
  font-size: 15px;
}

.op-comment.empty { color: var(--muted); font-style: italic; }

.op-time { color: var(--muted); font-size: 12px; margin-top: 2px; }

.op-amount {
  flex: none;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.op.income .op-amount { color: var(--income); }
.op.expense .op-amount { color: var(--expense); }

.op-delete {
  flex: none;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 8px;
}

.op-delete:hover { color: var(--text); background: var(--card-2); }

.history-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

/* Dialog */
.op-dialog {
  width: min(440px, calc(100vw - 32px));
  border: none;
  border-radius: 20px;
  padding: 20px;
  background: var(--card);
  color: var(--text);
}

.op-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.op-dialog h3 { margin: 0 0 16px; font-size: 20px; }
.op-dialog.income h3 { color: var(--income); }
.op-dialog.expense h3 { color: var(--expense); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { color: var(--muted); font-size: 13px; }

.field input,
.field textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  resize: none;
}

.field input:focus,
.field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

#op-amount { font-size: 24px; font-weight: 600; }

.dialog-buttons { display: flex; gap: 10px; margin-top: 6px; }

.btn {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary { background: var(--card-2); color: var(--text); }
.btn-primary { color: #fff; background: var(--accent); }
.op-dialog.income .btn-primary { background: var(--income); }
.op-dialog.expense .btn-primary { background: var(--expense); }
