/*
  The desk.

  The look is the one the doctor approved in the demo, kept deliberately. He
  agreed to a product; a plainer version of it reads as a downgrade however
  much better the machinery underneath has become.

  What it adds is the room. A clinic reception is bright, the tablet is old and
  smudged, the person using it is standing, and the patients are often 60+. So
  type is large, contrast is high, and nothing you have to hit is smaller than
  a thumb. Every size here is a legibility or reachability decision.

  --brand arrives at runtime from the clinic's own config, so a second clinic
  is a different colour rather than a fork.
*/

:root {
  --brand: #0d7a5f;
  --brand-dark: #095c47;
  --brand-soft: #e4f2ed;
  --brand-ink: #ffffff;
  --on-brand: var(--brand-dark);

  --ink: #10231f;
  --ink-2: #3d5450;
  --ink-3: #6b8480;
  --line: #dbe5e2;
  --line-soft: #eef2f1;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --hover: #fafcfb;

  --amber: #b4690e;
  --amber-soft: #fdf3e3;
  --red: #b42318;
  --red-soft: #fdeceb;
  --blue: #175cd3;
  --blue-soft: #eaf1fd;
  --neutral-soft: #eef1f0;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 35, 31, .06), 0 8px 24px rgba(16, 35, 31, .07);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #14302a;
    --on-brand: #6fd0ae;
    --ink: #e5ece8; --ink-2: #a8b7b0; --ink-3: #7e8d86;
    --line: #2b3833; --line-soft: #222d29;
    --bg: #0e1613; --surface: #16201c; --hover: #1b2622;
    --amber: #d9a55e; --amber-soft: #2c2517;
    --red: #e2887a; --red-soft: #2e1b17;
    --blue: #8fb4ee; --blue-soft: #1a2436;
    --neutral-soft: #222d29;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* Wide content - the table - scrolls inside its own box. Without min-width:0 a
   grid or flex child refuses to shrink below its content and pushes the whole
   page sideways, which puts the buttons out of reach rather than merely off
   to the side. */
.cols > *, .wrap { min-width: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

a { color: var(--on-brand); }

/* ------------------------------------------------------------- controls -- */

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  min-height: var(--tap);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  transition: background .12s; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.big { padding: 15px 26px; font-size: 16px; border-radius: 12px; min-height: 52px; }
.btn.sm { padding: 7px 12px; font-size: 12.5px; min-height: 38px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--on-brand); }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid var(--brand); outline-offset: 2px;
}

input, select {
  font: inherit; font-size: 14.5px; min-height: var(--tap); width: 100%;
  padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); outline: none; max-width: 100%;
}
input:focus, select:focus { border-color: var(--brand); }

/* --------------------------------------------------------------- topbar -- */

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 12px 22px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.topbar .spacer { flex: 1 1 auto; min-width: 0; }
.topbar .titles { min-width: 0; }

.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none;
}

