/* Sale Support Monitor — wall display, 55" 16:9.
   Visual language follows the supplied mockup: light ground, large rounded
   cards, pastel icon chips, oversized coloured numerals, pill badges.
   The LAYOUT does not: the mockup is a phone screen (one narrow column, a
   thumb-operated tab bar, scrolls forever). On a wall nobody scrolls and
   nobody taps, so everything is reflowed into one landscape screen that
   never moves. */

:root {
  --bg-a: #f3f7ff;
  --bg-b: #e9f0fd;
  --card: #ffffff;
  --ink: #16224a;
  --ink-2: #2b3766;
  --ink-mid: #55628a;
  --ink-dim: #7d8aab;
  --hair: #e6ecf8;

  --blue:   #2f6bff;
  --green:  #12c07a;
  --orange: #ff9f1c;
  --purple: #a855f7;
  --pink:   #f2415f;
  --grey:   #98a4c0;

  --blue-s:   #e8efff;
  --green-s:  #e2f8f0;
  --orange-s: #fff3e0;
  --purple-s: #f5ebff;
  --pink-s:   #ffe9ee;
  --grey-s:   #eef1f7;

  --r: 1.05rem;
  --shadow: 0 .18rem .8rem rgba(30, 55, 120, .07);
  --thai: "Sarabun", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
/* One knob drives every size. At 1920 this lands near 22px, which reads
   cleanly from three or four metres; a 4K panel scales up to the cap instead
   of rendering the same page at half the apparent size. */
html {
  font-size: clamp(13px, 1.15vw, 30px);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(158deg, var(--bg-a) 0%, var(--bg-b) 100%);
  color: var(--ink);
  font-family: var(--thai);
  line-height: 1.6;          /* Thai stacks marks above and below; below ~1.55 they collide */
}

/* Mono carries no Thai glyphs, so a Thai string inside it silently falls back
   to a proportional face and columns stop lining up. Numbers only. */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.wall {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: .62rem;
  padding: .7rem 1rem .6rem;
}

/* ---- header --------------------------------------------------------- */

.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.head h1 {
  margin: 0; font-size: 1.85rem; font-weight: 700; letter-spacing: -.01em;
}
.head h1 .accent { color: var(--blue); }
.head .sub { font-size: .82rem; color: var(--ink-dim); margin-top: -.15rem; }

.headright { display: flex; align-items: center; gap: .6rem; }
.clock {
  background: var(--card); border-radius: .8rem; box-shadow: var(--shadow);
  padding: .35rem .95rem; font-family: var(--mono);
  font-size: 1.5rem; font-weight: 700; color: var(--ink-2);
}
.stamp {
  background: var(--card); border-radius: .8rem; box-shadow: var(--shadow);
  padding: .4rem .9rem; font-size: .74rem; color: var(--ink-dim); text-align: right;
}
.stamp b { color: var(--ink-2); font-weight: 600; }

/* ---- stat strip ------------------------------------------------------ */

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: .62rem; }
.stat {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: .6rem .85rem; display: flex; align-items: center; gap: .7rem; min-width: 0;
}
.chip {
  width: 2.5rem; height: 2.5rem; border-radius: .78rem; flex: none;
  display: grid; place-items: center;
}
.chip svg { width: 1.35rem; height: 1.35rem; }
.stat .body { min-width: 0; }
.stat .label { font-size: .8rem; color: var(--ink-mid); white-space: nowrap; }
.stat .value {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 2.05rem; font-weight: 700; line-height: 1.1;
}
.stat .foot { font-size: .7rem; color: var(--ink-dim); }

.c-blue   { background: var(--blue-s);   color: var(--blue); }
.c-green  { background: var(--green-s);  color: var(--green); }
.c-orange { background: var(--orange-s); color: var(--orange); }
.c-purple { background: var(--purple-s); color: var(--purple); }
.c-pink   { background: var(--pink-s);   color: var(--pink); }
.t-blue { color: var(--blue); } .t-green { color: var(--green); }
.t-orange { color: var(--orange); } .t-purple { color: var(--purple); }
.t-pink { color: var(--pink); } .t-ink { color: var(--ink); }

/* ---- main grid ------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  /* Row 2 carries the two tallest panels (the salesperson table and the
     five-row confirmation queue), so it gets the extra height. Getting this
     ratio wrong does not look wrong -- it just hides rows behind a scrollbar
     nobody on a wall will ever drag. */
  grid-template-rows: minmax(0, 1.08fr) minmax(0, 1.25fr);
  gap: .62rem;
  min-height: 0;
}

