/* Meter Tracker - tokens, then components. See docs/design.md */
:root {
  --bg: #F4F6F9; --surface: #FFFFFF; --surface-2: #EEF1F6; --text: #0F172A; --muted: #556072; --border: #D9DFE8;
  --accent: #0E7C66; --on-accent: #FFFFFF; --accent-soft: #DDF3EC; --warn: #B45309; --warn-soft: #FEF3C7; --danger: #C62828; --danger-soft: #FDE8E8; --good: #15803D; --good-soft: #DCFCE7;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06); --scrim: rgba(15,23,42,.45);
  --r-lg: 16px; --r-md: 12px; --gutter: 16px; --tabh: 64px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F172A; --surface: #1B2336; --surface-2: #272F42; --text: #F8FAFC; --muted: #9AA7BC; --border: #38435A;
    --accent: #34D399; --on-accent: #06281D; --accent-soft: #123B33; --warn: #FBBF24; --warn-soft: #3A2E0B; --danger: #F87171; --danger-soft: #3F1B1F; --good: #4ADE80; --good-soft: #12351F;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --scrim: rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F172A; --surface: #1B2336; --surface-2: #272F42; --text: #F8FAFC; --muted: #9AA7BC; --border: #38435A;
  --accent: #34D399; --on-accent: #06281D; --accent-soft: #123B33; --warn: #FBBF24; --warn-soft: #3A2E0B; --danger: #F87171; --danger-soft: #3F1B1F; --good: #4ADE80; --good-soft: #12351F;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --scrim: rgba(0,0,0,.6); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 var(--font); font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent; min-height: 100dvh; }
body.noscroll { overflow: hidden; }
h1, h2, h3, p, dl, dd, ul, figure { margin: 0; padding: 0; }
ul { list-style: none; }
h1 { font-size: 28px; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
h3 { font-size: 18px; font-weight: 700; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1:focus { outline: none; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--on-accent); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); } .sm { font-size: 14px; } .center { text-align: center; } .block { display: block; } .grow { flex: 1; min-width: 0; }
.pad { padding: 4px 0 12px; }

/* shell */
#view { max-width: 640px; margin: 0 auto; padding: calc(var(--sat) + 12px) calc(var(--gutter) + var(--sar)) calc(var(--tabh) + var(--sab) + 28px) calc(var(--gutter) + var(--sal)); outline: none; }
.demo-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 13px; font-weight: 600; padding: calc(var(--sat) + 4px) 8px 4px; }
.demo-banner + #view { padding-top: 12px; }
.view { display: flex; flex-direction: column; gap: 14px; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding-top: 4px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.eyebrow.inv { color: inherit; opacity: .85; }
.detail-head { justify-content: flex-start; }
.detail-head h1 { font-size: 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* tab bar */
.tabbar { position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center; max-width: 640px; margin: 0 auto; height: calc(var(--tabh) + var(--sab)); padding: 0 var(--sal) var(--sab) var(--sar); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; color: var(--muted); font-size: 12px; font-weight: 600; border-radius: 12px; transition: color .15s; }
.tab[aria-current="page"] { color: var(--accent); }
.fab { justify-self: center; width: 56px; height: 56px; margin-top: -26px; border: 4px solid var(--bg); border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 6px 16px rgba(14,124,102,.35); transition: transform .15s; }
.fab:active { transform: scale(.94); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.sec { padding: 16px; }
.hero { background: linear-gradient(135deg, #0E7C66, #0B5D4E); color: #fff; border-radius: var(--r-lg); padding: 18px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.hero-num { font-size: 40px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.hero-side { text-align: right; font-size: 14px; display: flex; flex-direction: column; opacity: .95; } .hero-side strong { font-size: 20px; }
.meter-card { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; border-left: 5px solid var(--mc); }
.meter-card.flash { animation: flash 1s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--mc); } 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--mc) 40%, transparent); } 100% { box-shadow: var(--shadow); } }
.mc-head { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.mc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.mc-title strong { font-size: 18px; } .mc-title small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-main { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.big-num { font-size: 34px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.unit { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; } .dot.lg { width: 14px; height: 14px; }
.spark, .spark-empty { width: 120px; height: 36px; flex: none; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stats dt, .tile dt { font-size: 12px; color: var(--muted); font-weight: 600; } .stats dd { font-size: 14px; font-weight: 700; }
@media (max-width: 380px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.tile { background: var(--surface-2); border-radius: var(--r-md); padding: 10px 12px; display: flex; flex-direction: column; }
.tile dd { font-size: 18px; font-weight: 700; } .tile small { color: var(--muted); font-size: 12px; }
.budget { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; } .progress span { display: block; height: 100%; border-radius: 99px; transition: width .4s ease-out; }

/* badges, chips */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.good { background: var(--good-soft); color: var(--good); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 99px; border: 1.5px solid var(--border); background: var(--surface); font-weight: 600; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }
.chip.bucket { min-height: 36px; background: var(--accent-soft); border-color: transparent; color: var(--text); cursor: default; width: fit-content; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: var(--r-md); border: 1.5px solid var(--border); background: var(--surface); font-weight: 700; transition: transform .1s, background .15s; }
.btn:active:not(:disabled) { transform: scale(.98); } .btn:disabled { opacity: .6; cursor: default; }
.btn.small { min-height: 44px; padding: 0 16px; font-size: 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.tonal { background: var(--accent-soft); border-color: transparent; color: var(--text); align-self: flex-start; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); } .btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 50%; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }
.btn-row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; } .btn-row .btn { flex: 1 1 auto; }

/* lists */
.list { overflow: hidden; } .row { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding-right: 6px; } .row:last-child { border: 0; }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 14px 8px 14px 16px; min-height: 64px; }
.row-text { display: flex; flex-direction: column; min-width: 0; } .row-text small { color: var(--muted); font-size: 13px; }
.plain > li + li { border-top: 1px solid var(--border); }
.ins-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; min-height: 44px; } .ins-row.link { color: inherit; }
.spike { display: flex; align-items: center; gap: 10px; padding: 10px 0; color: var(--warn); } .spike strong { margin-left: auto; color: var(--text); } .spike small { color: var(--muted); min-width: 64px; text-align: right; }
.history { display: flex; flex-direction: column; } .hist { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); } .hist:first-child { border: 0; }
.hist.pending { opacity: .55; } .hist-main { min-width: 0; } .hist .num { font-size: 18px; }
.hist .muted svg { vertical-align: -3px; margin-right: 2px; } .note { font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.delta { color: var(--good); font-weight: 700; font-size: 13px; margin-left: 8px; }
.srow { display: flex; align-items: center; gap: 12px; padding: 10px 0; min-height: 56px; } .srow + .srow { border-top: 1px solid var(--border); } .srow > svg { color: var(--muted); }
.profile { display: flex; align-items: center; gap: 14px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 20px; overflow: hidden; flex: none; } .avatar img { width: 100%; height: 100%; object-fit: cover; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: var(--r-md); padding: 4px; gap: 4px; }
.seg button { min-height: 44px; border: 0; background: transparent; border-radius: 9px; font-weight: 600; color: var(--muted); } .seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* charts */
.chart-wrap { display: flex; flex-direction: column; gap: 6px; }
.chart { width: 100%; height: auto; overflow: visible; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; } .chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .flag { fill: var(--warn); font-size: 10px; font-weight: 700; font-family: var(--font); }
.chart .bar { transition: opacity .15s; } .chart .bar.sel { stroke: var(--text); stroke-width: 1.5; }
.chart .hit { cursor: pointer; } .chart .hit:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chart-readout { font-size: 14px; font-weight: 600; min-height: 22px; color: var(--muted); }
.legend { font-size: 13px; color: var(--muted); margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.sw.hatch { width: 16px; height: 12px; border-radius: 3px; border: 1px solid var(--c); background: repeating-linear-gradient(45deg, var(--c) 0 2px, transparent 2px 5px); }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: 104px 1fr auto; align-items: center; gap: 10px; }
.hb-label { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; min-width: 0; } .hb-label svg { color: var(--muted); flex: none; }
.hb-track { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; } .hb-fill { display: block; height: 100%; background: var(--c); border-radius: 99px; opacity: .8; } .hb-fill.top { opacity: 1; background: var(--warn); }
.hb-fill.hatched { background: repeating-linear-gradient(45deg, var(--c) 0 3px, color-mix(in srgb, var(--c) 35%, transparent) 3px 6px); }
.hb-val { font-size: 13px; font-weight: 700; min-width: 64px; text-align: right; }
.cmp { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; } .cmp-row { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center; font-size: 13px; } .cmp-l { color: var(--muted); font-weight: 600; }

/* sheets */
#overlay { position: relative; z-index: 50; }
.backdrop { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .2s ease-out; }
.backdrop.open { opacity: 1; }
.backdrop.dialog { align-items: center; padding: 20px; }
.panel { background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; border-radius: 24px 24px 0 0; padding: 8px 20px calc(20px + var(--sab)); transform: translateY(40px); transition: transform .25s cubic-bezier(.2,.8,.2,1); outline: none; }
.backdrop.open .panel { transform: none; }
.panel.dialog { border-radius: 20px; padding: 20px; max-width: 400px; transform: scale(.96); }
.panel-head { position: sticky; top: -8px; background: var(--surface); z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 0 8px; margin-top: -8px; }
.panel.sheet .panel-head { padding-top: 22px; } .panel-head h2 { margin: 0; font-size: 20px; }
.grabber { position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; background: var(--border); border-radius: 4px; }
.dialog-msg { margin: 6px 0 18px; color: var(--muted); }
@media (min-width: 700px) { .backdrop { align-items: center; } .panel { border-radius: 24px; } }

/* forms */
.form { display: flex; flex-direction: column; gap: 16px; padding-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; } .field-label { font-size: 14px; font-weight: 600; }
.field input[type=text], .field input[type=date], .field input[type=time], .field select { width: 100%; min-height: 48px; padding: 0 14px; background: var(--surface-2); border: 1.5px solid transparent; border-radius: var(--r-md); }
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.field-hint, .prev { font-size: 13px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.value-wrap { position: relative; } .big-input { font-size: 32px !important; font-weight: 800; min-height: 64px !important; padding-right: 64px !important; letter-spacing: -.01em; }
.unit-suffix { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; pointer-events: none; }
.tod { display: flex; align-items: center; justify-content: space-between; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; } .check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.warn-box { background: var(--warn-soft); color: var(--text); border: 1px solid var(--warn); border-radius: var(--r-md); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; font-size: 14px; } .warn-title { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--warn); }
.warn-box[hidden], .form-error[hidden] { display: none; }
.form-error { color: var(--danger); font-size: 14px; font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; } .swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; background: var(--c); color: #fff; display: grid; place-items: center; padding: 0; }
.swatch.on { border-color: var(--surface); box-shadow: 0 0 0 2.5px var(--text); }

/* states, toasts, login */
.state-block { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 16px; } .state-block p { color: var(--muted); max-width: 320px; }
.state-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.skeletons { display: flex; flex-direction: column; gap: 14px; } .skeleton-card { height: 190px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + var(--sab) + 16px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: 14px; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; }
.toast.in { opacity: 1; transform: none; } .toast.error { background: var(--danger); color: #fff; } .toast svg { flex: none; }
.login, .boot { min-height: 100dvh; display: grid; place-items: center; padding: calc(var(--sat) + 20px) 20px calc(var(--sab) + 20px); }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.logo { width: 72px; height: 72px; border-radius: 22px; background: var(--accent); color: #FBBF24; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(14,124,102,.3); }
.gsi-slot { min-height: 48px; display: flex; justify-content: center; align-items: center; margin: 8px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
.icon { flex: none; }

@media (hover: hover) { .btn:hover:not(:disabled) { background: var(--surface-2); } .btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); } .chip:hover { border-color: var(--accent); } .tab:hover { color: var(--text); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* sharing */
.badge.shared { background: var(--accent-soft); color: var(--text); margin-left: 0; }
.badge-row { margin: -4px 0 8px; }
.shared-card { display: flex; flex-direction: column; gap: 6px; }
.shared-top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.shared-line { display: inline-flex; align-items: center; gap: 4px; }
.field input[type=email] { width: 100%; min-height: 48px; padding: 0 14px; background: var(--surface-2); border: 1.5px solid transparent; border-radius: var(--r-md); }
.field input[type=email]:focus { border-color: var(--accent); outline: none; background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.inline-add { display: flex; gap: 8px; align-items: stretch; } .inline-add input { flex: 1; min-width: 0; } .inline-add .btn { flex: none; }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.share-body { display: flex; flex-direction: column; gap: 14px; }
.share-h { font-size: 15px; margin-top: 4px; }
.share-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 12px; color: var(--muted); background: var(--surface-2); border-radius: var(--r-md); text-align: center; }
.share-list { display: flex; flex-direction: column; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); min-height: 60px; } .share-row:first-child { border: 0; }
.ellip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar.sm { width: 36px; height: 36px; font-size: 14px; flex: none; }
.role-select { min-height: 44px; padding: 0 10px; border-radius: var(--r-md); border: 1.5px solid var(--border); background: var(--surface-2); font-weight: 600; flex: none; }
.role-select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.detail-head .btn.small { flex: none; padding: 0 12px; }
