/**
 * File: /kiosk/css/kiosk.css
 * Purpose: Shipping & Receiving TV board styles — dark, high-contrast,
 *          sized in vw/vh so it reads from across the dock on any TV size.
 * Version: 1.3.0 (2026-10-14)
 *
 * Changes in 1.3.0:
 * - Outbound Picked column widened so "612 / 2,340 cs" isn't cut off
 * - Panels split 0.9 / 1.15 / 1 (outbound has the most columns)
 * - .panel-nodoor hides an empty Door column; .panel-compact tightens rows
 *   when a panel overflows
 * - Fix: sections pinned to their grid rows — with no upcoming orders the
 *   hidden ticker shifted the panels into an auto-height row, so they never
 *   paged and the bottom rows were cut off
 * - .cell-ref: inbound lot / outbound order number, larger than other main lines
 * - .row-at-door (inbound truck at its door)
 * - .row-attention pulses orange, red with .attention-alert (Not confirmed
 *   while its driver is on site)
 * - .row-stale (check-in left open), .row-attention (truck here, order not
 *   confirmed), .st-stale, .tag-flag
 *
 * Changes in 1.2.0:
 * - .row-needs-door: pulsing drivers row while a Waiting driver has no door
 *
 * Changes in 1.1.0:
 * - .tag-driver: on-site driver tag on inbound/outbound rows
 */

