@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --green-dark: #14291F;
  --green: #1F3D2F;
  --green-soft: #2C4E3B;
  --amber: #C97E2E;
  --amber-lt: #E8C08A;
  --amber-bg: #FBF0E1;
  --cream: #F2F0EA;
  --white: #FFFFFF;
  --ink: #2B2B2B;
  --gray: #6B6B6B;
  --line: #E4E0D6;
  --success: #3C7A52;
  --success-bg: #E4F0E7;
  --wait: #C97E2E;
  --wait-bg: #FBF0E1;
  --idle: #6B6B6B;
  --idle-bg: #ECEAE3;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow: 0 8px 24px rgba(20, 41, 31, 0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
button { font-family: inherit; -webkit-tap-highlight-color: transparent; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Key gate screen ---------- */
.gate {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(165deg, var(--green-dark) 0%, var(--green) 65%, var(--green-soft) 100%);
  padding: 24px;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 34px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.gate-mark {
  width: 44px; height: 44px; border-radius: 11px; background: var(--amber);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 700; font-size: 21px; color: var(--green-dark);
  margin-bottom: 18px;
}
.gate-card h1 {
  font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; color: var(--green-dark);
  margin-bottom: 6px;
}
.gate-card p { font-size: 13.5px; color: var(--gray); line-height: 1.5; margin-bottom: 22px; }
.gate-field label { display: block; font-size: 12px; font-weight: 700; color: var(--green-dark); margin-bottom: 8px; }
.gate-field input {
  width: 100%; padding: 13px 14px; font-size: 15px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  outline: none; color: var(--ink); background: var(--cream);
}
.gate-field input:focus { border-color: var(--amber); background: var(--white); }
.gate-error { color: #B3452C; font-size: 12.5px; margin-top: 10px; min-height: 16px; }
.gate-submit {
  margin-top: 18px; width: 100%; padding: 14px; border: none; border-radius: var(--radius-sm);
  background: var(--amber); color: var(--green-dark); font-weight: 700; font-size: 14.5px;
}
.gate-submit:disabled { opacity: 0.5; }
.gate-hint { margin-top: 16px; font-size: 11.5px; color: var(--gray); line-height: 1.5; }

/* ---------- App shell ---------- */
.app { display: none; min-height: 100vh; flex-direction: column; }
.app.active { display: flex; }

.topbar {
  background: var(--green-dark); color: var(--white);
  padding: 14px 20px; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--amber);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 700; font-size: 15px; color: var(--green-dark);
}
.topbar-title { font-size: 14.5px; font-weight: 700; line-height: 1.25; }
.topbar-title small { display: block; font-size: 10.5px; font-weight: 500; color: var(--amber-lt); letter-spacing: 0.06em; text-transform: uppercase; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; }
.conn-dot.off { background: #B3452C; }
.conn-label { font-size: 11.5px; color: var(--amber-lt); }
.signout-btn { background: none; border: 1px solid rgba(255,255,255,0.25); color: var(--white); font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 100px; }

.tabs {
  display: flex; gap: 4px; background: var(--white); padding: 6px; margin: 16px auto 0;
  border-radius: 100px; border: 1px solid var(--line); width: fit-content;
}
.tab-btn {
  border: none; background: none; padding: 10px 22px; border-radius: 100px;
  font-size: 13.5px; font-weight: 700; color: var(--gray);
}
.tab-btn.active { background: var(--green-dark); color: var(--white); }

.view { display: none; flex: 1; padding: 20px; max-width: 900px; margin: 0 auto; width: 100%; }
.view.active { display: block; }

.view-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.view-header h1 { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 600; color: var(--green-dark); }
.view-header .sub { font-size: 12.5px; color: var(--gray); }
.refresh-btn { background: var(--white); border: 1px solid var(--line); border-radius: 100px; padding: 8px 16px; font-size: 12.5px; font-weight: 700; color: var(--green-dark); display: flex; align-items: center; gap: 6px; }
.refresh-btn svg { width: 13px; height: 13px; }

/* ---------- Manifest ---------- */
.manifest-panel {
  background: var(--green-dark); color: var(--white);
  border-radius: var(--radius-md); padding: 18px 20px; margin-bottom: 20px;
}
.manifest-title { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--amber-lt); margin-bottom: 12px; }
.manifest-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.manifest-chip {
  background: rgba(255,255,255,0.08); border-radius: var(--radius-sm);
  padding: 10px 14px; min-width: 140px;
}
.manifest-chip .qty { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 700; color: var(--amber); }
.manifest-chip .name { font-size: 12px; color: var(--white); margin-top: 2px; }
.manifest-empty { font-size: 13px; color: var(--amber-lt); }

/* ---------- Order cards (kitchen ticket style) ---------- */
.order-list { display: flex; flex-direction: column; gap: 14px; }
.order-card {
  background: var(--white); border-radius: var(--radius-md);
  border: 1px solid var(--line); overflow: hidden;
  display: flex; box-shadow: 0 3px 10px rgba(20,41,31,0.06);
}
.order-stub {
  width: 92px; flex-shrink: 0; background: var(--cream);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-right: 2px dashed var(--line); padding: 14px 8px;
}
.order-stub .code { font-family: 'Fraunces', serif; font-size: 18px; font-weight: 700; color: var(--green-dark); text-align: center; }
.order-stub .time { font-size: 10.5px; color: var(--gray); margin-top: 4px; }
.order-body { flex: 1; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.order-items { font-size: 13px; color: var(--ink); line-height: 1.6; }
.order-items b { color: var(--green-dark); }
.order-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; padding: 5px 11px; border-radius: 100px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.status-badge.received { background: var(--idle-bg); color: var(--idle); }
.status-badge.preparing { background: var(--wait-bg); color: #7A4E1A; }
.status-badge.ready { background: var(--success-bg); color: var(--success); }
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.action-btn {
  border: none; border-radius: var(--radius-sm); padding: 10px 18px;
  font-size: 13px; font-weight: 700; color: var(--white); background: var(--green);
}
.action-btn.ready-btn { background: var(--amber); color: var(--green-dark); }
.action-btn:active { transform: scale(0.98); }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--gray);
  background: var(--white); border-radius: var(--radius-md); border: 1px dashed var(--line);
}
.empty-state .emoji { font-size: 34px; margin-bottom: 10px; }

/* ---------- Counter lookup ---------- */
.lookup-box {
  background: var(--white); border-radius: var(--radius-md); border: 1px solid var(--line);
  padding: 22px; margin-bottom: 20px;
}
.lookup-row { display: flex; gap: 10px; }
.lookup-row input {
  flex: 1; padding: 15px 16px; font-size: 20px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; text-align: center;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); outline: none;
  color: var(--green-dark); font-family: 'Fraunces', serif;
}
.lookup-row input:focus { border-color: var(--amber); }
.lookup-row button {
  border: none; border-radius: var(--radius-sm); padding: 0 24px;
  background: var(--green-dark); color: var(--white); font-weight: 700; font-size: 14px;
}
.lookup-hint { font-size: 11.5px; color: var(--gray); margin-top: 10px; text-align: center; }

.result-card { background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--line); overflow: hidden; }
.result-top { padding: 24px; text-align: center; border-bottom: 2px dashed var(--line); }
.result-code { font-family: 'Fraunces', serif; font-size: 34px; font-weight: 700; color: var(--green-dark); }
.result-status { margin-top: 10px; }
.result-body { padding: 22px 24px; }
.result-items { font-size: 14px; line-height: 1.8; color: var(--ink); margin-bottom: 18px; }
.result-items b { color: var(--green-dark); }
.result-action { width: 100%; padding: 15px; border: none; border-radius: var(--radius-sm); font-weight: 700; font-size: 14.5px; }
.result-action.collect { background: var(--amber); color: var(--green-dark); }
.result-action.disabled { background: var(--idle-bg); color: var(--gray); }
.result-note { font-size: 12.5px; color: var(--gray); text-align: center; margin-top: 12px; line-height: 1.5; }
.result-collected { text-align: center; padding: 30px 20px; }
.result-collected .check { width: 56px; height: 56px; border-radius: 50%; background: var(--success-bg); color: var(--success); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; font-size: 26px; }
.result-collected h2 { font-family: 'Fraunces', serif; font-size: 19px; color: var(--green-dark); margin-bottom: 4px; }
.result-collected p { font-size: 13px; color: var(--gray); }

.lookup-error {
  background: #FBEAE5; border: 1px solid #E8B9A8; color: #8A3419;
  border-radius: var(--radius-md); padding: 16px; font-size: 13.5px; text-align: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(10px);
  background: var(--green-dark); color: var(--white);
  padding: 13px 22px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: all 250ms ease; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .order-card { flex-direction: column; }
  .order-stub { width: 100%; flex-direction: row; justify-content: space-between; border-right: none; border-bottom: 2px dashed var(--line); }
}
