:root {
  color-scheme: light;
  --ink: #1c1210;
  --burgundy: #6e1d28;
  --burgundy-deep: #3f1017;
  --gold: #c9a24a;
  --gold-soft: #e8d5a3;
  /* --cream is the inner surface colour (inputs, tiles, text on burgundy);
     --bg is the page background, a warm sand a step darker than cream. */
  --cream: #f6efe4;
  --bg: #e7dac3;
  --paper: #fffaf3;
  --line: rgba(62, 24, 20, 0.14);
  --muted: #6b5648;
  --ok: #2f6b45;
  --danger: #9b2c2c;
  --shadow: 0 18px 40px rgba(63, 16, 23, 0.14), 0 2px 6px rgba(63, 16, 23, 0.06);
  --sans: "Nunito Sans", "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(201, 162, 74, 0.30), transparent 50%),
    radial-gradient(900px 600px at 110% 0%, rgba(110, 29, 40, 0.14), transparent 45%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--burgundy); }
/* Visible keyboard focus everywhere (burgundy reads on both sand and paper). */
:focus-visible { outline: 2px solid var(--burgundy); outline-offset: 2px; border-radius: 6px; }
input:focus-visible { outline: none; }
input:focus {
  border-color: var(--burgundy) !important;
  box-shadow: 0 0 0 3px rgba(201, 162, 74, 0.45);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }
