/* Shared look for Gab's apps. Gab's views use his forest palette, Chloe's use her pinks. */

:root,
[data-theme="gab"] {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #e4e8e3;
  --line: #d3d9d2;
  --text: #1c332d;
  --muted: #4b6357;
  --accent: #365545;
  --on-accent: #f3f5f2;
  --hero: #1c332d;
  --on-hero: #e6ebe6;
  --hero-muted: #aab5af;
  --mark-work: #5f7a6b;
  --mark-income: #9ca7a1;
  --danger: #a33a2f;
  --shadow: 0 1px 2px rgb(28 51 45 / 0.06), 0 4px 16px rgb(28 51 45 / 0.06);
  color-scheme: light;
}

[data-theme="chloe"] {
  --bg: #fff6f8;
  --surface: #ffffff;
  --surface-2: #ffe9ef;
  --line: #ffc9d7;
  --text: #4a1d2b;
  --muted: #8a3a55;
  --accent: #fc809f;
  --on-accent: #3d0f1e;
  --hero: #fc809f;
  --on-hero: #3d0f1e;
  --hero-muted: #5c1f33;
  --mark-work: #fc809f;
  --mark-income: #ffbccd;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(74 29 43 / 0.06), 0 4px 16px rgb(252 128 159 / 0.12);
}

