/* Purchase dashboard. One token set, light + dark. */
:root {
  color-scheme: light;
  --bg: #F5F6F8; --surface: #FFFFFF; --surface-2: #EEF0F3; --line: #E2E5EA;
  --text: #12151A; --text-2: #5A6270; --text-3: #6B7280; --accent: #2F5BEA; --accent-soft: rgba(47,91,234,.10);
  --ok: #15803D; --ok-bg: #DCFCE7; --warn: #B45309; --warn-bg: #FEF3C7; --bad: #B91C1C; --bad-bg: #FEE2E2;
  /* shops: first three slots of the validated categorical palette (CVD-safe all-pairs, both modes) */
  --c-noodle: #2a78d6; --c-grill: #eb6834; --c-staff: #1baf7a; --c-buffet: #eda100; --c-other: #8C93A0;
  --shadow: 0 1px 2px rgba(16,24,40,.05);
  --hatch: repeating-linear-gradient(45deg, var(--line) 0 2px, transparent 2px 6px);
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sukhumvit Set", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0D0F12; --surface: #16191E; --surface-2: #1E2228; --line: #2A2F36;
    --text: #ECEEF2; --text-2: #A3ABB7; --text-3: #8C93A0; --accent: #7C9BFF; --accent-soft: rgba(124,155,255,.14);
    --ok: #4ADE80; --ok-bg: #0F2A1A; --warn: #FBBF24; --warn-bg: #33260A; --bad: #F87171; --bad-bg: #3A1414;
    --c-noodle: #3987e5; --c-grill: #d95926; --c-staff: #199e70; --c-buffet: #c98500;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0D0F12; --surface: #16191E; --surface-2: #1E2228; --line: #2A2F36;
  --text: #ECEEF2; --text-2: #A3ABB7; --text-3: #8C93A0; --accent: #7C9BFF; --accent-soft: rgba(124,155,255,.14);
  --ok: #4ADE80; --ok-bg: #0F2A1A; --warn: #FBBF24; --warn-bg: #33260A; --bad: #F87171; --bad-bg: #3A1414;
  --c-noodle: #3987e5; --c-grill: #d95926; --c-staff: #199e70; --c-buffet: #c98500;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 400 15px/24px var(--font);
  font-variant-numeric: tabular-nums lining-nums; min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .wrap { padding: 0 24px; } }
.num { font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.cap { font-size: 13px; line-height: 20px; }
.micro { font-size: 12px; line-height: 18px; font-weight: 500; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.title { font-size: 22px; line-height: 30px; font-weight: 600; }
.headline { font-size: 17px; line-height: 26px; font-weight: 600; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent; }
.top .wrap { display: flex; align-items: center; gap: 8px; height: 56px; }
.brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; white-space: nowrap; min-width: 0; }
.brand svg { width: 22px; height: 22px; flex: none; }
.brand .logo { width: 26px; height: 26px; border-radius: 8px; background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 13px; }
.spacer { flex: 1; }
.iconbtn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0;
  background: transparent; cursor: pointer; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-2); }
.iconbtn svg { width: 22px; height: 22px; }

/* bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs .wrap { display: grid; grid-template-columns: repeat(4, 1fr); height: 60px; }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; line-height: 16px; color: var(--text-3); font-weight: 500; position: relative; }
.tabs a svg { width: 22px; height: 22px; }
.tabs a.on { color: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* cards & sections */
.section { margin-top: 24px; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 2px 8px; }
.section-h h2 { font-size: 15px; line-height: 24px; color: var(--text-2); font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 16px; }
.card + .card { margin-top: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 8px; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.list > .li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px;
  border-top: 1px solid var(--line); }
.list > .li:first-child { border-top: 0; }
.list > a.li:active { background: var(--surface-2); }

