:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --surface-2: #f4ece0;
  --ink: #2b1d14;
  --ink-2: #6b5646;
  --line: #e7dccb;
  --accent: #8a4b2a;
  --accent-ink: #ffffff;
  --accent-soft: #f1dfcf;
  --good: #2f7d4f;
  --bad: #b3402a;
  --warn: #9a6a00;
  --warn-bg: #fff3d6;
  --bar: #c9833f;
  --bar-2: #e9c9a0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 30, 10, .08), 0 4px 14px rgba(60, 30, 10, .06);
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1410; --surface: #261c16; --surface-2: #31241c; --ink: #f3e9dd; --ink-2: #b9a794;
    --line: #3d2e24; --accent: #e4a15f; --accent-ink: #2b1d14; --accent-soft: #3d2a1b;
    --good: #6cc48d; --bad: #f08a72; --warn: #f0c55a; --warn-bg: #3a2e12;
    --bar: #e4a15f; --bar-2: #6e4c2c; --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hide { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.wrap { flex-wrap: wrap; }

/* ---- layout shell ---- */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--accent); }
.main { padding: 16px; max-width: 920px; margin: 0 auto; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); text-decoration: none; color: var(--ink-2); font-size: .72rem; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--accent); }
@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-left: 220px; }
  .nav {
    top: 0; right: auto; width: 220px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    padding: 20px 10px; gap: 4px;
  }
  .nav::before { content: "NTRC Sale"; font-weight: 800; color: var(--accent); font-size: 1.2rem; padding: 0 12px 16px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; height: 44px; padding: 0 12px; border-radius: 10px; font-size: .95rem; }
  .nav a.active { background: var(--accent-soft); }
  .topbar .brand { display: none; }
  .main { padding: 24px; }
}

/* ---- components ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > .card { margin: 0; }
.hero { background: var(--accent); color: var(--accent-ink); border: 0; }
.hero .muted { color: inherit; opacity: .8; }
.hero .big { font-size: 2.1rem; font-weight: 800; line-height: 1.1; }
.delta { font-size: .85rem; font-weight: 700; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }
.hero .delta.up, .hero .delta.down { color: inherit; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.pill.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: .92rem; }
.notice.bad { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad); }
.notice.ok { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .nav a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=password], input[type=number], input[type=search], select {
  min-height: 46px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); width: 100%;
}
input.cell { min-height: 36px; padding: 0 8px; text-align: right; width: 110px; border-radius: 8px; }
select.sm { min-height: 38px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: transparent; border-radius: 9px; font-weight: 700; color: var(--ink-2); cursor: pointer; padding: 0 10px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tabs button { flex: none; }

.list { display: flex; flex-direction: column; }
.list > .li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > .li:first-child { border-top: 0; padding-top: 0; }
.li .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 8px; border-radius: 99px; background: var(--bar-2); overflow: hidden; margin-top: 7px; }
.bar > i { display: block; height: 100%; background: var(--bar); border-radius: 99px; }
details.li > summary { list-style: none; cursor: pointer; }
details.li > summary::-webkit-details-marker { display: none; }
.sub { margin: 10px 0 0 12px; padding-left: 12px; border-left: 3px solid var(--bar-2); display: flex; flex-direction: column; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.r, th.r { text-align: right; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-2); font-size: 11px; }
.chart .bar-rect { fill: var(--bar); }
.chart .bar-rect.last { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px 16px; text-align: center; background: var(--surface);
}
.drop input[type=file] { display: none; }
.filechip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; font-size: .9rem; }

.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow: auto; }
@media (min-width: 900px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 80; font-weight: 600; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
@media (min-width: 900px) { #toast { bottom: 24px; } }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 10; }
@media (min-width: 900px) { .sticky-actions { bottom: 8px; } }
.spinner { padding: 40px; text-align: center; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

#acct { max-width: 124px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
#monthSel { min-width: 0; }
@media (max-width: 480px) { .topbar .brand { display: none; } }