/* Dark tokens apply with the system setting, or always when an app forces data-mode="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #14241f;
    --surface: #1c332d;
    --surface-2: #24403a;
    --line: #2f4c44;
    --text: #e6ebe6;
    --muted: #aab5af;
    --accent: #aab5af;
    --on-accent: #1c332d;
    --hero: #365545;
    --on-hero: #f3f5f2;
    --hero-muted: #bbc0b9;
    --mark-work: #9ca7a1;
    --mark-income: #5f7a6b;
    --danger: #e58a7f;
    --shadow: none;
    color-scheme: dark;
  }
  :root:not([data-mode="light"])[data-theme="chloe"] {
    --bg: #2b141b;
    --surface: #3a1c25;
    --surface-2: #4a2430;
    --line: #5a2d3b;
    --text: #ffe9ef;
    --muted: #ffbccd;
    --accent: #ff9cb5;
    --on-accent: #2b141b;
    --hero: #ff9cb5;
    --on-hero: #2b141b;
    --hero-muted: #5c1f33;
    --mark-work: #ff9cb5;
    --mark-income: #8a3a55;
    --danger: #ff9a8f;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-mode="dark"] {
  --bg: #14241f;
  --surface: #1c332d;
  --surface-2: #24403a;
  --line: #2f4c44;
  --text: #e6ebe6;
  --muted: #aab5af;
  --accent: #aab5af;
  --on-accent: #1c332d;
  --hero: #365545;
  --on-hero: #f3f5f2;
  --hero-muted: #bbc0b9;
  --mark-work: #9ca7a1;
  --mark-income: #5f7a6b;
  --danger: #e58a7f;
  --shadow: none;
  color-scheme: dark;
}
:root[data-mode="dark"][data-theme="chloe"] {
  --bg: #2b141b;
  --surface: #3a1c25;
  --surface-2: #4a2430;
  --line: #5a2d3b;
  --text: #ffe9ef;
  --muted: #ffbccd;
  --accent: #ff9cb5;
  --on-accent: #2b141b;
  --hero: #ff9cb5;
  --on-hero: #2b141b;
  --hero-muted: #5c1f33;
  --mark-work: #ff9cb5;
  --mark-income: #8a3a55;
  --danger: #ff9a8f;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.45 var(--font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 8px;
}
.top h1 { flex: 1; }
.stack > * + * { margin-top: 12px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 22px 4px 8px;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.hero {
  background: var(--hero);
  color: var(--on-hero);
  border-color: transparent;
}
.hero .muted { color: var(--hero-muted); }
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  min-width: 0;
}
.tile.hero { background: var(--hero); color: var(--on-hero); border-color: transparent; }
.tile .label { font-size: 0.78rem; color: var(--muted); }
.tile.hero .label { color: var(--hero-muted); }
.tile .value {
  margin-top: 4px;
  font-size: clamp(0.95rem, 4.3vw, 1.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- lists ---------- */

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.list > * + * { border-top: 1px solid var(--line); }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  background: none;
  border: 0;
  text-align: left;
}
button.row { cursor: pointer; }
.row > svg { flex: none; width: 20px; height: 20px; color: var(--muted); }
button.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; overflow-wrap: anywhere; }
.row .sub { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.row .amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.total { font-weight: 700; }
.row.total .sub { font-weight: 400; }
.row.total .amount { font-size: 1.05rem; }
.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--mark-work);
}
.dot.income { background: var(--mark-income); }
.dot.claim { background: transparent; border: 2px solid var(--mark-income); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.hero .btn.primary { background: var(--on-hero); border-color: var(--on-hero); color: var(--hero); }
.hero .btn:not(.primary) { background: transparent; border-color: color-mix(in srgb, var(--on-hero) 35%, transparent); color: var(--on-hero); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  flex: none;
}
.icon-btn svg, .btn svg, .tab svg { width: 20px; height: 20px; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }

.field { display: block; }
.field + .field, .field + .field-row, .field-row + .field, .field-row + .field-row { margin-top: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field > span {
  display: block;
  margin: 0 2px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px;
  appearance: none;
}
textarea.input { min-height: 80px; resize: vertical; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.hint { margin: 6px 2px 0; font-size: 0.8rem; color: var(--muted); }
.error-text { margin: 10px 2px 0; color: var(--danger); font-size: 0.9rem; font-weight: 550; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  gap: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}
.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
/* The chosen segment is filled, like the current tab (Gab msg 8748). */
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar-inner { display: flex; width: 100%; max-width: 640px; }
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 50px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
/* The current tab (Gab msg 8748, 27 Nov 2026): a filled pill behind its icon and a bolder label, so it
   reads by shape and contrast, not by a shade of green. */
.tab-ic {
  display: grid;
  place-items: center;
  width: 56px;
  height: 30px;
  border-radius: 999px;
}
.tab[aria-current="page"] { color: var(--text); font-weight: 700; }
.tab[aria-current="page"] .tab-ic { background: var(--accent); color: var(--on-accent); }
.fab {
  position: fixed;
  right: max(16px, calc(50% - 304px));
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  z-index: 11;
  width: 58px;
  height: 58px;
  border-radius: 20px;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- dialogs (bottom sheet on phones) ---------- */

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in 0.22s ease-out; }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.38); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.sheet[open] { animation: none; }
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 6px 20px;
}
.sheet-head h2 { flex: 1; font-size: 1.15rem; }
.sheet-body { padding: 8px 20px 12px; overflow-y: auto; }
.sheet-actions {
  display: flex;
  gap: 10px;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 16px);
  border-top: 1px solid var(--line);
}
.sheet-actions .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  z-index: 100;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 550;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- sign-in screen ---------- */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.auth .card { width: 100%; max-width: 400px; padding: 28px 22px; }
.auth-logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin-bottom: 16px; }
.auth h1 { margin-bottom: 4px; }
.auth form { margin-top: 20px; }
.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 0.9rem;
}
.banner .grow { flex: 1; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.danger-text { color: var(--danger); }
.note { margin: 0 2px 10px; }
.field-row > .field { margin-top: 0; }

/* Text choices (used by apps that offer them). Inputs stay at 16px so iPhones don't zoom in. */
:root[data-size="small"] { font-size: 14px; }
:root[data-size="large"] { font-size: 18px; }
:root[data-font="rounded"] { --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif; }
:root[data-font="serif"] { --font: ui-serif, "New York", Georgia, "Times New Roman", serif; }
:root[data-font="mono"] { --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