/* chips & pills */
.chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 8px;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; line-height: 18px; font-weight: 500;
  white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.line { background: transparent; border: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 500; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.d-noodle { background: var(--c-noodle); } .d-grill { background: var(--c-grill); }
.d-staff { background: var(--c-staff); } .d-buffet { background: var(--c-buffet); } .d-other { background: var(--c-other); }

/* date nav */
.datenav { display: flex; align-items: center; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.datenav a, .datenav label { height: 44px; min-width: 44px; display: grid; place-items: center; border-radius: 12px; }
.datenav a:hover { background: var(--surface-2); }
.datenav a.off { opacity: .3; pointer-events: none; }
.datenav .label { position: relative; padding: 0 4px; font-weight: 600; font-size: 17px; cursor: pointer; white-space: nowrap; }
.datenav .chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.datenav input[type=date] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* hero */
.hero { padding: 20px 16px; }
.hero .big { font-size: 36px; line-height: 44px; font-weight: 600; letter-spacing: -.5px; }
@media (min-width: 960px) { .hero .big { font-size: 44px; line-height: 52px; } }

/* cash equation */
.eq { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 4px; text-align: center; }
.eq .t { background: var(--surface-2); border-radius: 12px; padding: 8px 4px; }
.eq .t b { display: block; font-size: 17px; line-height: 26px; font-weight: 600; }
.eq .op { color: var(--text-3); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 20px; padding: 4px 0; }
.ico { width: 18px; height: 18px; flex: none; }
.ok-c { color: var(--ok); } .warn-c { color: var(--warn); } .bad-c { color: var(--bad); }

/* alerts */
.alert { display: grid; grid-template-columns: 4px 1fr; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.alert + .alert { margin-top: 8px; }
.alert .bar { background: var(--text-3); }
.alert.bad .bar { background: var(--bad); } .alert.warn .bar { background: var(--warn); }
.alert .body { padding: 12px 14px; min-width: 0; }
.alert .msg { display: flex; gap: 10px; align-items: flex-start; }
.alert .msg p { margin: 0; flex: 1; font-size: 14px; line-height: 22px; }
.alert .msg p b { font-weight: 600; }
.alert .why { display: block; margin-top: 2px; color: var(--text-2); font-size: 13px; line-height: 20px; }
.alert .impact { font-weight: 600; font-size: 14px; white-space: nowrap; }
.alert .crop { margin-top: 8px; }
.alert .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.alert.done { opacity: .7; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { height: 48px; border-radius: 12px; font-size: 15px; width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
form.inline { display: inline; margin: 0; }

/* shop cards */
.shop { display: block; }
.shop .head { display: flex; align-items: center; gap: 8px; }
.shop .w { margin-left: auto; font-size: 20px; line-height: 28px; font-weight: 600; }
.catrows { margin-top: 10px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
  font-size: 13px; line-height: 20px; }
.catrows .track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.catrows .fill { height: 100%; border-radius: 3px; }
.f-noodle-bg { background: var(--c-noodle); } .f-grill-bg { background: var(--c-grill); }
.f-staff-bg { background: var(--c-staff); } .f-buffet-bg { background: var(--c-buffet); } .f-other-bg { background: var(--c-other); }
.shop.missing { border-style: dashed; background: var(--hatch), var(--surface); }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: 500 11px/1 var(--font); fill: var(--text-3); }
.chart text.on { fill: var(--text); font-weight: 600; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .sel { fill: none; stroke: var(--text); stroke-width: 1.5; }
.chart .hatch { fill: url(#hatch); }
.f-noodle { fill: var(--c-noodle); } .f-grill { fill: var(--c-grill); } .f-staff { fill: var(--c-staff); }
.f-buffet { fill: var(--c-buffet); } .f-other { fill: var(--c-other); }
.s-noodle { stroke: var(--c-noodle); } .s-grill { stroke: var(--c-grill); } .s-staff { stroke: var(--c-staff); }
.s-buffet { stroke: var(--c-buffet); } .s-other { stroke: var(--c-other); }
.pt { stroke: var(--surface); stroke-width: 2; }
.pt.hollow { fill: var(--surface); stroke-width: 1.5; }
.chart .band { fill: var(--accent); opacity: .12; }
.chart .median { stroke: var(--text-3); stroke-dasharray: 3 3; stroke-width: 1; }
.hatch-fill { fill: var(--line); }
.ev-ok { fill: var(--ok); } .ev-cand { fill: color-mix(in srgb, var(--ok) 45%, var(--surface)); }
.ev-gap { fill: var(--warn); } .ev-miss { fill: var(--surface); stroke: var(--bad); stroke-width: 1.5; }
.ev-market { fill: var(--text-3); opacity: .45; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; line-height: 18px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.spark { width: 84px; height: 24px; flex: none; }
.spark .dot { fill: var(--text-3); }
.spark .dot.last { fill: var(--text); }
.cashbar { height: 14px; margin-top: 12px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 10px;
  border-radius: 8px; font-size: 12px; line-height: 18px; max-width: 260px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  opacity: 0; transition: opacity .15s; }
.tip.on { opacity: 1; }

/* line rows (sheet) */
.vrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 16px;
  border-top: 1px solid var(--line); position: relative; cursor: pointer; }
.vrow:first-child { border-top: 0; }
.vrow:active { background: var(--surface-2); }
.vrow .crop { grid-column: 1 / -1; }
.vrow.bad::before, .vrow.warn::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.vrow.bad::before { background: var(--bad); } .vrow.warn::before { background: var(--warn); }
.vrow .name { font-weight: 600; font-size: 15px; line-height: 22px; }
.vrow .amt { font-weight: 600; font-size: 17px; line-height: 22px; text-align: right; }
.vrow .sub { font-size: 13px; line-height: 20px; color: var(--text-2); }
.vrow .note { grid-column: 1 / -1; font-size: 13px; line-height: 20px; }
a.crop { display: block; }
.crop img { display: block; width: 100%; height: auto; max-height: 64px; object-fit: cover; object-position: left center;
  border-radius: 8px; background: var(--surface-2); }
.u-q { text-decoration: underline dotted var(--warn); text-underline-offset: 3px; }

/* photo */
.photo { display: block; position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 16px; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.photo span { position: absolute; right: 8px; bottom: 8px; }
dialog.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #0b0c0e; color: #fff; display: none; flex-direction: column; }
dialog.viewer[open] { display: flex; }
dialog.viewer::backdrop { background: rgba(0,0,0,.9); }
.vbar { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255,255,255,.06); }
.vcap { flex: 1; font-size: 14px; font-weight: 500; }
.vbtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255,255,255,.12); color: #fff;
  font-size: 20px; display: grid; place-items: center; cursor: pointer; text-decoration: none; }
.vscroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.vstage { position: relative; width: 100%; margin: 0 auto; }
.vstage img { display: block; width: 100%; height: auto; }
.vmark { position: absolute; left: 0; right: 0; height: 3.4%; transform: translateY(-50%); pointer-events: none;
  border: 2px solid #FBBF24; border-radius: 6px; background: rgba(251,191,36,.12); }
.calcbtn { position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 25; width: 52px; height: 52px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: 0 4px 16px rgba(16,24,40,.14);
  display: grid; place-items: center; cursor: pointer; }
.calcbtn svg { width: 24px; height: 24px; }
.cdisp { margin-top: 10px; background: var(--surface-2); border-radius: 16px; padding: 12px 16px; text-align: right; }
.cexpr { min-height: 22px; font-size: 15px; color: var(--text-2); word-break: break-all; }
.cres { font-size: 36px; line-height: 44px; font-weight: 600; cursor: pointer; word-break: break-all; }
.chist { min-height: 18px; text-align: right; margin: 6px 4px 0; }
.ckeys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.ckeys button { height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 22px;
  font-weight: 500; cursor: pointer; }
.ckeys button:active { background: var(--surface-2); }
.ckeys .fn { color: var(--text-2); background: var(--surface-2); }
.ckeys .op { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.ckeys .eq { background: var(--accent); color: #fff; border-color: var(--accent); }


/* bottom sheet */
dialog.sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 640px; max-height: 92dvh;
  border-radius: 24px 24px 0 0; background: var(--surface); color: var(--text); }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 24px; } }
dialog.sheet::backdrop { background: rgba(10,12,16,.45); }
dialog.sheet .inner { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
dialog.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.field label { display: block; font-size: 12px; line-height: 18px; color: var(--text-2); font-weight: 500; margin-bottom: 4px; }
.field input, .field select { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); padding: 0 12px; font-size: 16px; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field.full { grid-column: 1 / -1; }
.calc { margin-top: 10px; font-size: 13px; color: var(--text-2); }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.reasons label { cursor: pointer; }
.reasons input { display: none; }
.reasons input:checked + span { background: var(--accent-soft); color: var(--accent); }

/* tables */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 20px; }
table.t th { text-align: left; font-weight: 500; color: var(--text-2); padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t .r { text-align: right; }
table.t tr:last-child td { border-bottom: 0; }

/* filters */
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters a { flex: none; }
.filters a.on .chip, .filters a.on.chip { background: var(--text); color: var(--bg); }

/* pin */
.pinpage { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 16px calc(32px + env(safe-area-inset-bottom)); }
.pinpage .head { text-align: center; margin-bottom: auto; padding-top: 12vh; }
.dots { display: flex; gap: 16px; justify-content: center; margin: 24px 0 8px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-3); }
.dots i.on { background: var(--text); border-color: var(--text); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 24px; justify-content: center; }
.keys button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--surface);
  box-shadow: var(--shadow); border: 1px solid var(--line); font-size: 26px; font-weight: 500; cursor: pointer; }
.keys button:active { background: var(--surface-2); }
.keys button.flat { background: transparent; border: 0; box-shadow: none; font-size: 15px; color: var(--text-2); }
.err { color: var(--bad); font-size: 13px; text-align: center; min-height: 20px; }

.empty { text-align: center; padding: 28px 16px; color: var(--text-2); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.foot { text-align: center; font-size: 12px; color: var(--text-3); margin: 32px 0 8px; }
.split { display: block; }
@media (min-width: 960px) {
  .wide .wrap { max-width: 1120px; }
  .split { display: grid; grid-template-columns: 440px 1fr; gap: 24px; align-items: start; }
  .split .sticky { position: sticky; top: 72px; }
  .split .photo { aspect-ratio: 3 / 4; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.chart .pline { fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linejoin: round; }
.chart text.vlabel { font-size: 12px; font-weight: 600; fill: var(--text); }
.chart text.tlabel { font-size: 12px; fill: var(--text-2); }
.chart .bar { fill: var(--accent); }
.spark .sline { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-linejoin: round; }
