/* ==========================================================================
   The Salty Beak — Kitchen Display System (demo)
   Real KDS hardware runs a fixed dark screen (glare, heat lamps, wipe-down
   monitors), so this page intentionally does not follow prefers-color-scheme
   the way the guest site and POS do. It is dark on purpose, always.
   ========================================================================== */

:root {
  --teal-500:  #1aa3ac;
  --teal-400:  #2fbfb6;
  --coral-500: #ff6f4d;
  --gold-400:  #ffca5c;
  --sand-50:   #fbf3e7;

  --bg: #0a1418;
  --panel: #111f24;
  --panel-2: #16272d;
  --text: #f2f6f5;
  --text-soft: #9fb3b6;
  --border: rgba(242, 246, 245, 0.10);
  --border-strong: rgba(242, 246, 245, 0.2);

  --green: #3ecf7e;
  --amber: #f6b93b;
  --red: #ff5a52;

  /* Per-status accent, set on each column so tickets, headers, counts and
     action buttons all read from one variable instead of repeating colors. */
  --status: var(--teal-400);
  --status-ink: #06222a;

  --font-heading: 'Fredoka', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  --shadow-card: 0 2px 6px rgba(0,0,0,0.3), 0 10px 24px rgba(0,0,0,0.22);
  --shadow-pop: 0 6px 14px rgba(0,0,0,0.34), 0 18px 40px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 600; margin: 0; }
button { font-family: inherit; cursor: pointer; }
p { margin: 0; }

/* 100dvh, not 100vh: on iOS Safari 100vh is the viewport with the toolbars
   retracted, so a 100vh shell overflows and the bottom of a column cannot be
   reached. The 100vh line stays first as the fallback for browsers with no dvh. */