.card {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: .6rem .85rem .7rem;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.card > h2 {
  margin: 0 0 .4rem; font-size: .95rem; font-weight: 700;
  display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap;
}
.card > h2 .note { font-size: .72rem; font-weight: 400; color: var(--ink-dim); margin-left: auto; }
.card .fill { flex: 1; min-height: 0; overflow: auto; }

.a-kpi   { grid-column: span 4; }
.a-age   { grid-column: span 4; }
.a-type  { grid-column: span 4; }
.a-sale  { grid-column: span 8; }
.a-recon { grid-column: span 4; }

/* ---- gauges ---------------------------------------------------------- */

.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; height: 100%; min-height: 0; }
.gauge { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.gauge .gname { font-size: .78rem; color: var(--ink-mid); text-align: center; line-height: 1.35; }
.gauge .gcode {
  font-family: var(--mono); font-size: .62rem; letter-spacing: .1em;
  color: var(--ink-dim); margin-bottom: .1rem;
}
.gauge svg { width: 100%; max-width: 8.6rem; display: block; }
.arc-bg { fill: none; stroke: #eaeff9; stroke-width: 13; stroke-linecap: round; }
.arc-fg { fill: none; stroke-width: 13; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.arc-tick { stroke: var(--orange); stroke-width: 3; }

/* The percentage lives inside the SVG, not in a div pulled up over it with a
   negative margin. The margin version looked identical and broke the moment
   the row height changed by a few pixels — the number drifted out of the arc
   and the caption under it fell off the card. Here the two cannot separate. */
.gtext {
  font-family: var(--mono); font-weight: 700; font-size: 40px;
  text-anchor: middle; fill: var(--ink);
}
.gtext.pass { fill: var(--green); }
.gtext.fail { fill: var(--pink); }
.gtext.idle { fill: var(--grey); }

.gsub { font-size: .72rem; color: var(--ink-dim); text-align: center; line-height: 1.45; }
.gsub .gap { color: var(--pink); font-weight: 600; }
.gsub .ok { color: var(--green); font-weight: 600; }

/* Never signal pass/fail by hue alone — red and green at a distance, on a
   panel that may be dimmed or off-axis, is where colour vision stops helping. */
.badge {
  display: inline-flex; align-items: center; gap: .22rem;
  font-size: .68rem; font-weight: 600; border-radius: 999px;
  padding: .07rem .55rem; margin-top: .2rem;
}
.badge.pass { background: var(--green-s); color: var(--green); }
.badge.fail { background: var(--pink-s);  color: var(--pink); }
.badge.warn { background: var(--orange-s); color: var(--orange); }
.badge.idle { background: var(--grey-s);  color: var(--ink-dim); }

/* ---- aging ----------------------------------------------------------- */

.age { display: flex; flex-direction: column; gap: .18rem; }
.age-row { display: grid; grid-template-columns: 1fr 4.2rem; align-items: center; gap: .5rem; }
.age-top { display: flex; align-items: baseline; gap: .4rem; font-size: .8rem; }
.age-tag {
  font-size: .62rem; border-radius: 999px; padding: .02rem .45rem;
  background: var(--grey-s); color: var(--ink-dim); white-space: nowrap;
}
.age-track { height: .46rem; border-radius: 999px; background: #eef2fa; overflow: hidden; margin-top: .12rem; }
.age-fill { height: 100%; border-radius: 999px; }
.age-val {
  text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.25rem; font-weight: 700;
}

/* Ramped by what can still be done, not by how bad it looks. Bar length is
   proportional to count and the 30-day pile is the biggest number here, so on
   one flat list it drew the longest loudest bar and won the eye outright —
   the exact failure this screen exists to prevent. Today's queue sits above
   the rule at full weight; the backlog sits below it, demoted but on the same
   scale so the sizes stay honestly comparable. */
[data-band="today"] .age-fill { background: var(--blue); }
[data-band="today"] .age-val  { color: var(--blue); }
[data-band="today"] .age-top  { font-weight: 700; }
[data-band="warm"]  .age-fill { background: var(--orange); }
[data-band="warm"]  .age-val  { color: var(--orange); }
[data-band="late"]  .age-fill { background: var(--pink); }
[data-band="late"]  .age-val  { color: var(--pink); }
[data-band="cold"]  .age-fill { background: var(--pink); opacity: .5; }
[data-band="cold"]  .age-val  { color: var(--pink); opacity: .68; }

.age.backlog .age-top { font-size: .74rem; color: var(--ink-mid); }
.age.backlog .age-val { font-size: 1.05rem; }
.age.backlog .age-track { height: .3rem; }

.split {
  display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .25rem;
  font-size: .66rem; color: var(--ink-dim); white-space: nowrap;
}
.split::after { content: ""; flex: 1; height: 1px; background: var(--hair); }

.age-note { margin-top: auto; padding-top: .35rem; font-size: .7rem; color: var(--ink-dim); }

/* ---- reconciliation queue -------------------------------------------- */

.recon { display: flex; flex-direction: column; gap: .2rem; }
.rrow {
  display: flex; align-items: center; gap: .65rem;
  border-radius: .7rem; padding: .13rem .6rem;
  background: var(--orange-s);
}
.rrow.blocked { background: var(--pink-s); }
.rrow.clear   { background: var(--green-s); }
.rrow.info    { background: var(--grey-s); }
.rcount {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.45rem; font-weight: 700; min-width: 2.6rem; text-align: right; color: var(--orange);
}
.rrow.blocked .rcount { color: var(--pink); }
.rrow.clear   .rcount { color: var(--green); }
.rrow.info    .rcount { color: var(--ink-mid); }
.rtext { font-size: .78rem; line-height: 1.32; min-width: 0; }
.rhint { font-size: .66rem; line-height: 1.3; color: var(--ink-dim); }

/* ---- tables ----------------------------------------------------------- */

table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: .68rem; font-weight: 600; color: var(--ink-dim);
  padding: .16rem .4rem .22rem; border-bottom: 1px solid var(--hair); white-space: nowrap;
  position: sticky; top: 0; background: var(--card);
}
table.t td { padding: .13rem .4rem; border-bottom: 1px solid var(--hair); font-size: .8rem; }
table.t tr:last-child td { border-bottom: 0; }
table.t .r { text-align: right; }

.who { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.av {
  width: 1.7rem; height: 1.7rem; border-radius: 999px; flex: none;
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
  background: var(--blue-s); color: var(--blue);
}
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar { height: .4rem; border-radius: 999px; background: #eef2fa; overflow: hidden; min-width: 4rem; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--green); }
.bar.mid > i { background: var(--orange); }
.bar.low > i { background: var(--pink); }
.pctcell { display: flex; align-items: center; gap: .45rem; }
.pctnum {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: .82rem; font-weight: 700; min-width: 2.7rem; text-align: right;
}

/* ---- insight bar ------------------------------------------------------ */

.insight {
  background: linear-gradient(100deg, #eef3ff 0%, #f6efff 100%);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: .5rem .9rem; display: flex; align-items: center; gap: .8rem;
}
.insight .chip { background: #ffffff; color: var(--purple); }
.insight .txt { font-size: .84rem; line-height: 1.5; }
.insight .txt b { color: var(--blue); }
.insight .txt .warn { color: var(--pink); font-weight: 700; }
.insight .foot {
  margin-left: auto; font-size: .66rem; color: var(--ink-dim);
  text-align: right; white-space: nowrap; font-family: var(--mono);
}

/* ---- fault ------------------------------------------------------------ */

/* A failed fetch must never render as zeros. "งานค้าง 0" on a wall reads as
   good news and would hide an outage for as long as nobody thinks to check. */
.fault {
  grid-column: 1 / -1;
  background: var(--pink-s); border-radius: var(--r);
  padding: .45rem .9rem; font-size: .8rem; color: #a11333;
}
.fault b { color: var(--pink); }

/* Amber, not red: the data on screen is real, it has just stopped being
   refreshed. Different cause, different colour, so a stalled scheduler and a
   dead endpoint are never mistaken for each other from across the room. */
.fault.stale { background: var(--orange-s); color: #7a4a00; }
.fault.stale b { color: var(--orange); }
.fault .d { font-family: var(--mono); font-size: .66rem; color: var(--ink-dim); }

.dash { color: var(--grey); }
.loading { font-size: .78rem; color: var(--ink-dim); padding: .4rem 0; }

/* ---- desks and phones -------------------------------------------------
   The wall is the target, but the same URL gets opened on a laptop between
   calls. Below 1100px the fixed screen becomes an ordinary scrolling page
   rather than eleven panels crushed to nothing. */

@media (max-width: 1100px) {
  html { font-size: 15px; }
  body { height: auto; overflow: auto; }
  .wall { height: auto; grid-template-rows: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-rows: none; }
  .a-kpi, .a-age, .a-recon, .a-sale, .a-type { grid-column: 1 / -1; }
  .card .fill { overflow: visible; }
  .insight { flex-wrap: wrap; }
  .insight .foot { margin-left: 0; }
}