:root {
  /* Brand — sampled from the GO Cold Storage logo (app/images/systemlogo.png) */
  --brand-navy: #223e66;
  --brand-sky: #5394cf;

  --bg: #0c1726;
  --panel: #13233a;
  --panel-alt: #182b46;
  --line: #223e66;
  --text: #eef3f8;
  --muted: #93a9c4;
  --accent: var(--brand-sky);

  --st-grey: #64748b;
  --st-blue: var(--brand-sky);
  --st-teal: #14b8a6;
  --st-amber: #f59e0b;
  --st-orange: #f97316;
  --st-red: #ef4444;
  --st-green: #22c55e;
  --st-violet: #a78bfa;

  --fs-base: clamp(14px, 1.05vw, 34px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-base);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.8em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Setup ─────────────────────────────────────────────────────────── */

.setup {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.setup-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  display: grid;
  gap: 10px;
  font-size: 18px;
}

.setup-logo { display: block; width: 140px; height: auto; margin: 0 auto 12px; }
.setup-card h1 { margin: 0 0 4px; font-size: 28px; }
.setup-card p { margin: 0 0 8px; line-height: 1.4; }
.setup-card label { font-weight: 600; margin-top: 8px; }

.setup-card input,
.setup-card select {
  font: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

.setup-card input:focus,
.setup-card select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.setup-card button {
  margin-top: 16px;
  font: inherit;
  font-weight: 700;
  padding: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--brand-sky);
  color: #fff;
  cursor: pointer;
}

.setup-card button:disabled { opacity: 0.6; cursor: wait; }

.setup-error {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
}

/* ── Board layout ──────────────────────────────────────────────────── */

.board {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 1.2vh;
  padding: 1.6vh 1.2vw;
  overflow: hidden;
}

/* Each section has a fixed grid row: when the ticker is hidden it must not
   shift the panels into its auto-height row (the panels would grow to fit
   every row, paging would never start, and the bottom rows would be cut off). */
.topbar    { grid-row: 1; }
.kpis      { grid-row: 2; }
.ticker    { grid-row: 3; }
.panels    { grid-row: 4; }
.statusbar { grid-row: 5; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left { display: flex; align-items: center; gap: 1.2vw; }
.topbar-logo { height: 6vh; width: auto; }

.topbar h1 {
  margin: 0;
  font-size: 2.1em;
  letter-spacing: 0.02em;
}

.topbar-right { text-align: right; }
.clock { font-size: 2.2em; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.clock-date { color: var(--muted); font-size: 1em; margin-bottom: 0.2em; }

.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1vw;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--brand-sky);
  border-radius: 10px;
  padding: 1vh 1vw;
}

.kpi-label { color: var(--muted); font-size: 0.95em; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 2.6em; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-sub { color: var(--muted); font-size: 0.9em; }
.kpi-accent .kpi-value { color: var(--accent); }

.panels {
  display: grid;
  grid-template-columns: 0.9fr 1.15fr 1fr;
  gap: 1vw;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  column-gap: 0.8em;
  padding: 1vh 1vw 0.6vh;
}

.panel-head h2 { margin: 0; font-size: 1.3em; white-space: nowrap; }
/* On a narrow panel the page/hidden notes wrap below the title as one line. */
.panel-meta { display: flex; gap: 0.8em; align-items: baseline; margin-left: auto; white-space: nowrap; }
.panel-page { color: var(--muted); font-size: 0.85em; }
.panel-hidden { color: var(--muted); font-size: 0.8em; font-style: italic; }

/* ── Upcoming orders ticker ────────────────────────────────────────── */

.ticker {
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  font-size: 0.95em;
}

.ticker-label {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.5vh 1vw;
  background: var(--brand-navy);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ticker-count {
  background: var(--st-red);
  border-radius: 999px;
  padding: 0 0.55em;
  font-size: 0.9em;
}

.ticker-track {
  position: relative;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.ticker-text {
  display: inline-block;
  padding-left: 100%;
  animation: ticker-scroll var(--ticker-duration, 40s) linear infinite;
}

.ticker-item { margin-right: 2.5em; }
.ticker-item b { color: var(--brand-sky); margin-right: 0.4em; }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

/* ── Stale-data banner ─────────────────────────────────────────────── */

.stale-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 1.2vh 1.2vw;
  background: var(--st-red);
  color: #fff;
  font-size: 1.4em;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel-empty {
  padding: 4vh 1vw;
  text-align: center;
  color: var(--muted);
  font-size: 1.1em;
}

/* ── Rows ──────────────────────────────────────────────────────────── */

.row {
  display: grid;
  align-items: center;
  gap: 0.5vw;
  padding: 0.75vh 0.8vw;
  border-top: 1px solid var(--line);
}

.row:nth-child(even) { background: var(--panel-alt); }

.row-head {
  border-top: 0;
  color: var(--muted);
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.4vh;
  padding-bottom: 0.4vh;
}

.row-inbound  { grid-template-columns: 3.6em 3.9em minmax(0, 1fr) 4.8em; }
.row-outbound { grid-template-columns: 3.4em 3.9em minmax(0, 1fr) 6.6em 7.8em; }
.row-drivers  { grid-template-columns: 3.9em minmax(0, 1fr) 4.4em 6.8em; }

/* No row has a door: drop the column and give the width to the names. */
.panel-nodoor .cell-door { display: none; }
.panel-nodoor .row-inbound  { grid-template-columns: 3.6em minmax(0, 1fr) 4.8em; }
.panel-nodoor .row-outbound { grid-template-columns: 3.4em minmax(0, 1fr) 6.6em 7.8em; }

/* More rows than fit: tighten before paging. */
.panel-compact .row:not(.row-head) { padding-top: 0.3vh; padding-bottom: 0.3vh; }

.row-head > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row > span { min-width: 0; }

.cell-main { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-ref { font-size: 1.15em; font-weight: 700; letter-spacing: 0.01em; }
.cell-sub { display: block; color: var(--muted); font-size: 0.82em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.date { font-weight: 700; font-variant-numeric: tabular-nums; }
.date-late { color: var(--st-red); }
.date-future { color: var(--muted); font-weight: 600; }
.kpi-overdue { color: #fca5a5; font-weight: 700; }

.door {
  display: inline-grid;
  place-items: center;
  min-width: 2.4em;
  height: 1.9em;
  padding: 0 0.3em;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 1.05em;
}

.door-empty { color: var(--muted); font-weight: 400; }

.tag {
  display: inline-block;
  font-size: 0.72em;
  font-weight: 800;
  padding: 0.1em 0.45em;
  border-radius: 4px;
  margin-right: 0.35em;
  vertical-align: 0.1em;
}

.tag-delivery { background: rgba(83, 148, 207, 0.25); color: #a9cdef; }
.cell-status { display: flex; flex-direction: column; align-items: flex-start; gap: 0.2em; min-width: 0; }
.tag-flag { margin: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag-repack { background: rgba(245, 158, 11, 0.2); color: #fcd34d; margin: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag-pickup { background: rgba(167, 139, 250, 0.2); color: #c4b5fd; }
/* Load's driver is on site; background/color come from the st-* class. */
.tag-driver { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: 0.05em; }
.cell-status .tag-driver { margin: 0; }
/* On the inbound lot line the tag inherits .cell-sub's smaller font; bring it
   back up to the outbound tag's size so it reads from across the dock. */
.cell-sub .tag-driver { font-size: 0.9em; padding: 0.12em 0.5em; margin-right: 0.6em; }

.pill {
  display: inline-block;
  max-width: 100%;
  padding: 0.25em 0.55em;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  background: var(--st-grey);
}

.st-grey { background: var(--st-grey); }
.st-blue { background: var(--st-blue); }
.st-teal { background: var(--st-teal); }
.st-amber { background: var(--st-amber); color: #1f1300; }
.st-orange { background: var(--st-orange); }
.st-red { background: var(--st-red); }
.st-green { background: var(--st-green); color: #052e12; }
.st-violet { background: var(--st-violet); color: #1e1240; }
/* Check-in left open for hours: needs closing in the app, not an alarm. */
.st-stale { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--muted); }

.row-stale > span { opacity: 0.6; }

/* Inbound: the truck is at its door — the load being received now. */
.row.row-at-door { box-shadow: inset 0.35em 0 0 var(--st-green); background-color: rgba(34, 197, 94, 0.14); }

/* Truck at the dock, order not confirmed: it can't load until someone
   confirms it, so it pulses like a driver waiting for a door — orange at
   first, red once the driver has waited WAIT_ALERT_MIN (.attention-alert). */
.row.row-attention {
  --attention: var(--st-orange);
  --needs-door-tint: rgba(249, 115, 22, 0.1);
  --needs-door-glow: rgba(249, 115, 22, 0.34);
  box-shadow: inset 0.35em 0 0 var(--attention);
  animation: needs-door-pulse 1.6s ease-in-out infinite;
}

.row.row-attention.attention-alert {
  --attention: var(--st-red);
  --needs-door-tint: rgba(239, 68, 68, 0.12);
  --needs-door-glow: rgba(239, 68, 68, 0.4);
}

/* A driver waiting a long time for a door should stand out. */
.wait-warn { color: var(--st-amber); font-weight: 700; }
.wait-alert { color: var(--st-red); font-weight: 800; }

/* Driver Waiting with no door: the row pulses so shipping assigns one.
   Amber by default, red once the wait passes WAIT_ALERT_MIN. Only
   background/box-shadow animate, so row heights (and paging) don't change. */
.row-needs-door {
  --needs-door: var(--st-amber);
  --needs-door-tint: rgba(245, 158, 11, 0.1);
  --needs-door-glow: rgba(245, 158, 11, 0.34);
  box-shadow: inset 0.35em 0 0 var(--needs-door);
  animation: needs-door-pulse 1.6s ease-in-out infinite;
}

.row-needs-door.needs-door-alert {
  --needs-door: var(--st-red);
  --needs-door-tint: rgba(239, 68, 68, 0.12);
  --needs-door-glow: rgba(239, 68, 68, 0.4);
}

.row-needs-door .door {
  border: 2px solid var(--needs-door);
  color: var(--needs-door);
  font-weight: 800;
}

@keyframes needs-door-pulse {
  0%, 100% { background-color: var(--needs-door-tint); }
  50% { background-color: var(--needs-door-glow); }
}

@media (prefers-reduced-motion: reduce) {
  .row-needs-door,
  .row.row-attention { animation: none; background-color: var(--needs-door-glow); }
}

/* ── Status bar ────────────────────────────────────────────────────── */

.statusbar {
  display: flex;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.8em;
}

.conn-offline {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.2);
  padding: 0.2em 0.7em;
  border-radius: 6px;
}

/* Narrow screens (setup on a phone, portrait TV): stack the panels. */
@media (max-width: 900px) {
  .board { height: auto; min-height: 100vh; overflow: visible; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .panels { grid-template-columns: 1fr; }
  .panel { max-height: none; }
  .panel-body { overflow: visible; }
}
