:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c1f1d;
  --muted: #5d655f;
  --line: #e2e6e2;
  --brand: #1f5f4a;
  --brand-ink: #ffffff;
  --brand-soft: #e4f0eb;
  --user: #1f5f4a;
  --user-ink: #ffffff;
  --warn-bg: #fff6e5;
  --warn-ink: #6b4b00;
  --danger: #b4231d;
  --radius: 14px;
  --max: 720px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --surface: #1b1f1d;
    --text: #eef1ef;
    --muted: #a6ada8;
    --line: #2b312e;
    --brand: #4cae8f;
    --brand-ink: #0d1a15;
    --brand-soft: #1e2f28;
    --user: #2e7d62;
    --user-ink: #ffffff;
    --warn-bg: #3a2d10;
    --warn-ink: #f3d28b;
    --danger: #ff7b73;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 14px; }
.brand-name { font-weight: 700; }
.brand-sub { color: var(--muted); }
.top-actions { display: flex; gap: 6px; align-items: center; }
.link { background: none; border: 0; color: var(--brand); padding: 6px 8px; border-radius: 8px; text-decoration: none; }
.link:hover { background: var(--brand-soft); }
.link.small { font-size: 14px; }

.chat { flex: 1; width: 100%; max-width: var(--max); margin: 0 auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; }

.session { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 15px; }
.session .hello { margin: 0 0 6px; font-weight: 600; }
.session ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.session li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.session .acc-name { font-weight: 600; }
.session .acc-state { color: var(--muted); }
.session .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.session .dot.ready { background: #2f9e6b; }
.session .dot.preparing, .session .dot.updating { background: #d9a400; }
.session .dot.needs_attention { background: var(--danger); }
.session .muted { color: var(--muted); margin: 4px 0 0; }

.messages { display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 88%; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--user); color: var(--user-ink); border-color: transparent; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.bubble a { word-break: break-all; }
.msg.user .bubble a { color: inherit; }
.status { color: var(--muted); font-size: 14px; padding: 0 6px; }
.status::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; vertical-align: middle; }
@keyframes blink { 50% { opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) { .status::after { animation: none; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 999px; font-size: 14px; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.card { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px 14px; max-width: 88%; display: flex; flex-direction: column; gap: 8px; }
.card p { margin: 0; }
.card .muted { color: var(--muted); font-size: 14px; }
.card.action { border-color: var(--brand); }
.card.error { border-color: var(--danger); }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; }

.primary { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.primary[disabled] { opacity: 0.6; cursor: default; }
.secondary { background: var(--surface); color: var(--brand); border: 1px solid var(--brand); border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.secondary:hover { background: var(--brand-soft); }

.notice { max-width: var(--max); margin: 0 auto; background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; font-size: 14px; }

.composer { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer form { max-width: var(--max); margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; background: var(--bg); color: var(--text); max-height: 160px; }
.composer-actions { max-width: var(--max); margin: 8px auto 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 480px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
dialog h2 { margin: 0 0 4px; font-size: 20px; }
dialog label { font-size: 14px; font-weight: 600; margin-top: 6px; }
dialog input, dialog textarea { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: var(--bg); color: var(--text); }
.ticket-draft { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.ticket-draft p { margin: 4px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.muted { color: var(--muted); }
@media (min-width: 720px) { .bubble, .card { max-width: 76%; } }
