/* ============================================================
   TOKENS
   Semantic, not literal. Every colour in the app resolves to
   one of these. If you ever write a raw hex below this block,
   it is a bug.
   ============================================================ */

:root {
  --page:            #F6F6F7;
  --surface:         #FFFFFF;
  --surface-hover:   #F4F4F5;
  --surface-sunken:  #F0F0F2;
  --card-border:     #ECECEE;
  --pill-bg:         #FFFFFF;
  --pill-shadow:     0 1px 2px rgba(15,15,20,.07);

  --line:            #E8E8EA;
  --content:         #151515;
  --content-secondary:#757575;
  --content-muted:   #A5A5A5;

  --accent:          #5B3DF5;
  --accent-soft:     #EFECFF;
  --accent-contrast: #FFFFFF;

  --positive:        #0E9F6E;
  --negative:        #D92D20;

  --shadow-card:     0 1px 2px rgba(15,15,20,.04);
  --color-scheme:    light;
}

[data-theme="dark"] {
  --page:            #0B0B0D;
  --surface:         #1A1A1E;
  --surface-hover:   #232329;
  --surface-sunken:  #232329;
  --card-border:     transparent;
  --pill-bg:         #24242A;
  --pill-shadow:     none;

  --line:            #2A2A30;
  --content:         #F5F5F7;
  --content-secondary:#9A9AA3;
  --content-muted:   #6B6B75;

  --accent:          #8B5CF6;
  --accent-soft:     #201A38;
  --accent-contrast: #FFFFFF;

  --positive:        #34D399;
  --negative:        #F87171;

  --shadow-card:     none;
  --color-scheme:    dark;
}

/* ============================================================
   BASE
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--page);
  color-scheme: var(--color-scheme);   /* makes native pickers + scrollbars follow */
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: 104px;               /* room for the FAB */
  background: var(--page);
  color: var(--content);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.mono, .card-value, .expense-amount, time {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

button { font: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ============================================================
   HEADER
   ============================================================ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 14px;
  font-weight: 600;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--content-secondary);
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--content); }

/* Show one icon per theme */
.ico-moon { display: none; }
[data-theme="dark"] .ico-sun  { display: none; }
[data-theme="dark"] .ico-moon { display: block; }

/* ============================================================
   SEGMENTED CONTROL
   ============================================================ */

.segmented {
  display: flex;
  gap: 4px;
  padding: 6px 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }

.segmented button {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--content-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.segmented button[aria-pressed="true"] {
  background: var(--pill-bg);
  color: var(--content);
  box-shadow: var(--pill-shadow);
}

/* ============================================================
   CARD GRID
   ============================================================ */

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px 0;
}

.card {
  min-width: 0;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-card);
}

.card--wide { grid-column: 1 / -1; }

.card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--content-secondary);
}
.card-label svg { flex: 0 0 auto; opacity: .85; }

.card-value {
  margin: 0;
  font-size: 26px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--content);
}
.card-value--hero { font-size: 40px; }

.card-note {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--content-secondary);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 500;
}
.delta.is-good { color: var(--positive); }
.delta.is-bad  { color: var(--negative); }
.delta svg { flex: 0 0 auto; }

/* ============================================================
   SECTION HEAD
   ============================================================ */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 26px 16px 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.link-btn {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 12px;
  color: var(--content-secondary);
  cursor: pointer;
}
.link-btn:hover { color: var(--content); }

/* ============================================================
   EXPENSE LIST
   ============================================================ */

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

.expense-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: background-color 150ms ease-out;
}
.expense-row:hover { background: var(--surface-hover); }

.expense-left { min-width: 0; }

.expense-note {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--content);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--content-secondary);
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-sunken);
  font-size: 11px;
  font-weight: 500;
  color: var(--content-secondary);
  white-space: nowrap;
}

.expense-amount {
  font-size: 14px;
  font-weight: 500;
  color: var(--content);
  white-space: nowrap;
}

/* ============================================================
   EXPORT CARD
   ============================================================ */

.export-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 16px 0;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-card);
}

.export-icon {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--surface-sunken);
  color: var(--content-secondary);
}

.export-text { min-width: 0; flex: 1; }

.export-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--content);
}

.export-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--content-secondary);
}

.export-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  transition: transform 150ms ease-out, filter 150ms ease-out;
}
.export-btn:hover  { filter: brightness(1.08); }
.export-btn:active { transform: scale(.94); }

/* ============================================================
   FAB
   ============================================================ */

.fab {
  position: fixed;
  right: max(16px, calc((100vw - 600px) / 2 + 16px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 17px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 38%, transparent);
  transition: transform 150ms ease-out;
}
.fab:hover  { filter: brightness(1.06); }
.fab:active { transform: scale(.95); }