@media (min-width: 861px) { .wrap { padding-top: 28px; } }
header.appbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px; flex-wrap: nowrap;
}
.appbar-end { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
header.appbar > nav, .appbar-end nav { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }
.mark {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(145deg, var(--burgundy), var(--burgundy-deep));
  color: var(--gold-soft); display: grid; place-items: center;
  font-family: var(--serif); font-weight: 600; font-size: 22px;
  box-shadow: var(--shadow);
}
.brand h1 { font-family: var(--serif); font-size: 26px; margin: 0; letter-spacing: -0.02em; line-height: 1.1; }
.brand p {
  margin: 0; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tag-short { display: none; }
.nav-short { display: none; }
nav a {
  margin-left: 0; text-decoration: none; font-weight: 700; font-size: 14px;
  color: var(--burgundy-deep); white-space: nowrap;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px;
  transition: color 0.15s ease;
}
nav a:hover, .sign-out:hover { color: var(--burgundy); text-decoration: underline; text-underline-offset: 4px; }
.grid { display: grid; grid-template-columns: 1.3fr 0.9fr; gap: 18px; }
.order-page .grid {
  grid-template-columns: 1.3fr 0.9fr;
  align-items: start;
}
.order-page .main-column {
  display: flex; flex-direction: column; min-width: 0;
  border-radius: 22px;
  box-shadow: var(--shadow);
  background: var(--paper);
}
.order-page .chat-card {
  border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0;
  display: flex; flex-direction: column; min-height: 0;
  box-shadow: none;
}
.order-page .dock {
  background: #fff;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 22px 22px;
  box-shadow: none;
}
.order-page .sidebar .cart-card { height: 100%; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 {
  font-family: var(--serif); font-size: 20px; margin: 0;
}
.card-head { padding: 16px 18px 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.chat {
  min-height: 420px; max-height: 62vh; overflow-y: auto;
  padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(110, 29, 40, 0.28) transparent;
}
.bubble {
  max-width: 90%; padding: 10px 13px; border-radius: 16px;
  line-height: 1.45; font-size: 15px; white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(63, 16, 23, 0.08);
  animation: bubble-in 0.22s ease-out both;
}
.bubble.assistant {
  background: #f3e6d6; border: 1px solid rgba(62, 24, 20, 0.06);
  border-bottom-left-radius: 6px; align-self: flex-start;
}
.bubble.customer {
  background: linear-gradient(160deg, #7a2230, var(--burgundy));
  color: #fffaf3; border-bottom-right-radius: 6px; align-self: flex-end;
}
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px); } }
.composer {
  display: flex; gap: 8px; padding: 12px; align-items: center;
  background: #fff; border-top: 1px solid var(--line);
}
.composer > button { flex-shrink: 0; }
input, select, textarea, button {
  font: inherit;
}
.composer input,
#phone,
.pin-bar input {
  font-size: 16px;
}
.composer input {
  flex: 1 1 0; min-width: 0; border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; background: var(--cream);
  min-height: 44px;
  text-overflow: ellipsis;
}
#phone {
  width: 100%; margin-top: 8px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line);
  min-height: 44px; background: #fff;
}
button.primary, button.gold, button.ghost, .icon-btn {
  border: 0; border-radius: 999px; padding: 12px 16px; cursor: pointer; font-weight: 700;
  min-height: 44px; min-width: 44px;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
button.primary { background: var(--burgundy); color: var(--cream); }
button.gold { background: var(--gold); color: var(--burgundy-deep); }
button.ghost { background: transparent; color: var(--burgundy); border: 1px solid var(--line); }
button.primary:hover:not(:disabled) { background: #82242f; box-shadow: 0 4px 12px rgba(110, 29, 40, 0.25); }
button.gold:hover:not(:disabled) { background: #d4ae58; box-shadow: 0 4px 12px rgba(201, 162, 74, 0.35); }
button.ghost:hover:not(:disabled) { background: rgba(110, 29, 40, 0.06); }
button.primary:active:not(:disabled), button.gold:active:not(:disabled),
.ticket-actions button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 14px; flex-shrink: 0;
}
.icon-btn svg { width: 22px; height: 22px; display: block; }
.icon-btn .icon-stop { display: none; }
.icon-btn.recording .icon-mic { display: none; }
.icon-btn.recording .icon-stop { display: block; }
.talk-meta { display: flex; gap: 8px; padding: 0 12px 12px; align-items: center; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; color: var(--burgundy); font-weight: 700; }
.banner {
  margin: 0 16px 8px; padding: 8px 12px; border-radius: 12px;
  background: #efe3c6; color: var(--burgundy-deep); font-size: 13px;
}
.banner.warn { background: #f6e0dc; }
.cart-summary {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 16px 18px 10px; background: transparent; border: 0;
  text-align: left; cursor: default; min-height: 44px; font: inherit; color: inherit;
}
.cart-summary-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cart-summary-main strong { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.cart-summary-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.cart-total { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.cart-chevron { display: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: 0 2px 4px; }
.cart-card.is-open .cart-chevron { transform: rotate(225deg); margin-bottom: 0; }
.branch-line { padding: 0 18px 6px; }
@media (max-width: 860px) { .order-page .branch-line { padding-top: 12px; } }
.cart { padding: 0 18px 18px; }
.cart ul { list-style: none; margin: 0; padding: 0; }
.cart li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.total { font-size: 18px; font-family: var(--serif); margin-top: 10px; }
.handoff { padding: 0 18px 18px; border-top: 1px dashed var(--line); margin: 0 0 0; }
.handoff summary {
  cursor: pointer; font-weight: 700; color: var(--burgundy-deep);
  min-height: 44px; display: flex; align-items: center; list-style: none;
}
.handoff summary::-webkit-details-marker { display: none; }
.handoff summary::after { content: " +"; color: var(--muted); font-weight: 700; margin-left: 6px; }
.handoff[open] summary::after { content: " –"; }
.pill {
  display: inline-block; padding: 4px 8px; border-radius: 999px;
  background: var(--gold-soft); color: var(--burgundy-deep); font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  white-space: nowrap;
}
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 18px 18px; }
@media (max-width: 600px) { .metrics { grid-template-columns: 1fr 1fr; } }
.metric { background: var(--cream); border: 1px solid rgba(62, 24, 20, 0.06); border-radius: 14px; padding: 12px; min-width: 0; }
.metric b { display: block; font-family: var(--serif); font-size: 22px; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.ticket {
  border: 1px dashed var(--burgundy); border-radius: 14px; padding: 12px;
  margin: 0 18px 12px; background: #fff; font-family: ui-monospace, Menlo, monospace;
  font-size: 12px; white-space: pre-wrap;
}
.footer { margin-top: 24px; color: var(--muted); font-size: 12px; text-align: center; }
.recording { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.banner.ok { background: #dcefe3; color: var(--ok); }
.ticket-card {
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
  margin: 0 18px 16px; background: #fff;
}
.ticket-card header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.ticket-card h3 { margin: 0; font-family: var(--serif); font-size: 18px; }
.ticket-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 14px; margin-bottom: 10px; }
.ticket-meta > div { min-width: 0; overflow-wrap: anywhere; }
.ticket-meta b { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; display: block; }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.ticket-actions button { border: 0; border-radius: 999px; padding: 8px 12px; cursor: pointer; font-weight: 700; font-size: 13px; background: var(--burgundy); color: var(--cream); min-height: 44px; }
.ticket-actions button.secondary { background: var(--gold); color: var(--burgundy-deep); }
.ticket-actions button.danger { background: var(--danger); color: #fff; }
.ticket-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.history { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; color: var(--muted); }
.history li { padding: 3px 0; }
.notify-error { background: #f6e0dc; color: var(--danger); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }
.pin-bar { display: flex; gap: 8px; align-items: center; padding: 0 18px 16px; flex-wrap: wrap; }
.pin-bar input { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; flex: 1 1 140px; max-width: 200px; min-width: 0; min-height: 44px; }
#pinStatus { flex: 1 1 100%; }
@media (min-width: 861px) { #pinStatus { flex: 0 1 auto; } }
.ticket-text { font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; background: var(--cream); border-radius: 10px; padding: 10px; margin-top: 8px; }

@media (max-width: 860px) {
  .nav-full { display: none; }
  .nav-short { display: inline; }
  header.appbar { gap: 8px; margin-bottom: 8px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 18px; }
  .tag-full { display: none; }
  .tag-short { display: inline; }
  .brand p { font-size: 10px; white-space: nowrap; }
  .mark { width: 36px; height: 36px; border-radius: 11px; font-size: 18px; }
  .appbar-end { gap: 6px; }
  .order-page, .order-page html {
    height: 100vh; height: 100dvh; overflow: hidden;
  }
  html:has(.order-page), body.order-page {
    height: 100vh; height: 100dvh; overflow: hidden;
  }
  .order-page .wrap {
    max-width: none;
    height: 100vh; height: 100dvh;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
    display: flex; flex-direction: column; min-height: 0;
  }
  .order-page .appbar {
    position: sticky; top: 0; z-index: 40;
    flex-shrink: 0; margin-bottom: 8px;
  }
  .order-page .grid {
    display: flex; flex-direction: column;
    flex: 1; min-height: 0; gap: 0;
    align-items: stretch;
  }
  .order-page .sidebar,
  .order-page .cart-card,
  .order-page .dock,
  .order-page .chat-card {
    width: 100%;
  }
  .order-page .main-column {
    display: contents;
  }
  .order-page .chat-card {
    order: 1;
    flex: 1; min-height: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: none;
    border-bottom: 0;
  }
  .order-page .sidebar { order: 2; }
  .order-page .dock { order: 3; }
  .order-page .card-head { display: none; }
  .order-page .chat {
    flex: 1; min-height: 0; max-height: none;
  }
  .order-page .sidebar { flex-shrink: 0; position: relative; z-index: 20; }
  .order-page .cart-card {
    border-radius: 0; box-shadow: none;
    border-left: none; border-right: none;
    overflow: visible;
  }
  .order-page .cart-summary {
    cursor: pointer;
    padding: 8px 14px;
    background: var(--paper);
    border-top: 1px solid var(--line);
  }
  .order-page .cart-summary-main { flex-direction: row; align-items: baseline; gap: 8px; }
  .order-page .cart-summary-main strong { font-size: 16px; }
  .order-page .cart-chevron { display: inline-block; }
  .order-page .cart-panel {
    display: none;
    position: absolute; left: 0; right: 0; bottom: 100%;
    max-height: min(52dvh, 420px);
    overflow-y: auto;
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: 0 -16px 32px rgba(63, 16, 23, 0.14);
  }
  .order-page .cart-card.is-open .cart-panel { display: block; }
  .order-page .dock {
    flex-shrink: 0;
    border-radius: 0 0 16px 16px;
    box-shadow: none;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    z-index: 21;
  }
  .order-page .talk-label { display: none; }
  .order-page .icon-btn { padding: 0; width: 44px; }
  .order-page .talk-meta { padding: 0 12px 8px; min-height: 0; }
  .order-page #talkHint { display: none; }
  .order-page.is-talking #talkHint { display: inline; }
  .order-page .footer { display: none; }
  header.appbar > nav, .appbar-end nav { gap: 8px; }
  .composer { padding: 8px 10px; }
  .bubble { font-size: 15.5px; }
}

/* Phones: not enough room for tagline + mode pill + two nav links, so the pill
   becomes a status dot. Its text stays in the DOM (screen readers, title tooltip). */
@media (max-width: 480px) {
  #modePill {
    font-size: 0; letter-spacing: 0; padding: 0;
    width: 10px; height: 10px; min-width: 10px;
    background: var(--gold); box-shadow: 0 0 0 3px rgba(201, 162, 74, 0.3);
  }
  .appbar-end { gap: 8px; }
  .metrics { padding-left: 14px; padding-right: 14px; }
  .ticket-card, .ticket { margin-left: 12px; margin-right: 12px; }
  .ticket-meta { grid-template-columns: 1fr; }
}

@media (min-width: 861px) {
  .order-page .cart-panel { display: block; }
  .order-page .handoff { display: block; }
  /* Keep the order summary in view while a long chat scrolls. */
  .order-page .sidebar { position: sticky; top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble { animation: none; }
  .recording { animation: none; }
  .chat { scroll-behavior: auto; }
  button, nav a { transition: none; }
}

.login-page { min-height: 100vh; min-height: 100dvh; }
.login-wrap { max-width: 520px; padding-top: calc(24px + env(safe-area-inset-top, 0px)); }
@media (min-width: 861px) { .login-wrap { padding-top: clamp(32px, 12vh, 112px); } }
.login-card { padding-bottom: 8px; }
.login-lead { padding: 0 18px 8px; line-height: 1.45; }
.login-form { display: flex; flex-direction: column; gap: 8px; padding: 0 18px 18px; }
.login-form label { font-weight: 700; font-size: 13px; color: var(--burgundy-deep); }
.login-form input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; background: var(--cream); font-size: 16px; min-height: 44px;
}
#code { letter-spacing: 0.35em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.login-form button { width: 100%; }
.sign-out { font-weight: 700; font-size: 14px; text-decoration: none; color: var(--burgundy-deep); min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; background: none; border: 0; cursor: pointer; }
@media (max-width: 860px) {
  .login-wrap { padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px)); }
}