.kds-body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.kds-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  /* Fixed to the top edge of the screen: clear the notch. */
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, #16272d 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04), 0 6px 20px rgba(0,0,0,0.35);
  position: relative;
  z-index: 5;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 10px;
}
.kds-brand { display: flex; align-items: center; gap: 12px; }
.kds-brand-mascot {
  font-size: 1.5rem;
  line-height: 1;
  background: rgba(47,191,182,0.12);
  border: 1px solid rgba(47,191,182,0.3);
  border-radius: var(--radius-md);
  padding: 7px;
}
.kds-brand strong { font-size: 1.1rem; letter-spacing: 0.2px; }
.kds-brand-sub { display: block; font-size: 0.68rem; color: var(--text-soft); letter-spacing: 0.4px; text-transform: uppercase; margin-top: 1px; }
.kds-topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kds-clock { font-family: var(--font-heading); font-variant-numeric: tabular-nums; color: var(--text-soft); font-size: 0.95rem; min-width: 74px; text-align: right; }
.kds-btn {
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
}
.kds-btn:hover { border-color: var(--teal-400); color: var(--teal-400); }
.kds-btn.danger { border-color: var(--red); color: var(--red); }
.kds-btn.danger:hover { background: var(--red); color: #1a0a08; }
.kds-topbar-link { color: var(--text-soft); text-decoration: none; font-size: 0.82rem; font-weight: 700; padding: 9px 14px; border-radius: var(--radius-full); border: 1px solid var(--border-strong); }
.kds-topbar-link:hover { color: var(--text); border-color: var(--teal-400); }

/* ---------- Phone status tabs (shown under 700px only) ---------- */
.kds-tabs { display: none; }
.kds-tab {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text-soft);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}
.kds-tab-count {
  background: var(--panel-2);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 24px;
}
.kds-tab.active { color: var(--text); border-bottom-color: var(--teal-400); }
.kds-tab[data-tab="preparing"].active { border-bottom-color: var(--amber); color: var(--amber); }
.kds-tab[data-tab="ready"].active { border-bottom-color: var(--green); color: var(--green); }
.kds-tab.active .kds-tab-count { background: var(--teal-500); color: #06222a; }
.kds-tab[data-tab="preparing"].active .kds-tab-count { background: var(--amber); color: #2a1b04; }
.kds-tab[data-tab="ready"].active .kds-tab-count { background: var(--green); color: #06220f; }

.kds-board {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: max(14px, env(safe-area-inset-right, 0px));
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  overflow-x: auto;
  min-height: 0;
}
/* Each column declares its own status color once; everything inside it (header
   rule, count pill, ticket edge, timer, action button) inherits from --status. */
.kds-column[data-col="new"]       { --status: var(--teal-400); --status-ink: #06222a; }
.kds-column[data-col="preparing"] { --status: var(--amber);    --status-ink: #2a1b04; }
.kds-column[data-col="ready"]     { --status: var(--green);    --status-ink: #06220f; }

.kds-column {
  flex: 1;
  min-width: 280px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 8px 26px rgba(0,0,0,0.26);
  overflow: hidden; /* keep the status rule clipped to the rounded corner */
}
.kds-column-head {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  /* A solid bar of the status color across the top of the column: the fastest
     way to tell three columns apart from across a kitchen. */
  border-top: 4px solid var(--status);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), transparent);
  flex-shrink: 0;
}
.kds-column-title {
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0.3px;
  color: var(--status);
}
.kds-column-count {
  background: var(--status);
  color: var(--status-ink);
  border-radius: var(--radius-full);
  padding: 3px 12px;
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: center;
}

.kds-column-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px;
  display: grid;
  gap: 12px;
  align-content: start;
}
.kds-empty {
  color: var(--text-soft);
  font-style: italic;
  font-size: 0.88rem;
  text-align: center;
  padding: 34px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.02);
}

/* --- Ticket card ---
   The age color (green/amber/red) is the URGENCY signal and owns the left edge
   and the timer. The column's --status color owns the action button. Those are
   two different questions ("how long has this sat?" vs "what happens if I tap
   it?"), so they deliberately stay on two different channels. */
.kds-ticket {
  --age: var(--green);
  --age-tint: rgba(62,207,126,0.14);
  position: relative;
  background: linear-gradient(180deg, #1a2d34 0%, var(--panel-2) 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  border-left: 7px solid var(--age);
  padding: 14px 14px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.kds-ticket:hover { transform: translateY(-2px); box-shadow: var(--shadow-pop); }
.kds-ticket:active { transform: translateY(0) scale(0.995); }

.kds-ticket.age-green { --age: var(--green); --age-tint: rgba(62,207,126,0.14); }
.kds-ticket.age-amber { --age: var(--amber); --age-tint: rgba(246,185,59,0.16); }
.kds-ticket.age-red {
  --age: var(--red);
  --age-tint: rgba(255,90,82,0.18);
  border-color: rgba(255,90,82,0.4);
  animation: pulseRed 1.6s ease-in-out infinite;
}
@keyframes pulseRed {
  0%, 100% { box-shadow: var(--shadow-card), 0 0 0 0 rgba(255,90,82,0); }
  50%      { box-shadow: var(--shadow-card), 0 0 0 5px rgba(255,90,82,0.22); }
}

.kds-ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
/* The table/seat label is what a cook looks for first, so it is the biggest
   thing on the card. */
.kds-ticket-order { font-family: var(--font-heading); font-size: 1.35rem; line-height: 1.15; display: block; letter-spacing: 0.2px; }
.kds-ticket-type {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 800;
  color: var(--text-soft);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  margin-bottom: 5px;
}
.kds-ticket-timer {
  font-family: var(--font-heading);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  background: var(--age-tint);
  color: var(--age);
  border: 1px solid var(--age);
  flex-shrink: 0;
}
.age-red .kds-ticket-timer { box-shadow: 0 0 12px rgba(255,90,82,0.35); }

.kds-ticket-items { margin: 0 0 12px; display: grid; gap: 9px; }
.kds-ticket-item { border-top: 1px dashed var(--border); padding-top: 8px; }
.kds-ticket-item:first-child { border-top: none; padding-top: 0; }
.kds-item-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.25;
}
/* Quantity as a badge, not a prefix: "2x" must never blur into the item name. */
.kds-item-qty {
  flex-shrink: 0;
  font-family: var(--font-heading);
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--sand-50);
  background: rgba(255,255,255,0.09);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1px 7px;
  min-width: 30px;
  text-align: center;
}
.kds-item-name { min-width: 0; }
.kds-item-mods { margin: 4px 0 0; padding-left: 46px; }
.kds-item-mods li { font-size: 0.84rem; color: var(--text-soft); list-style: disc; line-height: 1.4; }
/* A special instruction is the thing most likely to get missed, so it reads as
   a callout rather than another dim line of text. */
.kds-item-note {
  font-size: 0.84rem;
  color: var(--gold-400);
  font-style: italic;
  margin: 5px 0 0 46px;
  padding: 5px 10px;
  background: rgba(255,202,92,0.14);
  border-left: 3px solid var(--gold-400);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.kds-ticket-action {
  width: 100%;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.4px;
  text-align: center;
  background: var(--status);
  color: var(--status-ink);
  box-shadow: 0 2px 0 rgba(0,0,0,0.28);
}
.kds-ticket:hover .kds-ticket-action { filter: brightness(1.08); }

/* Tablet: three columns will not fit side by side, so stack them and let the
   whole board scroll. All three stay visible at once. */
@media (max-width: 900px) {
  .kds-board { flex-direction: column; overflow-y: auto; overflow-x: hidden; }
  .kds-column { min-width: 0; max-height: 34vh; }
}

/* Phone: even stacked, three columns at 34vh each means constant scrolling and
   no column is usable. Show one at a time, picked by the tab bar. */
@media (max-width: 700px) {
  .kds-tabs {
    display: flex;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  .kds-board {
    flex-direction: column;
    overflow-y: hidden; /* the single visible column scrolls, not the board */
    overflow-x: hidden;
    padding: 10px;
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }
  .kds-board > .kds-column { display: none; max-height: none; }
  .kds-board[data-active-col="new"] .kds-column[data-col="new"],
  .kds-board[data-active-col="preparing"] .kds-column[data-col="preparing"],
  .kds-board[data-active-col="ready"] .kds-column[data-col="ready"] { display: flex; }
  /* The tab bar already names the column and shows its count. */
  .kds-column-head { display: none; }

  .kds-topbar { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top, 0px)); gap: 8px; }
  .kds-brand-sub { display: none; }
  .kds-brand strong { font-size: 0.95rem; }
  .kds-brand-mascot { font-size: 1.3rem; }
  .kds-topbar-actions { gap: 6px; }
  .kds-btn, .kds-topbar-link { padding: 10px 10px; font-size: 0.74rem; min-height: 44px; display: inline-flex; align-items: center; }
  .kds-clock { min-width: 0; font-size: 0.85rem; }

  /* A ticket is the primary tap target on this screen: give it real size. */
  .kds-ticket { padding: 12px 12px 11px; }
  .kds-ticket-action { padding: 14px 10px; min-height: 48px; font-size: 0.92rem; }
  .kds-item-line { font-size: 1rem; }
  .kds-ticket-order { font-size: 1.25rem; }
  /* Enforced by width as well as by pointer type: the (pointer: coarse) rule
     does not fire in a desktop browser emulating a phone. */
  .kds-btn, .kds-topbar-link { min-height: 44px; }
  .kds-tab { min-height: 48px; }
}

@media (pointer: coarse) {
  .kds-btn, .kds-topbar-link { min-height: 44px; display: inline-flex; align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  .kds-ticket.age-red { animation: none; }
}
