/* ---------- Design tokens ----------
   Coolors "Sunny Beach Day": charcoal #264653 · teal #2A9D8F · saffron #E9C46A
   · sandy orange #F4A261 · burnt sienna #E76F51.
   Charcoal leads; each section owns one palette colour. Light mode uses deeper
   versions of the pale colours so icons keep >= 3:1 contrast. */
:root {
  --bg: #faf7f2;            /* warm sand-white */
  --surface: #ffffff;
  --surface-2: #f2eee6;
  --text: #264653;          /* charcoal blue */
  --muted: #56676f;
  --border: #e6e0d4;
  --primary: #264653;
  --primary-hover: #1b3540;
  --on-primary: #ffffff;
  --accent: #c65438;
  --accent-soft: #fbe6df;
  --logo-bg: #2a9d8f;       /* teal: the palette's signature */
  --logo-ink: #ffffff;
  /* Section colours: icons, indicator lines, tints and data marks; never body text */
  --c-today: #264653;       /* charcoal */
  --c-expenses: #c65438;    /* burnt sienna, deepened */
  --c-habits: #23887c;      /* teal, deepened */
  --c-food: #a9831c;        /* saffron, deepened */
  --c-work: #b8692b;        /* sandy orange, deepened */
  --danger: #b83a27;
  --success: #1f7a70;
  --success-soft: #dcf0ed;
  --warn-soft: #fbefd3;
  --warn: #8a5a12;
  --danger-soft: #f9e0da;
  --focus: 0 0 0 3px rgba(42, 157, 143, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(38, 70, 83, 0.06), 0 2px 6px rgba(38, 70, 83, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12232b;          /* charcoal, deepened */
    --surface: #19303a;
    --surface-2: #213c48;
    --text: #f3efe7;
    --muted: #a8b7bd;
    --border: #2c4a57;
    --primary: #e9c46a;     /* saffron: the light accent on a dark ground */
    --primary-hover: #f0d48d;
    --on-primary: #264653;
    --accent: #ef8467;
    --accent-soft: #3f2a24;
    --logo-bg: #2a9d8f;
    --logo-ink: #ffffff;
    --c-today: #f3efe7;
    --c-expenses: #ef8467;
    --c-habits: #4cc0b1;
    --c-food: #e9c46a;
    --c-work: #f4a261;
    --danger: #f2917a;
    --success: #5cc9ba;
    --success-soft: #1d4542;
    --warn-soft: #3d3420;
    --warn: #ebc77a;
    --danger-soft: #45261f;
    --focus: 0 0 0 3px rgba(233, 196, 106, 0.45);
    --shadow: none;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { text-align: center; color: var(--muted); padding: 40vh 16px 0; margin: 0; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-google { background: var(--surface); border-color: var(--border); }
.btn-google:hover { background: var(--surface-2); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select {
  width: 100%; min-height: 44px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input:focus, select:focus { border-color: var(--primary); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner, .tabs, .content { max-width: 1000px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-name { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.avatar-fallback { display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-weight: 700; }

.logo {
  display: inline-grid; place-items: center;
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--logo-bg); color: var(--on-primary); font-size: 28px; font-weight: 700;
}
.logo-sm { width: 30px; height: 30px; border-radius: 8px; font-size: 16px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 6px; flex: none;
  padding: 10px 12px; border-bottom: 2px solid transparent;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--section); }
.tab[aria-current="page"] .icon { color: var(--section); stroke-width: 2.1; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.content { padding-top: 20px; padding-bottom: 48px; display: flex; flex-direction: column; gap: 16px; }
.page-title { font-size: 24px; display: flex; align-items: center; gap: 10px; }
.page-title .icon { width: 26px; height: 26px; color: var(--section); stroke-width: 2; }
.greeting { margin: -8px 0 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.section-head h2 { font-size: 17px; }
.section-head input { width: auto; }

.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.form-inline { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .btn { grid-column: 1 / -1; justify-self: start; }
  .form-inline { grid-template-columns: 1fr auto; align-items: end; }
}
@media (min-width: 900px) {
  .form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; align-items: end; }
  .form-grid .btn { grid-column: auto; }
}

/* ---------- Data display ---------- */
.empty { margin: 0; padding: 12px 0; color: var(--muted); text-align: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.stat { background: color-mix(in srgb, var(--section, var(--text)) 9%, var(--surface)); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.bars { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--c-expenses); border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; }

.group + .group, .stats + .group { margin-top: 16px; }
.group-head { display: flex; justify-content: space-between; font-size: 14px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-amount { font-variant-numeric: tabular-nums; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip-danger, .priority-high { background: var(--danger-soft); color: var(--danger); }
.priority-medium { background: var(--warn-soft); color: var(--warn); }
.priority-low { background: var(--success-soft); color: var(--success); }

/* Habits */
.table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
.habit-table { width: 100%; border-collapse: collapse; }
.habit-table th, .habit-table td { padding: 4px 2px; text-align: center; font-weight: 500; }
.habit-table thead th { font-size: 12px; color: var(--muted); }
.habit-table .habit-name { text-align: left; padding-right: 8px; min-width: 110px; overflow-wrap: anywhere; }
.habit-table tbody tr + tr { border-top: 1px solid var(--border); }
.habit-table .is-today { color: var(--section); }
.dow, .dom { display: block; }
.dom { font-weight: 700; }
.tick {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--border); background: transparent; color: var(--on-primary); font-weight: 700;
}
.tick:hover { border-color: var(--c-habits); }
.tick.is-done { background: var(--c-habits); border-color: var(--c-habits); color: var(--surface); }
.habit-title { display: block; font-weight: 600; }
.habit-meta { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.streak { white-space: nowrap; font-size: 13px; }
.icon-btn-sm { width: 28px; height: 28px; font-size: 12px; }
@media (max-width: 480px) {
  .habit-table .habit-name { min-width: 76px; }
  .habit-table th, .habit-table td { padding: 4px 1px; }
  .tick { width: 30px; height: 30px; }
}

/* Food */
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.day-label { text-align: center; }

.row-sub { display: block; font-size: 13px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.small { font-size: 13px; }
.manual > summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; padding: 4px 0 10px; }
.manual[open] > summary { color: var(--text); }

/* Food photo */
.photo-card { display: flex; flex-direction: column; gap: 14px; }
.photo-intro h2 { font-size: 17px; }
.photo-intro p { margin: 4px 0 0; }
.photo-controls { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .photo-controls { grid-template-columns: 1fr auto; } }

.photo-result { display: flex; gap: 14px; align-items: flex-start; }
.photo-thumb { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); flex: none; background: var(--surface-2); }
.photo-summary { min-width: 0; }
.photo-summary h3 { font-size: 16px; }
.photo-summary p { margin: 6px 0 0; }
.analyzing { display: flex; align-items: center; gap: 10px; margin: 0; align-self: center; }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.confidence-high { background: var(--success-soft); color: var(--success); }
.confidence-medium { background: var(--warn-soft); color: var(--warn); }
.confidence-low { background: var(--danger-soft); color: var(--danger); }
.review { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.review-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.review-item.is-excluded .review-check span { opacity: .45; }
.review-check { display: flex; gap: 10px; align-items: flex-start; flex: 1; min-width: 0; cursor: pointer; }
.review-check input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; flex: none; accent-color: var(--primary); }
.review-check strong { overflow-wrap: anywhere; }
.scale-select { width: 76px; flex: none; }
.review-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.review-total strong { font-size: 18px; }
.review-actions { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .review-actions { grid-template-columns: 160px auto auto; justify-content: start; } }

/* Work board */
.board { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .board { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; } }
.column-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; margin-bottom: 12px; }
.count { font-size: 12px; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 2px 8px; }
.column-doing { border-top: 3px solid var(--c-work); }
.column-done { border-top: 3px solid var(--success); }
.column-todo { border-top: 3px solid var(--muted); }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 10px 4px; }
.task-title { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
.column-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.task-actions { display: flex; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

/* Today */
.overview { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .overview { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 16px; }
.link { font-size: 14px; font-weight: 600; text-decoration: none; }
.checklist, .plain-list { list-style: none; margin: 0; padding: 0; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--c-habits); flex: none; }
.check span:nth-of-type(1) { flex: 1; }
.streak-sm { font-size: 13px; }
.plain-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 32px 24px; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.login-card h1 { font-size: 26px; }
.login-card p { margin: 0; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; text-align: left; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 50;
}

@media (max-width: 480px) {
  .user-name { display: none; }
  .bars li { grid-template-columns: 80px 1fr auto; }
}

/* Devanagari brand mark (न) */
.devanagari { font-family: "Kohinoor Devanagari", "Noto Sans Devanagari", "Mangal", var(--font); }
.logo svg { width: 100%; height: 100%; fill: none; stroke: var(--logo-ink); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.devanagari { font-weight: 500; color: var(--muted); }

/* Phones: tabs become a bottom bar (icon above label) so all five fit
   and sit under the thumb. */
@media (max-width: 640px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    max-width: none; margin: 0; overflow: visible;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tab {
    flex-direction: column; justify-content: center; gap: 3px;
    padding: 8px 0 7px; font-size: 11px; min-width: 0;
    border-bottom: 0; border-top: 2px solid transparent;
  }
  .tab[aria-current="page"] { border-top-color: var(--section); }
  .tab .icon { width: 22px; height: 22px; }
  .content { padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}

/* Section colour lookup: tabs, the current page and Today cards set --section */
[data-section="today"], .tab[data-tab="today"] { --section: var(--c-today); }
[data-section="expenses"], .tab[data-tab="expenses"] { --section: var(--c-expenses); }
[data-section="habits"], .tab[data-tab="habits"] { --section: var(--c-habits); }
[data-section="food"], .tab[data-tab="food"] { --section: var(--c-food); }
[data-section="work"], .tab[data-tab="work"] { --section: var(--c-work); }

/* Today cards: a tinted badge with the section icon */
.panel-head h2 { display: flex; align-items: center; gap: 10px; }
.icon-badge {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--section) 16%, transparent);
}
.icon-badge .icon { width: 18px; height: 18px; color: var(--section); stroke-width: 2; }

/* Multi-currency expenses */
.amount-row { display: flex; gap: 8px; }
.amount-row .currency-select { width: 104px; flex: none; }
.amount-row input { flex: 1; min-width: 0; }
.money-lines { display: flex; flex-direction: column; gap: 2px; }
.bar-group + .bar-group { margin-top: 14px; }
.bar-group-head { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 0 -8px; }
