/* Design tokens. Scale follows the UX guide: 14/20 text, spacing 2-24, radii 4/8/12/full, one accent. */
:root {
  color-scheme: light dark;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-xs: 12px; --text-sm: 13px; --text: 14px; --text-lg: 16px; --text-xl: 20px; --text-2xl: 28px;
  --lh-xs: 16px; --lh: 20px; --lh-xl: 28px; --lh-2xl: 36px;
  --w-regular: 400; --w-medium: 500; --w-strong: 600;

  --s1: 2px; --s2: 4px; --s3: 6px; --s4: 8px; --s5: 10px; --s6: 12px; --s7: 16px; --s8: 24px; --s9: 32px;
  --r-sm: 4px; --r: 8px; --r-lg: 12px; --r-full: 999px;

  /* The default accent. An organisation's own replaces these five, worked out by libbrand.php. */
  --accent: #4f46e5; --accent-hover: #463eca; --on-accent: #ffffff; --accent-soft: #ededfc; --accent-text: #4f46e5;

  --shell: #f4f4f2; --sheet: #ffffff; --raised: #ffffff; --subtle: #f7f7f5; --hover: #efefec; --selected: #e9e9e5;
  --line: #e4e4e0; --line-strong: #cfcfca;
  --ink: #1c1c1a; --ink-2: #5d5d58; --ink-3: #6f6f6a;

  --warn: #8a5300; --warn-soft: #fbf0dc;
  --info: #24518f; --info-soft: #e7eef9;
  --danger: #a32222; --danger-soft: #fbe9e9;
  --neutral-soft: #eeeeeb;

  --overlay: rgba(20, 20, 18, .4);
  --shadow: 0 8px 28px rgba(20, 20, 18, .16), 0 1px 3px rgba(20, 20, 18, .1);
}

/* Dark follows the device unless someone chose a theme in the console's account menu, which sets data-theme on <html>. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8b8ef5; --accent-hover: #999cf6; --on-accent: #111111; --accent-soft: #303141; --accent-text: #8b8ef5;

    --shell: #141413; --sheet: #1c1c1a; --raised: #252523; --subtle: #20201e; --hover: #2a2a27; --selected: #33332f;
    --line: #30302d; --line-strong: #45453f;
    --ink: #ecece8; --ink-2: #b0b0aa; --ink-3: #9a9a94;

    --warn: #e6b566; --warn-soft: #3a2c13;
    --info: #92b6ec; --info-soft: #1c2a40;
    --danger: #ef9a9a; --danger-soft: #3c1d1d;
    --neutral-soft: #2c2c29;

    --overlay: rgba(0, 0, 0, .6);
    --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --accent: #8b8ef5; --accent-hover: #999cf6; --on-accent: #111111; --accent-soft: #303141; --accent-text: #8b8ef5;

  --shell: #141413; --sheet: #1c1c1a; --raised: #252523; --subtle: #20201e; --hover: #2a2a27; --selected: #33332f;
  --line: #30302d; --line-strong: #45453f;
  --ink: #ecece8; --ink-2: #b0b0aa; --ink-3: #9a9a94;

  --warn: #e6b566; --warn-soft: #3a2c13;
  --info: #92b6ec; --info-soft: #1c2a40;
  --danger: #ef9a9a; --danger-soft: #3c1d1d;
  --neutral-soft: #2c2c29;

  --overlay: rgba(0, 0, 0, .6);
  --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: var(--w-regular) var(--text)/var(--lh) var(--font); color: var(--ink); background: var(--shell); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--w-strong); }
h2 { font-size: var(--text); line-height: var(--lh); font-weight: var(--w-strong); }
a { color: var(--accent-text); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s3); min-height: 32px; padding: 0 var(--s6);
  border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--raised); color: var(--ink);
  font: var(--w-medium) var(--text)/var(--lh) var(--font); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.btn svg { width: 16px; height: 16px; flex: none; }

.field { display: grid; gap: var(--s3); }
.field > label, .label { font-weight: var(--w-medium); }
.hint { color: var(--ink-2); font-size: var(--text-sm); }
.input {
  width: 100%; min-height: 36px; padding: var(--s3) var(--s5); border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--raised); color: var(--ink); font: inherit;
}
textarea.input { resize: vertical; }
.input::placeholder { color: var(--ink-3); }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 var(--s3); border-radius: var(--r-sm); font-size: var(--text-xs); font-weight: var(--w-medium); white-space: nowrap; background: var(--neutral-soft); color: var(--ink-2); }
.badge.ai { background: var(--info-soft); color: var(--info); }
.badge.waiting { background: var(--warn-soft); color: var(--warn); }
.badge.human { background: var(--accent-soft); color: var(--accent-text); }
.notice { padding: var(--s4) var(--s6); border-radius: var(--r); font-size: var(--text-sm); background: var(--neutral-soft); color: var(--ink-2); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* Message bubbles, shared by the widget and the staff console. */
.msg { display: grid; gap: var(--s2); max-width: 78%; justify-items: start; }
.msg.mine { margin-left: auto; justify-items: end; }
.msg-meta { color: var(--ink-3); font-size: var(--text-xs); line-height: var(--lh-xs); }
.msg-body { padding: var(--s4) var(--s6); border-radius: var(--r-lg); background: var(--subtle); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .msg-body { background: var(--selected); border-color: transparent; }
.msg.pending .msg-body { opacity: .65; }
.msg.failed .msg-body { border-color: var(--danger); }
.msg-files { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.msg.mine .msg-files { justify-content: flex-end; }
.msg-file { display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3); border: 1px solid var(--line); border-radius: var(--r); font-size: var(--text-sm); color: var(--ink); text-decoration: none; max-width: 100%; }
.msg-file svg { width: 16px; height: 16px; flex: none; }
.msg-file span:first-of-type { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file .hint { flex: none; white-space: nowrap; }
a.msg-file:hover { background: var(--subtle); }
.msg-file.missing { color: var(--ink-3); border-style: dashed; }
.msg-system { align-self: center; text-align: center; color: var(--ink-2); font-size: var(--text-sm); padding: var(--s1) var(--s7); }
.msg-system.error { color: var(--danger); }
.dots { display: inline-flex; gap: var(--s2); padding: var(--s2) 0; }
.dots i { width: 6px; height: 6px; border-radius: var(--r-full); background: var(--ink-3); animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } }
