/* Law DB beta portal. Colours are tokens; dark mode and high contrast redefine them. Text size scales from the
   root font size (the A− / A+ buttons). */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef1f5; --text: #1b2430; --muted: #5b6676;
  --brand: #1f3a5f; --brand-text: #ffffff; --accent: #2f6db5; --link: #1f5fa8;
  --border: #d5dbe3; --danger: #b42318; --ok: #1d7a46; --warn: #8a5a00; --focus: #f0b429;
  --user-bubble: #e6eef8; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px; --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161d; --surface: #182029; --surface-2: #1f2934; --text: #e4e9ef; --muted: #9aa6b4;
    --brand: #1f3a5f; --brand-text: #ffffff; --accent: #6fa8e8; --link: #8cbcf2;
    --border: #2c3846; --danger: #f97066; --ok: #4ade80; --warn: #fbbf24; --user-bubble: #1d3048;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161d; --surface: #182029; --surface-2: #1f2934; --text: #e4e9ef; --muted: #9aa6b4;
  --brand: #1f3a5f; --brand-text: #ffffff; --accent: #6fa8e8; --link: #8cbcf2;
  --border: #2c3846; --danger: #f97066; --ok: #4ade80; --warn: #fbbf24; --user-bubble: #1d3048;
  --shadow: none; color-scheme: dark;
}
:root[data-contrast="high"] {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #ffffff; --text: #000000; --muted: #000000;
  --brand: #000000; --brand-text: #ffffff; --accent: #0000c8; --link: #0000c8; --border: #000000;
  --user-bubble: #ffffff; --focus: #c80000; color-scheme: light;
}
:root[data-contrast="high"][data-theme="dark"] {
  --bg: #000000; --surface: #000000; --surface-2: #000000; --text: #ffffff; --muted: #ffffff;
  --brand: #000000; --accent: #ffff00; --link: #ffff00; --border: #ffffff; --user-bubble: #000000;
  --focus: #00ffff; color-scheme: dark;
}
:root[data-font="dyslexic"] { --font: "Atkinson Hyperlegible", Verdana, Tahoma, sans-serif; letter-spacing: .02em; word-spacing: .08em; }

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--scale, 1)); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.55; }
a { color: var(--link); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
:root[data-motion="reduce"] * { animation: none !important; transition: none !important; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* header */
.top { background: var(--brand); color: var(--brand-text); display: flex; align-items: center; gap: 12px;
       padding: 10px 16px; flex-wrap: wrap; }
.top .brand { font-weight: 650; font-size: 1.05rem; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.top .brand small { font-weight: 500; opacity: .8; font-size: .75rem; border: 1px solid rgba(255,255,255,.5);
                    border-radius: 999px; padding: 0 8px; }
.top button, .top a.btn { color: var(--brand-text); background: transparent; border: 1px solid rgba(255,255,255,.45); }
.top button:hover, .top a.btn:hover { background: rgba(255,255,255,.12); }
.balance { font-size: .85rem; opacity: .95; }

/* controls */
button, .btn { font: inherit; font-size: .9rem; border-radius: 8px; border: 1px solid var(--border);
               background: var(--surface); color: var(--text); padding: 7px 12px; cursor: pointer;
               text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-contrast="high"] button.primary { color: var(--bg); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.danger { color: var(--danger); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
                          border-radius: 8px; padding: 8px 10px; max-width: 100%; }
label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field input, .field select { width: 100%; }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.error { color: var(--danger); font-weight: 600; }
.ok { color: var(--ok); }

/* sign-in pages */
.card-page { min-height: 100vh; display: flex; flex-direction: column; }
.card-wrap { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
        padding: 28px; width: 100%; max-width: 440px; }
.card h1 { font-size: 1.35rem; margin: 0 0 6px; }
.card .lede { color: var(--muted); margin: 0 0 20px; }
.card button.primary { width: 100%; justify-content: center; }
.terms-box { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
             font-size: .88rem; background: var(--surface-2); margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 4px; }
.doc { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; }

/* chat */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border);
           background: var(--surface); flex-wrap: wrap; }
.toolbar select { min-width: 0; flex: 1 1 220px; max-width: 420px; }
.toolbar .spacer { flex: 1; }
#log { flex: 1; overflow-y: auto; padding: 16px; }
.thread { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { border-radius: var(--radius); padding: 12px 16px; overflow-wrap: anywhere; }
.msg.user { background: var(--user-bubble); align-self: flex-end; max-width: 85%; white-space: pre-wrap; border: 1px solid var(--border); }
.msg.user .files { font-size: .8rem; color: var(--muted); margin-top: 6px; white-space: normal; }
.msg.bot { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.msg.bot .body { overflow-x: auto; }
.msg.bot .body table { border-collapse: collapse; margin: 8px 0; font-size: .92em; }
.msg.bot .body th, .msg.bot .body td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.msg.bot .body h1, .msg.bot .body h2, .msg.bot .body h3 { line-height: 1.25; margin: 1em 0 .4em; }
.msg.bot .body h1 { font-size: 1.3rem; } .msg.bot .body h2 { font-size: 1.15rem; } .msg.bot .body h3 { font-size: 1.02rem; }
.msg.bot .body blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.msg.bot .body code { font-family: var(--mono); font-size: .9em; }
.msg.bot .body details { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; margin-top: 10px; font-size: .9em; }
.steps { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.steps summary { cursor: pointer; }
.steps ol { margin: 6px 0 0; padding-left: 22px; max-height: 220px; overflow-y: auto; font-family: var(--mono); font-size: .8rem; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
           animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.actions button { font-size: .82rem; padding: 4px 10px; min-height: 30px; }
.meta { font-size: .78rem; color: var(--muted); margin-left: auto; align-self: center; }
.welcome { max-width: 680px; margin: 6vh auto 0; text-align: center; color: var(--muted); }
.welcome h1 { color: var(--text); font-size: 1.4rem; }
.welcome ul { text-align: left; display: inline-block; }

.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 16px 14px; }
.composer form { max-width: 900px; margin: 0 auto; }
.composer textarea { width: 100%; resize: vertical; min-height: 64px; max-height: 40vh; display: block; }
.composer .row { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.composer .row .grow { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px;
        font-size: .82rem; display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: none; min-height: 24px; padding: 0 6px; background: transparent; }
.chip.busy { opacity: .7; }
.notice { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }

.mode-hint { flex-basis: 100%; margin: 0; font-size: .82rem; color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .88rem; margin: 0;
          border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.toggle input { margin: 0; }
.toggle:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.toggle #detailed-rate { font-weight: 500; color: var(--muted); }
dialog#guide { border: 1px solid var(--border); border-radius: 14px; padding: 0; max-width: min(720px, calc(100vw - 32px));
               max-height: calc(100vh - 48px); background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog#guide::backdrop { background: rgba(0,0,0,.45); }
.guide { padding: 20px 24px; overflow-y: auto; }
.guide h2 { margin: 0 0 8px; font-size: 1.25rem; }
.guide h2:focus { outline: none; }
.guide h3 { font-size: 1rem; margin: 16px 0 4px; }
.guide p, .guide li { font-size: .93rem; }
.guide ul { padding-left: 20px; margin: 4px 0; }
.guide li { margin-bottom: 6px; }

/* accessibility panel */
.panel { position: absolute; right: 16px; top: 54px; z-index: 20; background: var(--surface); color: var(--text);
         border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 16px;
         width: min(320px, calc(100vw - 32px)); }
.panel h2 { font-size: 1rem; margin: 0 0 10px; }
.panel .opt { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; font-size: .9rem; }
.panel .opt .group { display: flex; gap: 4px; }
.panel button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* admin */
.admin main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.admin section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
                 margin-bottom: 16px; box-shadow: var(--shadow); }
.admin h2 { font-size: 1.1rem; margin: 0 0 12px; }
.tablewrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: .88rem; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.grid th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { font-size: .75rem; border-radius: 999px; padding: 1px 8px; border: 1px solid var(--border); }
.badge.active { color: var(--ok); border-color: currentColor; }
.badge.suspended { color: var(--danger); border-color: currentColor; }
.badge.invited { color: var(--warn); border-color: currentColor; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form .field { margin: 0; }
.linkbox { display: flex; gap: 8px; margin-top: 10px; }
.linkbox input { flex: 1; font-family: var(--mono); font-size: .8rem; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.row-actions button { font-size: .78rem; min-height: 28px; padding: 2px 8px; }
.stat { display: inline-block; margin-right: 24px; }
.stat b { display: block; font-size: 1.3rem; }

@media (max-width: 640px) {
  .msg.user { max-width: 100%; }
  .top .balance { order: 3; width: 100%; }
  #keys { display: none; }          /* no Enter-to-send on a phone keyboard */
  .composer .row .toggle { flex: 1; }
  .card { padding: 20px; }
}
@media print {
  .top, .toolbar, .composer, .actions { display: none !important; }
  .app { height: auto; } #log { overflow: visible; }
}
