:root {
  --paper: #1b1d19;
  --paper-raised: #24261f;
  --ink: #f4f1ea;
  --ink-dim: #a9a89c;
  --accent: #d97022;
  --accent-soft: #3a2c1a;
  --ready: #3fa66b;
  --ready-soft: #163325;
  --alert: #e94b4b;
  --alert-soft: #3a1616;
  --line: #38392f;
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; -webkit-tap-highlight-color: transparent; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  flex-shrink: 0;
  gap: 12px;
}
.brand {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand small { font-family: var(--font-body); font-size: 12px; color: var(--ink-dim); font-weight: 500; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-dim); }
.status-pill.live .status-dot { background: var(--ready); box-shadow: 0 0 0 3px var(--ready-soft); }
.status-pill.down .status-dot { background: var(--alert); box-shadow: 0 0 0 3px var(--alert-soft); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  min-height: 44px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.06); }

/* ---------- Priority rail ---------- */
.priority-rail {
  flex-shrink: 0;
  background: var(--alert-soft);
  border-bottom: 2px solid var(--alert);
  padding: 10px 14px;
  display: none;
}
.priority-rail.has-items { display: block; }
.priority-rail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #ffd9d9;
}
.priority-badge {
  background: var(--alert);
  color: #fff;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
}
.priority-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.priority-chip {
  flex-shrink: 0;
  background: #2a1414;
  border: 1px solid var(--alert);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.priority-chip.pulse { animation: pulseAlert 1.1s ease-in-out 3; }
@keyframes pulseAlert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233,75,75,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(233,75,75,0); }
}
.priority-chip .qty-name { font-weight: 700; font-size: 15px; }
.priority-chip .origin { font-size: 12px; color: #ffcfcf; font-family: var(--font-mono); }
.priority-chip .notes { font-size: 12px; color: #ffcfcf; font-style: italic; }
.priority-chip button {
  margin-top: 4px;
  border: none;
  background: var(--alert);
  color: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 12px;
  min-height: 36px;
  cursor: pointer;
}

/* ---------- Columns ---------- */
.board {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.column {
  flex: 1 0 300px;
  min-width: 300px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  background: var(--paper-raised);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
.column-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.column-head .count { color: var(--ink-dim); font-weight: 600; font-family: var(--font-mono); }
.column-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.column[data-status="New"] .column-head { border-top: 3px solid var(--accent); }
.column[data-status="Preparing"] .column-head { border-top: 3px solid #d9b622; }
.column[data-status="Ready"] .column-head { border-top: 3px solid var(--ready); }

.empty-hint { color: var(--ink-dim); font-size: 13px; text-align: center; padding: 24px 8px; }

/* ---------- Order ticket ---------- */
.ticket {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px 10px;
  position: relative;
}
.ticket.has-priority { border-color: var(--accent); }
.ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.ticket-order-no {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.ticket-table { font-size: 12px; color: var(--ink-dim); }
.ticket-timer { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
.ticket-timer.overdue { color: var(--alert); font-weight: 700; }

.ticket-perf {
  border-top: 1px dashed var(--line);
  margin: 8px 0;
}

.ticket-items { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.ticket-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 14px;
  padding-left: 10px;
  border-left: 3px solid transparent;
}
.ticket-item.priority {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 5px 8px;
}
.ticket-item .qty { font-family: var(--font-mono); font-weight: 700; min-width: 26px; }
.ticket-item .meta { flex: 1; }
.ticket-item .item-notes { font-size: 12px; color: var(--ink-dim); font-style: italic; }
.priority-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-left: 6px;
}

.ticket-actions { display: flex; gap: 8px; }
.btn {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #241505; }
.btn.ready { background: var(--ready); border-color: var(--ready); color: #08170f; }

/* ---------- PIN screen ---------- */
.pin-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}
.pin-screen h1 { font-family: var(--font-display); font-size: 30px; margin: 0; }
.pin-screen p { color: var(--ink-dim); margin: 0; max-width: 320px; }
.pin-dots { display: flex; gap: 14px; margin: 6px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink-dim); }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.pin-pad button {
  height: 76px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 24px;
  font-family: var(--font-mono);
  cursor: pointer;
}
.pin-pad button:active { background: rgba(255,255,255,0.08); }
.pin-error { color: var(--alert); font-size: 13px; min-height: 18px; }

@media (max-width: 480px) {
  .board { flex-direction: column; overflow-x: visible; }
  .column { max-width: 100%; min-width: 0; }
  .brand { font-size: 18px; }
}
