:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #16242f;
  --muted: #5d6b74;
  --line: #ded8ca;
  --accent: #0b6e69;
  --accent-ink: #ffffff;
  --accent-soft: #dcefec;
  --warn: #b4530a;
  --warn-soft: #fbead5;
  --danger: #a3261f;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 15px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }

input[type="text"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  min-height: 44px;
}
label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

.banner {
  background: var(--warn-soft);
  color: var(--warn);
  padding: 8px 16px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
}

/* ---------- status pill ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.status .dot { width: 12px; height: 12px; border-radius: 50%; background: #b9b3a5; flex: none; }
.status[data-state="idle"] .dot { background: var(--accent); }
.status[data-state="speech"] .dot { background: var(--accent); animation: pulse .7s ease-in-out infinite; }
.status[data-state="busy"] .dot { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.7); opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .status .dot { animation: none !important; } }

/* ---------- conversation ---------- */
.talk { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.bubbles {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  max-width: min(86%, 720px);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  position: relative;
}
.bubble.theirs { align-self: flex-start; border-left: 5px solid var(--accent); }
.bubble.mine { align-self: flex-end; background: #ebe7dc; }
.bubble .big { font-size: 1.45rem; line-height: 1.3; overflow-wrap: anywhere; }
.bubble.mine .big { font-size: 1.05rem; }
.bubble .small { margin-top: 6px; font-size: .92rem; color: var(--muted); overflow-wrap: anywhere; }
.bubble .timing { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.note { align-self: center; color: var(--muted); font-size: 15px; text-align: center; padding: 6px 12px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.composer input { flex: 1; min-width: 0; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.toolbar .grow { flex: 1; min-width: 0; }
.toolbar h2 { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- patient ---------- */
.patient { min-height: 100%; display: flex; flex-direction: column; }
.patient header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.patient header .who { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.center { align-items: center; justify-content: center; text-align: center; padding: 24px 20px; gap: 18px; }
.globe { font-size: 44px; line-height: 1; }
.langs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
}
.langs button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  min-height: 60px;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
}
.langs button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.startbar { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
.startbar .btn { width: 100%; font-size: 1.3rem; min-height: 60px; }
.number {
  font-size: 5.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.label { font-size: 15px; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.lead { font-size: 1.35rem; max-width: 26ch; }
.codebox { display: flex; flex-direction: column; gap: 12px; width: min(100%, 320px); }
.codebox input { text-align: center; font-size: 1.8rem; letter-spacing: .25em; text-transform: uppercase; font-weight: 700; }
.error { color: var(--danger); font-weight: 600; }

/* ---------- doctor ---------- */
.doctor { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
}
.topbar .brand { font-weight: 800; letter-spacing: .02em; }
.topbar .me { flex: 1; text-align: right; opacity: .85; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.layout { display: grid; grid-template-columns: 360px 1fr; min-height: 0; flex: 1; }
.side { border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.main { display: flex; flex-direction: column; min-height: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { font-size: 14px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.qr { display: flex; gap: 14px; align-items: center; }
.qr img { width: 116px; height: 116px; border-radius: 8px; border: 1px solid var(--line); background: #fff; flex: none; }
.qr .token { font-size: 1.5rem; font-weight: 800; letter-spacing: .1em; font-variant-numeric: tabular-nums; }
.qr .hint { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.queue li { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.queue .num { font-size: 1.4rem; font-weight: 800; color: var(--accent); min-width: 2.2ch; text-align: center; font-variant-numeric: tabular-nums; }
.queue .info { flex: 1; min-width: 0; }
.queue .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .info span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.queue .btn { flex: none; }
.queue .x { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 20px; min-width: 36px; min-height: 36px; border-radius: 8px; }
.queue .x:hover { background: var(--warn-soft); color: var(--danger); }
.count { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 9px; margin-left: 6px; font-size: 13px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); text-align: center; padding: 24px; }
.empty b { font-size: 1.3rem; color: var(--ink); }

dialog { border: 0; border-radius: var(--radius); padding: 24px; width: min(92vw, 420px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(22, 36, 47, .55); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 1.3rem; }
dialog p { color: var(--muted); font-size: 15px; }

@media (max-width: 860px) {
  .doctor { height: auto; min-height: 100%; }
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .main { min-height: 70vh; }
  /* phone: during a conversation the whole screen is for the conversation */
  body.talking .doctor { height: 100%; }
  body.talking .side { display: none; }
  body.talking .main { min-height: 0; }
  .toolbar .grow { flex-basis: 100%; }
}

@media print {
  body * { visibility: hidden; }
  #qr-card, #qr-card * { visibility: visible; }
  #qr-card { position: fixed; inset: 40px auto auto 40px; border: 0; }
  #qr-card img { width: 320px; height: 320px; }
  #qr-card .btn { display: none; }
}
