/* Patient History Assistant — refined clinical product UI */

:root {
  --bg: #e8eef2;
  --bg-deep: #d5e0e8;
  --surface: #fbfcfd;
  --surface-elevated: #ffffff;
  --ink: #15232e;
  --ink-soft: #2a3d4d;
  --muted: #5c7384;
  --accent: #2563a6;
  --accent-hover: #1d4f85;
  --accent-soft: #e8f1fb;
  --accent-line: #b9d1ea;
  --patient-bubble: #2563a6;
  --clinician-bubble: #ffffff;
  --border: #cfdce5;
  --border-strong: #b3c5d2;
  --danger: #9b2c2c;
  --danger-soft: #f8eaea;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(21, 35, 46, 0.05), 0 8px 28px rgba(21, 35, 46, 0.07);
  --shadow-soft: 0 1px 2px rgba(21, 35, 46, 0.04);
  --font-display: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-body: "Figtree", "Avenir Next", "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.55) 0%, transparent 120px),
    var(--bg);
}

.app[hidden],
.gate[hidden] {
  display: none !important;
}

/* Author display rules beat the UA [hidden] stylesheet — force hide. */
.chip[hidden],
.action-row[hidden],
.checklist[hidden],
.input-row[hidden],
.finish-more[hidden],
.ddx-panel[hidden],
.similar-panel[hidden],
.mic-status[hidden],
.stage-badge[hidden],
.usage-compact[hidden],
.cost-badge[hidden],
.signed-in-label[hidden],
.topup-btn[hidden],
.gate-why[hidden],
.gate-why-hint[hidden],
.gate-note[hidden],
.settings-email[hidden],
.settings-topup[hidden],
.settings-session-meta[hidden],
#model-picker[hidden],
dialog [hidden] {
  display: none !important;
}

body.session-finished .input-row {
  display: none !important;
}

