/* ---------------------------------------------------------------------
   Tokens
--------------------------------------------------------------------- */
:root {
  --bg: #1b1f23;
  --surface: #242931;
  --surface-2: #2d333d;
  --surface-press: #20242b;
  --display-bg: #11141a;
  --display-fg: #f2c46d;
  --display-fg-dim: #8a6f3f;
  --accent: #5ec8b8;
  --accent-dark: #3fa393;
  --danger: #e4685d;
  --text: #eceef0;
  --text-dim: #8b939b;
  --text-faint: #5b6168;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-display: "IBM Plex Mono", "SF Mono", monospace;
  --font-ui: "Manrope", -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0 0 48px;
}

.app {
  width: 100%;
  max-width: 430px;
  padding: 18px 16px 0;
}

/* ---------------------------------------------------------------------
   Header
--------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 14px;
  position: relative;
}

.date-nav button {
  background: var(--surface);
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
}

.date-nav button:active { background: var(--surface-press); }

.date-label {
  min-width: 92px;
  text-align: center;
  color: var(--text);
}

.date-label.is-today { color: var(--accent); }
.date-label { cursor: pointer; }

.date-picker-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.month-nav { justify-content: center; margin-bottom: 18px; }

/* ---------------------------------------------------------------------
   Summary view
--------------------------------------------------------------------- */
.summary-totals {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.summary-stat {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
}

.summary-stat-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.summary-stat-value {
  font-family: var(--font-display);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.summary-stat-value.income { color: var(--accent); }
.summary-stat-value.expense { color: var(--danger); }
.summary-stat-value.negative { color: var(--danger); }

.trend-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 20px;
}

.trend-chart {
  width: 100%;
  height: 80px;
}

.trend-svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.trend-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trend-dot { fill: var(--accent); }

.trend-hover-dot {
  fill: var(--display-bg);
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.trend-hover-info {
  min-height: 15px;
  text-align: center;
  margin-bottom: 6px;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.trend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.trend-label-end.negative { color: var(--danger); }

.category-breakdown {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.cbr-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.cbr-name { color: var(--text); font-weight: 600; }

.cbr-amount {
  font-family: var(--font-display);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.cbr-bar-track {
  background: var(--surface);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.cbr-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* ---------------------------------------------------------------------
   Account toggle
--------------------------------------------------------------------- */
.segmented {
  display: flex;
  background: var(--surface);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}

.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
}

.segmented button.active {
  background: var(--surface-2);
  color: var(--text);
}

.segmented.tight { margin-bottom: 14px; }

/* ---------------------------------------------------------------------
   Balance bar
--------------------------------------------------------------------- */
.balance-bar {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 14px;
}

.balance-bar .balance-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.balance-values {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.balance-bar .balance-amount {
  font-family: var(--font-display);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.balance-bar .balance-amount.negative { color: var(--danger); }

.balance-now {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.balance-now.negative { color: var(--danger); }

.balance-bar .balance-edit {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 4px;
}

/* ---------------------------------------------------------------------
   Display panel (the signature element)
--------------------------------------------------------------------- */
.display {
  background: var(--display-bg);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #00000080;
}

.display::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 80% at 30% 0%, #f2c46d10, transparent 60%);
  pointer-events: none;
}

.display-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 2px;
  font-family: var(--font-display);
}

.display-currency {
  font-size: 22px;
  color: var(--display-fg-dim);
  margin-right: 6px;
}

.display-amount {
  font-size: 44px;
  color: var(--display-fg);
  font-weight: 500;
  letter-spacing: 0.01em;
  text-shadow: 0 0 18px #f2c46d40;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.display-amount.is-empty { color: var(--display-fg-dim); }

.display-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--text-faint);
}

.display-meta .category-tag {
  color: var(--accent);
  font-weight: 600;
}

.display-meta .category-tag.is-income { color: #d6b86b; }

/* ---------------------------------------------------------------------
   Category grid
--------------------------------------------------------------------- */
.section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 2px 8px;
  font-weight: 700;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  background: var(--surface);
  border: 1px solid transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  padding: 11px 4px;
  border-radius: var(--radius-md);
  text-align: center;
  line-height: 1.2;
}

.chip:active { background: var(--surface-press); }

.chip.selected {
  background: #5ec8b822;
  border-color: var(--accent);
  color: var(--accent);
}

.chip.add-chip {
  color: var(--text-faint);
  border: 1px dashed var(--text-faint);
  background: transparent;
}

.subcategory-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  outline: none;
}

.subcategory-input::placeholder { color: var(--text-faint); }
.subcategory-input:focus { border-color: var(--accent); }

.note-input { margin-top: -6px; }

/* ---------------------------------------------------------------------
   Numpad
--------------------------------------------------------------------- */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.numpad button {
  background: var(--surface);
  border: none;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 21px;
  padding: 16px 0;
  border-radius: var(--radius-md);
  box-shadow: 0 1px 0 #ffffff08 inset, 0 2px 4px #00000030;
}

.numpad button:active {
  background: var(--surface-press);
  box-shadow: none;
  transform: translateY(1px);
}

.numpad button.backspace { color: var(--danger); font-size: 17px; }

/* ---------------------------------------------------------------------
   Type toggle + submit
--------------------------------------------------------------------- */
.row-gap { display: flex; gap: 8px; margin-bottom: 10px; }
.row-gap .segmented { margin-bottom: 0; }

.submit-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #0e1a18;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  padding: 15px 0;
  border-radius: var(--radius-md);
  margin-bottom: 22px;
  transition: opacity 0.15s;
}

.submit-btn:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
}

.submit-btn:active:not(:disabled) { opacity: 0.85; }

.submit-btn.is-editing { background: #d6b86b; }

/* ---------------------------------------------------------------------
   Totals + list
--------------------------------------------------------------------- */
.totals-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}

.totals-bar .totals-title {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.totals-bar .totals-amount {
  font-family: var(--font-display);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.totals-amount.negative { color: var(--danger); }
.totals-amount.positive { color: var(--accent); }
.totals-amount.zero { color: var(--text-dim); }

.split-line {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 14px;
}

.tx-list { display: flex; flex-direction: column; gap: 7px; }

.tx-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 11px 12px;
}

.tx-row .tx-account-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tx-account-dot.bank { background: var(--accent); }
.tx-account-dot.cash { background: #d6b86b; }

/* Dynamic account type colours */
.tx-account-dot[data-type="checking"]  { background: var(--accent); }
.tx-account-dot[data-type="savings"]   { background: #6db8f2; }
.tx-account-dot[data-type="cash"]      { background: #d6b86b; }
.tx-account-dot[data-type="investment"]{ background: #a86df2; }
.tx-account-dot[data-type="credit"]    { background: var(--danger); }

.tx-row .tx-main { flex: 1; min-width: 0; }

.tx-row .tx-category {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.tx-row .tx-sub {
  font-size: 12px;
  color: var(--text-faint);
}

.tx-row .tx-amount {
  font-family: var(--font-display);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.expense { color: var(--text); }
.tx-amount.income { color: var(--accent); }

.tx-row .tx-delete {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  padding: 2px 4px;
}

.tx-row.is-pending { opacity: 0.55; }
.tx-row.is-error .tx-amount { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 28px 10px;
  border: 1px dashed var(--surface-2);
  border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------
   Banner (config / sync warnings)
--------------------------------------------------------------------- */
.banner {
  background: #e4685d18;
  border: 1px solid #e4685d40;
  color: #f0a39c;
  font-size: 12.5px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  line-height: 1.4;
}

.banner code {
  background: #00000030;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-display);
}

.footer-status {
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 18px;
}

/* ---------------------------------------------------------------------
   Auth screen
--------------------------------------------------------------------- */
.auth-screen {
  padding-top: 40px;
}

.auth-screen .brand {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 28px;
}

.auth-copy {
  font-size: 13.5px;
  color: var(--text-dim);
  margin: 0 0 14px;
  line-height: 1.5;
}

.auth-copy strong { color: var(--text); }

.auth-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  outline: none;
}

.auth-input::placeholder { color: var(--text-faint); }
.auth-input:focus { border-color: var(--accent); }

.auth-code-input {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.18em;
  text-align: center;
}

.auth-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 0;
  text-align: center;
}

.auth-error {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 6px;
  min-height: 1em;
}

.auth-qr-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
  display: flex;
  justify-content: center;
}

.auth-qr-box img {
  width: 180px;
  height: 180px;
}

.auth-copy code {
  background: var(--surface);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 12px;
  word-break: break-all;
}

.sign-out-link {
  margin-top: 10px;
}

/* ---------------------------------------------------------------------
   Account selector row
--------------------------------------------------------------------- */
.account-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.account-selector {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.account-selector::-webkit-scrollbar { display: none; }

.acct-chip {
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.acct-chip:active { background: var(--surface-press); }
.acct-chip.active { background: var(--surface-2); color: var(--text); }

.acct-chip[data-type="checking"].active  { color: var(--accent); }
.acct-chip[data-type="savings"].active   { color: #6db8f2; }
.acct-chip[data-type="cash"].active      { color: #d6b86b; }
.acct-chip[data-type="investment"].active{ color: #a86df2; }
.acct-chip[data-type="credit"].active    { color: var(--danger); }

.acct-empty-hint {
  font-size: 12.5px;
  color: var(--text-faint);
  align-self: center;
}

.manage-accounts-btn {
  background: var(--surface);
  border: none;
  color: var(--text-faint);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  font-size: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.manage-accounts-btn:active { background: var(--surface-press); }

/* Colour the account tag in the display panel */
.display-meta [data-type="checking"]  { color: var(--accent); }
.display-meta [data-type="savings"]   { color: #6db8f2; }
.display-meta [data-type="cash"]      { color: #d6b86b; }
.display-meta [data-type="investment"]{ color: #a86df2; }
.display-meta [data-type="credit"]    { color: var(--danger); }

/* ---------------------------------------------------------------------
   Bottom sheet
--------------------------------------------------------------------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  justify-content: flex-end;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px 36px;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sheet-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.sheet-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 4px 6px;
  line-height: 1;
}

/* ---------------------------------------------------------------------
   Account management list (inside sheet)
--------------------------------------------------------------------- */
.acct-mgmt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

.acct-mgmt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.acct-mgmt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-faint);
}
.acct-mgmt-dot[data-type="checking"]  { background: var(--accent); }
.acct-mgmt-dot[data-type="savings"]   { background: #6db8f2; }
.acct-mgmt-dot[data-type="cash"]      { background: #d6b86b; }
.acct-mgmt-dot[data-type="investment"]{ background: #a86df2; }
.acct-mgmt-dot[data-type="credit"]    { background: var(--danger); }

.acct-mgmt-info {
  flex: 1;
  min-width: 0;
}

.acct-mgmt-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.acct-mgmt-meta {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 2px;
  text-transform: capitalize;
}

.acct-mgmt-edit {
  background: none;
  border: 1px solid var(--surface-2);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
}

/* ---------------------------------------------------------------------
   Account form (inside sheet)
--------------------------------------------------------------------- */
.form-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: -4px;
}

.form-select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b939b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.form-select:focus { border-color: var(--accent); }

.danger-btn {
  width: 100%;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  padding: 13px 0;
  border-radius: var(--radius-md);
  margin-bottom: 0;
}