.live {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; color: var(--on-brand);
  background: var(--brand-soft); padding: 7px 12px; border-radius: 99px;
}
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); animation: pulse 2s infinite; }
.live.polling { color: var(--amber); background: var(--amber-soft); }
.live.polling .dot { background: var(--amber); }
.live.offline { color: var(--red); background: var(--red-soft); }
.live.offline .dot { background: var(--red); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

/* ----------------------------------------------------------------- page -- */

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px; }
@media (max-width: 46rem) { .wrap { padding: 14px; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin: 0; padding: 16px 18px 0; font-weight: 700;
}

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
@media (max-width: 1120px) { .cols { grid-template-columns: minmax(0, 1fr); } }

/* ---------------------------------------------------------------- stats -- */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .n { font-size: 32px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; font-weight: 500; }
.stat.good .n { color: var(--brand); }
.stat.warn .n { color: var(--amber); }
.stat.bad .n { color: var(--red); }

/* -------------------------------------------------------------- serving -- */

.serving {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff; border-radius: var(--radius); padding: 20px 24px;
  display: flex; align-items: center; gap: 26px; flex-wrap: wrap;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.serving .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: .14em; opacity: .8; }
.serving .num { font-size: 60px; font-weight: 800; line-height: .95; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.serving .mid { flex: 1 1 12rem; min-width: 0; }
.serving .who { font-size: 18px; font-weight: 600; margin-top: 3px; }
.serving .meta { font-size: 13px; opacity: .85; margin-top: 2px; }
.serving .btn { background: #fff; color: var(--brand-dark); border-color: #fff; }
.serving .btn:hover { background: #eaf5f1; }

.closed-bar {
  background: var(--amber-soft); border: 1px solid var(--amber); color: var(--amber);
  padding: 14px 18px; border-radius: var(--radius); font-weight: 600; margin-bottom: 18px;
}

/* -------------------------------------------------------------- toolbar -- */

.toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar input { flex: 1 1 12rem; min-width: 0; }
.daynav { display: flex; gap: 6px; flex: none; }
.daynav .btn { padding: 10px 14px; }

/* --------------------------------------------------------------- table -- */

table { width: 100%; border-collapse: collapse; }
.tablewrap table { min-width: 640px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 700;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); font-size: 14.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }
tbody tr.serving-row { background: var(--brand-soft); }

.tok {
  display: inline-grid; place-items: center; width: 42px; height: 42px;
  border-radius: 10px; background: var(--neutral-soft); font-weight: 700; font-size: 16px;
  font-variant-numeric: tabular-nums;
}
tr.serving-row .tok { background: var(--brand); color: var(--brand-ink); }

.nm { font-weight: 600; }
.mut { color: var(--ink-3); font-size: 12.5px; }
.src { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.pill {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 4px 9px; border-radius: 99px; letter-spacing: .02em; text-transform: uppercase;
}
.pill.booked { background: var(--blue-soft); color: var(--blue); }
.pill.confirmed { background: var(--brand-soft); color: var(--on-brand); }
.pill.arrived { background: var(--amber-soft); color: var(--amber); }
.pill.in_consult { background: var(--brand); color: var(--brand-ink); }
.pill.done { background: var(--neutral-soft); color: var(--ink-3); }
.pill.no_show { background: var(--red-soft); color: var(--red); }
.pill.cancelled { background: var(--neutral-soft); color: var(--ink-3); }

.empty { padding: 40px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ----------------------------------------------------------------- side -- */

.side .card { margin-bottom: 16px; }
.caps { display: flex; gap: 8px; padding: 14px 16px; flex-wrap: wrap; }
.cap { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 12px; flex: 1 1 8rem; }
.cap .t { font-weight: 700; font-size: 12.5px; }
.cap .b { color: var(--ink-3); margin-top: 3px; }
.cap.taken { background: var(--brand-soft); border-color: var(--brand); }
.cap.taken .b { color: var(--on-brand); font-weight: 600; }
.cap.full { background: var(--red-soft); border-color: var(--red); }
.cap.full .b { color: var(--red); font-weight: 600; }
.cap.over { background: var(--neutral-soft); }

.log { padding: 6px 16px 16px; max-height: 320px; overflow-y: auto; }
.log div { font-size: 12.5px; color: var(--ink-2); padding: 8px 0; border-bottom: 1px solid var(--line-soft); line-height: 1.5; }
.log div:last-child { border: none; }
.log .t { color: var(--ink-3); font-size: 11px; }

/* --------------------------------------------------------------- dialog -- */

dialog {
  border: none; border-radius: var(--radius); padding: 0;
  box-shadow: 0 24px 60px rgba(16, 35, 31, .3);
  background: var(--surface); color: var(--ink); max-width: calc(100vw - 2rem);
}
dialog::backdrop { background: rgba(16, 35, 31, .5); }
.dlg { padding: 22px; width: 380px; max-width: 100%; }
.dlg h3 { margin: 0 0 4px; font-size: 18px; }
.dlg .hint { margin: 0 0 8px; font-size: 13px; color: var(--ink-3); }
.dlg label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
.dlg .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* -------------------------------------------------------------- sign in -- */

.centred { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.sign-in { width: min(24rem, 100%); padding: 28px; }
.sign-in .logo { width: 52px; height: 52px; font-size: 19px; border-radius: 13px; margin-bottom: 16px; }
.sign-in h1 { font-size: 20px; margin: 0 0 4px; }
.sign-in label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 14px 0 5px; }
.sign-in .btn { width: 100%; margin-top: 20px; }

.error { color: var(--red); background: var(--red-soft); padding: 10px 13px; border-radius: 10px; margin: 14px 0 0; font-size: 13.5px; }

/* --------------------------------------------------------------- toast -- */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: 99px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px; max-width: calc(100vw - 2rem);
  text-align: center; z-index: 40;
}
.toast.bad { background: var(--red); color: #fff; }

@media (prefers-reduced-motion: reduce) { *, .live .dot { animation: none !important; transition: none !important; } }