.gate.is-signed-in .gate-why {
  display: none !important;
}
.gate.is-signed-in .gate-note {
  display: none !important;
}
.gate.is-signed-in .gate-why-hint {
  display: block !important;
  margin: 0 0 8px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: rgba(251, 252, 253, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  animation: fade-down 0.45s var(--ease);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2f75bd 0%, #174c80 100%);
  color: #fff;
  border-radius: 11px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand p { margin: 0; font-size: 0.78rem; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.signed-in-label {
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}
.chip-ghost:hover {
  color: var(--ink);
  border-color: var(--border-strong);
}

.cost-badge {
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: center;
}

.stage-badge {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.stage-badge-emergency {
  color: var(--danger);
  background: var(--danger-soft);
}

.msg.msg-emergency {
  border-color: #e0a8a8;
  border-left: 4px solid #b33a3a;
}

body.emergency-mode .topbar {
  border-bottom-color: #e0a8a8;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }

/* ---------- chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 85%;
  padding: 13px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  box-shadow: var(--shadow-soft);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  animation: rise 0.35s var(--ease);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-down {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.msg.clinician {
  align-self: flex-start;
  background: var(--clinician-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.msg.patient {
  align-self: flex-end;
  background: linear-gradient(160deg, #2f75bd, #2563a6);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.msg.system {
  align-self: center;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 2px 8px;
}

.msg.error {
  align-self: center;
  background: var(--danger-soft);
  border: 1px solid #e5bcbc;
  color: var(--danger);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

.msg.error .error-text { flex: 1 1 12rem; }

.msg.error .retry-btn {
  appearance: none;
  border: 1px solid #c45a5a;
  background: #fff;
  color: var(--danger);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  flex: 0 0 auto;
}

.msg.error .retry-btn:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.msg .summary-block {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.msg h1, .msg h2, .msg h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0.6em 0 0.2em;
}
.msg ul { margin: 0.3em 0; padding-left: 1.2em; }
.msg p { margin: 0.4em 0; }
.msg hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.typing {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-width: min(92%, 34rem);
  padding: 10px 16px 12px;
  background: var(--accent-soft);
  border-radius: 14px 14px 14px 4px;
}
.typing.is-deep { background: #e6edf3; }
.typing-label {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--muted);
  transition: opacity 0.25s ease;
}
.typing.is-deep .typing-label { color: #3d5263; }
.typing-dots { display: flex; gap: 5px; }
.typing-dots span {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}
.typing.is-deep .typing-dots span { background: #5a7388; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- composer ---------- */
.composer {
  padding: 12px 22px 16px;
  background: rgba(251, 252, 253, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip-primary:hover { background: var(--accent-hover); color: #fff; }

.chip-yes {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  min-width: 4.5rem;
  justify-content: center;
}
.chip-yes:hover { background: var(--accent); color: #fff; }

.chip-no {
  background: var(--bg);
  border-color: var(--border);
  color: var(--ink);
  font-weight: 600;
  min-width: 4.5rem;
  justify-content: center;
}
.chip-no:hover { border-color: var(--danger); color: var(--danger); }

#confirm-yes-btn,
#confirm-add-btn { min-width: 0; }

.checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 12px;
}

.checklist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.checklist-label {
  flex: 1;
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--ink);
}

.checklist-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.checklist-btns .chip {
  padding: 6px 14px;
  min-width: 3.6rem;
  font-size: 0.82rem;
  justify-content: center;
}

.checklist-btns .chip.is-selected.chip-yes {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.checklist-btns .chip.is-selected.chip-no {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.checklist-submit { align-self: flex-end; margin-top: 2px; }
.checklist-submit:disabled { opacity: 0.45; cursor: not-allowed; }

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  line-height: 1.4;
  max-height: 140px;
  outline: none;
  background: var(--surface-elevated);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 166, 0.12);
}
#input:disabled { background: var(--bg); }

.mic-btn,
.send-btn {
  width: 46px; height: 46px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mic-btn {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
}
.mic-btn:hover { border-color: var(--accent); color: var(--accent); }
.mic-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.mic-btn.is-listening {
  background: var(--danger-soft);
  border-color: #c0392b;
  color: #c0392b;
  animation: mic-pulse 1.4s ease-in-out infinite;
}
.mic-btn.is-unsupported { display: none; }

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.28); }
  50% { box-shadow: 0 0 0 8px rgba(192, 57, 43, 0); }
}

.mic-status {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: #c0392b;
  text-align: center;
}
.mic-status.is-hint { color: var(--muted); }

.send-btn {
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); cursor: default; }

.disclaimer {
  margin: 10px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.chip-edu {
  width: 100%;
  justify-content: center;
  text-align: center;
  white-space: normal;
  line-height: 1.35;
  font-size: 1.02rem;
  font-weight: 650;
  padding: 14px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: #1f568f;
  box-shadow: none;
}
.chip-edu:hover {
  background: #d9e8f7;
  border-color: #8fb5da;
  color: #174877;
}

.finish-more {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}
.finish-more .chip,
.finish-more .chip-edu {
  width: 100%;
  justify-content: center;
}
.action-row:has(#download-btn:not([hidden])) {
  flex-wrap: wrap;
}
.action-row:has(#finish-more:not([hidden])) {
  flex-direction: column;
  align-items: stretch;
}

.settings-section {
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.settings-section h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}
.settings-email {
  margin: 0 0 10px;
  word-break: break-all;
}
.settings-usage { margin: 0 0 8px; }
.settings-cost { margin: 0 0 10px; }
.settings-topup { width: 100%; margin-top: 4px; }
.settings-lang { display: block; }
.settings-lang select {
  width: 100%;
  max-width: none;
  padding: 9px 11px;
  font-size: 0.92rem;
}
.settings-why {
  margin: 0 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 12px;
}
.settings-why summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 0.92rem;
  padding: 12px 0;
  list-style: none;
}
.settings-why summary::-webkit-details-marker { display: none; }
.settings-why summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-weight: 500;
}
.settings-why[open] summary::after { content: "–"; }
.settings-why-body {
  padding: 0 0 12px;
}
.settings-why-body p {
  margin: 0 0 10px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-soft);
}
.settings-why-body p:last-child { margin-bottom: 0; }
.settings-session-meta {
  margin: 0 0 12px;
  line-height: 1.45;
}

.gate-why-hint {
  margin: 0;
}
.gate-why-hint .btn-link {
  padding: 0;
  font-size: 0.92rem;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.similar-panel {
  margin: 0 0 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.similar-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.similar-panel-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
}
.similar-note {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
.similar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.similar-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
}
.similar-list .dx-label {
  font-size: 0.78rem;
  color: var(--muted);
}
.similar-list a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.92rem;
  line-height: 1.35;
}
.similar-list a:hover { text-decoration: underline; }
.similar-list .dx-rationale {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}
.similar-list li.needs-review {
  border-left: 3px solid var(--warn, #c48a2a);
}
.similar-status { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }
.similar-status.is-error { color: var(--danger); }

.ddx-panel {
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
}
.ddx-panel-head h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.05rem;
}
.ddx-note {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}
.ddx-list {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ddx-list li { font-size: 0.95rem; line-height: 1.4; }
.ddx-list .ddx-pct {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ddx-status { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }
.ddx-status.is-error { color: var(--danger); }

dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0;
  width: min(440px, 92vw);
  background: var(--surface-elevated);
}
dialog::backdrop { background: rgba(18, 32, 42, 0.48); }

.settings-form { padding: 22px; display: flex; flex-direction: column; gap: 8px; }
.settings-form h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}
.settings-form label { font-size: 0.85rem; font-weight: 600; margin-top: 8px; }

.settings-form input[type="text"],
.settings-form input[type="password"],
.settings-form select {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface);
}
.settings-form select { font-size: 0.88rem; }
.settings-form input:focus, .settings-form select:focus { border-color: var(--accent); }

.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.78rem; margin: 2px 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.dialog-actions-spread {
  justify-content: space-between;
  align-items: center;
}
.dialog-actions-end { display: flex; gap: 10px; }

.btn-primary, .btn-secondary {
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-primary { background: var(--accent); color: #fff; border: none; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
}
.btn-secondary:hover { border-color: var(--border-strong); }
.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 8px;
}
.btn-link:hover { color: var(--ink); }

.usage-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.usage-bar-sm { width: 72px; height: 6px; }
.usage-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2f75bd, #2563a6);
  transition: width 0.25s ease;
}
.usage-block { margin: 12px 0 18px; }
.usage-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.usage-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 7rem;
}
.usage-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.topup-btn { font-size: 0.78rem; padding: 4px 10px; }

/* ---------- opening gate ---------- */
.gate {
  min-height: 100dvh;
  padding: 28px 20px 40px;
  background:
    radial-gradient(ellipse 70% 45% at 12% -5%, rgba(47, 117, 189, 0.16) 0%, transparent 55%),
    radial-gradient(ellipse 55% 40% at 95% 8%, rgba(45, 90, 120, 0.12) 0%, transparent 50%),
    linear-gradient(165deg, #f3f7f9 0%, var(--bg) 42%, var(--bg-deep) 100%);
  animation: fade-in 0.5s var(--ease);
}

.gate-shell {
  width: min(1080px, 100%);
  margin: 0 auto;
}

.gate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  animation: fade-down 0.5s var(--ease);
}

.gate-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.gate-brand-text { display: flex; flex-direction: column; gap: 2px; }

.gate-product {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
}

.gate-tagline {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.gate-auth-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.gate-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr;
  gap: 28px;
  align-items: start;
}

.gate-intro {
  animation: rise 0.55s var(--ease) 0.05s both;
}

.gate-headline {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 3.4vw, 2.55rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--ink);
}

.gate-lead {
  margin: 0 0 18px;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: 38rem;
}

.gate-privacy {
  margin: 0 0 22px;
  padding: 16px 18px;
  max-width: 38rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
}

.gate-privacy h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}

.gate-privacy p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.gate-why {
  margin: 0 0 22px;
  padding: 22px 0 0;
  border-top: 1px solid var(--border);
  max-width: 38rem;
}

.gate-why h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--ink);
}

.gate-why p {
  margin: 0 0 12px;
  font-size: 0.95rem;
  line-height: 1.62;
  color: var(--ink-soft);
}

.gate-why p:last-child { margin-bottom: 0; }

.gate-note {
  margin: 0;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
  max-width: 38rem;
}

.gate-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 24px 22px;
  animation: rise 0.55s var(--ease) 0.12s both;
  position: sticky;
  top: 20px;
}

.gate-prefs-title {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate-field {
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gate-field > label,
.field-label,
.lang-select-label {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--ink);
}

.field-note {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}

.gate-field select,
.lang-select-wrap select {
  font: inherit;
  font-size: 0.92rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  max-width: 100%;
}
.gate-field select:focus,
.lang-select-wrap select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 166, 0.12);
}

.lang-select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.lang-select-wrap select {
  max-width: 11rem;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.persona-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.persona-card {
  display: block;
  cursor: pointer;
  margin: 0;
}

.persona-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.persona-card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.persona-card:hover .persona-card-body {
  border-color: var(--border-strong);
}

.persona-card input:checked + .persona-card-body {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.persona-card input:focus-visible + .persona-card-body {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.persona-title {
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--ink);
}

.persona-desc {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}

.gate-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.gate-tab {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.gate-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gate-form[hidden] { display: none !important; }
.gate-form label { font-size: 0.85rem; font-weight: 600; }
.gate-form input {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.gate-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 166, 0.12);
}
.gate-submit { margin-top: 10px; width: 100%; }
.gate-panel[hidden] {
  display: none !important;
}
.gate-panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.2rem;
}
.gate-error {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}
.gate-info {
  margin: 14px 0 0;
  color: var(--accent);
  font-size: 0.9rem;
}

.package-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0;
}
.package-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.package-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.package-card strong {
  font-size: 1.25rem;
  color: var(--accent);
}
.package-card span { font-weight: 600; }
.package-card em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 860px) {
  .gate-layout {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .gate-card {
    position: static;
  }
  .gate-headline {
    font-size: 1.85rem;
  }
}

@media (max-width: 600px) {
  .brand p,
  .gate-tagline { display: none; }
  .msg { max-width: 92%; }
  .usage-compact { min-width: 0; }
  .cost-badge { display: none; }
  .lang-select-label { display: none; }
  .lang-select-wrap select { max-width: 7.5rem; }
  .gate { padding: 18px 14px 32px; }
  .gate-card { padding: 20px 16px 18px; }
  .topbar { padding: 12px 14px; }
  .chat { padding: 18px 14px 12px; }
  .composer { padding: 10px 14px 14px; }
}
