/* Donna — light, premium legal-SaaS design system.
   Hand-written, no build step. Newsreader (serif display) + Hanken Grotesk (UI). */

:root {
  --paper: #f6f5f1;        /* app background, warm off-white */
  --surface: #ffffff;      /* cards / panels */
  --sidebar: #fbfaf7;
  --ink: #1c1b18;          /* primary text, warm near-black */
  --text: #1c1b18;         /* alias used by some templates */
  --muted: #74716a;        /* secondary text */
  --faint: #a4a09a;        /* tertiary text */
  --border: #e7e3db;
  --border-2: #dbd6cc;
  --accent: #1f3a5f;       /* deep navy */
  --accent-hover: #294b78;
  --accent-soft: #eef1f6;
  --accent-ink: #f6f5f1;   /* text on dark/ink fills */
  --ok: #3f6b53;   --ok-soft: #eaf1ec;
  --warn: #8a6a32; --warn-soft: #f6eed9;
  --err: #9b3d3d;  --err-soft: #f6e9e8;
  --radius: 11px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(28,27,24,.05);
  --shadow: 0 1px 2px rgba(28,27,24,.04), 0 10px 30px -16px rgba(28,27,24,.22);
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -0.01em; color: var(--ink); }
h1 { font-size: 1.9rem; line-height: 1.15; margin: 0 0 .25rem; }
h2 { font-size: 1.3rem; margin: 1.6rem 0 .8rem; }
h3 { font-size: 1.05rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

p { margin: .4rem 0; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85em; background: #00000008; padding: .1em .35em; border-radius: 5px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ── App shell ─────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex: 0 0 244px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 1.4rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  padding: .2rem .5rem 1.3rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.brand:hover { color: var(--ink); }
.brand-mark { width: 26px; height: 26px; display: block; }
.brand-mark--dark { display: none; }
[data-theme="dark"] .brand-mark--light { display: none; }
[data-theme="dark"] .brand-mark--dark { display: block; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .65rem; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; font-size: .92rem;
}
.nav-item:hover { background: #00000008; color: var(--ink); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }

.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .5rem; }
.foot-user { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.foot-tools { display: flex; flex-direction: column; gap: .1rem; }
.foot-workspace { min-width: 0; }
.foot-workspace select { width: 100%; font-size: .85rem; padding: .4rem .55rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); cursor: pointer; }
.foot-workspace select:focus { outline: none; border-color: var(--accent); }
.role-form { display: inline-block; margin: 0 .4rem; }
.role-form select { width: auto; font-size: .85rem; padding: .15rem .4rem; }
.who { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--accent-ink); display: grid; place-items: center; font-weight: 600; font-size: .85rem; flex: 0 0 auto; }
.who-name { font-size: .9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkish { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: .85rem; padding: .25rem; }
.linkish:hover { color: var(--accent); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ── Disclaimer bar (persistent legal notice, every screen) ──── */
.disclaimer-bar {
  margin-top: auto;            /* sticky-footer: rests at the bottom of .main */
  border-top: 1px solid var(--border);
  background: var(--sidebar);
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.45;
  letter-spacing: .01em;
  text-align: center;
  padding: .7rem 1.4rem;
}
.auth-shell { display: flex; flex-direction: column; min-height: 100vh; }
.auth-shell .auth { flex: 1 1 auto; min-height: 0; }
.auth-shell .disclaimer-bar { margin-top: 0; }
/* width:100% gives .page a definite cross-size so it fills the column (capped at
   max-width, centered on wide screens). Without it, the auto margins inside the
   flex column steal the free space and .page collapses to its content width. */
.page { width: 100%; max-width: 920px; margin: 0 auto; padding: 2.4rem 2.2rem 4rem; }

/* ── Page header ───────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.crumb { color: var(--muted); font-size: .86rem; margin-bottom: 1.1rem; display: inline-flex; gap: .35rem; align-items: center; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.3rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1.1rem; margin-bottom: .6rem; transition: border-color .15s, box-shadow .15s;
}
.list-row:hover { border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.list-row .title { font-weight: 600; }
.list-row .meta { color: var(--muted); font-size: .85rem; margin-top: .1rem; }

/* ── Buttons ───────────────────────────────────────────────── */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .9rem;
  background: var(--ink); color: var(--accent-ink);
  border: 1px solid var(--ink); border-radius: var(--radius-sm);
  padding: .5rem .95rem; cursor: pointer; white-space: nowrap;
  transition: transform .04s ease, opacity .15s, background .15s;
}
button:hover, .btn:hover { background: #000; color: var(--accent-ink); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

.btn.secondary, button.secondary {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border-2);
}
.btn.secondary:hover, button.secondary:hover { background: #00000005; border-color: var(--ink); color: var(--ink); }
.btn.small, button.small { padding: .3rem .6rem; font-size: .82rem; border-radius: 6px; }
.btn.ghost, button.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover, button.ghost:hover { background: #00000008; color: var(--err); }

/* ── Forms ─────────────────────────────────────────────────── */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 .35rem; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: .55rem .7rem; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2374716a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; padding-right: 1.8rem; }
form p { margin: 0 0 .85rem; }          /* Django as_p spacing */
.helptext, .helptext { font-size: .8rem; color: var(--faint); }
ul.errorlist { list-style: none; padding: 0; margin: .2rem 0 .6rem; color: var(--err); font-size: .85rem; }

.field-inline { display: flex; gap: .5rem; align-items: flex-end; }
.field-inline > * { margin: 0; }
.field-inline input, .field-inline select { flex: 1; }

/* ── Auth ──────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background:
  radial-gradient(1200px 500px at 50% -10%, #ffffff 0%, var(--paper) 60%); }
.auth-card { width: 100%; max-width: 392px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.2rem 2rem; box-shadow: var(--shadow); }
.auth-logo { font-family: var(--serif); font-size: 1.7rem; font-weight: 600; letter-spacing: -.02em; text-align: center; display: flex; align-items: center; justify-content: center; gap: .5rem; margin-bottom: .55rem; }
.auth-logo img { width: 56px; height: 56px; display: block; }
.auth-tagline { font-family: var(--serif); font-style: italic; font-size: .98rem; color: var(--muted); text-align: center; margin: 0 0 1.5rem; }
.auth-card h1 { font-size: 1.15rem; text-align: center; color: var(--muted); font-family: var(--sans); font-weight: 500; margin: 0 0 1.5rem; }
.auth-card button[type=submit] { width: 100%; margin-top: .4rem; padding: .6rem; }
.auth-alt { text-align: center; color: var(--muted); font-size: .88rem; margin-top: 1.2rem; }

/* ── Flash messages ────────────────────────────────────────── */
.flash { max-width: 920px; margin: 1.2rem auto -0.6rem; padding: 0 2.2rem; }
.flash-item { background: var(--accent-soft); border: 1px solid #d7deea; color: var(--accent); border-radius: var(--radius-sm); padding: .6rem .85rem; font-size: .9rem; margin-bottom: .5rem; }

/* ── Notices (no model / warnings) ─────────────────────────── */
.notice { background: var(--warn-soft); border: 1px solid #e9d9b0; color: var(--warn); border-radius: var(--radius); padding: .8rem 1rem; font-size: .9rem; margin-bottom: 1rem; }
.notice a { color: var(--warn); text-decoration: underline; }

/* ── Badges / status ───────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .74rem; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; padding: .18rem .5rem; border-radius: 999px; border: 1px solid var(--border-2); color: var(--muted); background: var(--surface); }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: #cfe0d4; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: #e9d9b0; }
.badge.err { color: var(--err); background: var(--err-soft); border-color: #e6c9c7; }

/* ── Chat ──────────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; min-height: calc(100vh - 8rem); }
.messages { list-style: none; padding: 0; margin: 0 0 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.msg { max-width: 78%; }
.msg .role { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin-bottom: .3rem; }
.msg .bubble { padding: .8rem 1rem; border-radius: 13px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; align-items: flex-end; display: flex; flex-direction: column; }
.msg.user .bubble { background: var(--ink); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.bubble > :first-child { margin-top: 0; } .bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .5rem; }
.bubble ul, .bubble ol { margin: .3rem 0 .5rem 1.2rem; padding: 0; }
.bubble li { margin: .15rem 0; }
.bubble code { background: #00000010; padding: .08em .35em; border-radius: 4px; font-size: .88em; }
.bubble pre { background: #00000010; padding: .6rem .8rem; border-radius: 8px; overflow: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-family: var(--sans); font-weight: 700; margin: .5rem 0 .3rem; }
.msg.user .bubble code, .msg.user .bubble pre { background: #ffffff22; }
.bubble h1 { font-size: 1.22rem; } .bubble h2 { font-size: 1.1rem; } .bubble h3 { font-size: 1.02rem; } .bubble h4, .bubble h5, .bubble h6 { font-size: .95rem; }
.bubble a { text-decoration: underline; }
.bubble blockquote { margin: .5rem 0; padding: .1rem 0 .1rem .85rem; border-left: 3px solid var(--border-2); color: var(--muted); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: .9rem 0; }
.bubble table { border-collapse: collapse; width: 100%; margin: .55rem 0; font-size: .92em; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: .35rem .55rem; text-align: left; vertical-align: top; }
.bubble th { background: #00000008; font-weight: 700; }
.bubble ul ul, .bubble ol ol, .bubble ul ol, .bubble ol ul { margin: .15rem 0 .15rem 1.1rem; }
.msg.user .bubble th, .msg.user .bubble td { border-color: #ffffff33; }
.msg.user .bubble th { background: #ffffff14; }
.msg.user .bubble blockquote { border-color: #ffffff55; color: #ffffffcc; }
.msg.user .bubble hr { border-color: #ffffff33; }
.msg.user .bubble a { color: #fff; }
.thinking-indicator { color: var(--muted); font-style: italic; animation: donna-thinking 1.4s ease-in-out infinite; }
@keyframes donna-thinking { 0%, 100% { opacity: .3; } 50% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .thinking-indicator { animation: none; opacity: .6; } }
.topbar { display: flex; align-items: center; gap: 12px; }
.topbar-search { flex: 1 1 auto; }
.workspace-switch { grid-column: 2; justify-self: center; min-width: 0; }
.workspace-switch select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: .5rem .65rem; cursor: pointer; width: auto; max-width: 480px;
}
.topbar-link { flex: 0 0 auto; color: var(--muted); font-size: .9rem; }
.topbar-link:hover { color: var(--ink); }
.invite-form { display: flex; gap: .5rem; align-items: center; max-width: 520px; }
.invite-form input { flex: 1 1 auto; }
.invite-form select { flex: 0 0 auto; width: auto; }
.thinking { margin: 0 0 .45rem; max-width: 760px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--sidebar); font-size: .9rem; }
.thinking[hidden] { display: none; }
.thinking > summary { cursor: pointer; padding: .35rem .7rem; color: var(--muted); font-family: var(--sans); font-weight: 600; list-style: none; user-select: none; }
.thinking > summary::-webkit-details-marker { display: none; }
.thinking > summary::before { content: "✦ "; opacity: .55; }
.thinking .think-body { padding: .3rem .8rem .55rem; color: var(--muted); border-top: 1px solid var(--border); }
.thinking .think-body > :first-child { margin-top: 0; }
.thinking .think-body > :last-child { margin-bottom: 0; }

.sidebar-search { margin: .3rem 0 .2rem; }
.sidebar-search input[type="search"] { width: 100%; font-size: .9rem; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); }
.sidebar-search input[type="search"]:focus { outline: none; border-color: var(--accent); }

.copy-btn { opacity: 0; background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: .75rem; color: var(--muted); padding: .1rem .45rem; margin-top: .3rem; transition: opacity .12s; }
.msg.assistant:hover .copy-btn { opacity: .6; }
.copy-btn:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }

.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; margin-bottom: 1.2rem; }
.topbar-search { margin: 0; grid-column: 3; justify-self: end; }
.topbar-search input[type="search"] { width: 280px; max-width: 42vw; font-size: .9rem; padding: .45rem .85rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink); }
.topbar-search input[type="search"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.topbar-profile { display: flex; align-items: center; gap: .5rem; color: var(--ink); font-weight: 600; }
.topbar-profile:hover { color: var(--accent); }
.sidebar-foot .who { color: var(--ink); text-decoration: none; }
.sidebar-foot .who:hover { color: var(--accent); }

[data-theme="dark"] {
  --paper: #16151a; --surface: #1f1e25; --sidebar: #1a191f;
  --ink: #ECEAE4; --text: #ECEAE4; --muted: #a39f98; --faint: #6f6b64;
  --border: #2e2c34; --border-2: #3a3742;
  --accent: #8fb3e0; --accent-hover: #a9c6ec; --accent-soft: #23252e; --accent-ink: #16151a;
  --ok: #7fb39a; --ok-soft: #1d2823; --warn: #cdab6a; --warn-soft: #2a2418; --err: #d98a8a; --err-soft: #2a1d1d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.6);
}

.composer { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--paper) 22%); padding-top: .8rem; margin-top: auto; }
.composer .card { margin: 0; }
.composer textarea { border: 0; padding: .3rem .1rem; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: .6rem; margin-top: .5rem; }
.composer-bar select { width: auto; max-width: 230px; }
.composer-bar .spacer { flex: 1; }

/* ── Tables / tabular grid ─────────────────────────────────── */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.grid th, table.grid td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); vertical-align: top; }
table.grid th { background: #faf9f6; font-weight: 600; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
table.grid th:last-child, table.grid td:last-child { border-right: 0; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.docname { font-weight: 600; white-space: nowrap; }
table.grid td[data-status="generating"] { color: var(--accent); background: var(--accent-soft); animation: pulse 1.3s ease-in-out infinite; }
table.grid td[data-status="error"] { color: var(--err); }
table.grid td[data-status="pending"] { color: var(--faint); }
@keyframes pulse { 50% { opacity: .55; } }

.toolbar { display: flex; align-items: center; gap: .6rem; margin: .9rem 0; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.colhead { display: flex; align-items: center; gap: .4rem; justify-content: space-between; }
.colhead form { display: inline; }
.x-btn { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 0 .2rem; font-size: 1rem; line-height: 1; }
.x-btn:hover { color: var(--err); background: none; }

/* embedded doc viewer */
.doc-embed { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-sm); margin-bottom: 1rem; }
.doc-embed embed { display: block; width: 100%; height: 70vh; border: 0; }
.extract { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.3rem; box-shadow: var(--shadow-sm); }
.extract pre { white-space: pre-wrap; margin: 0; max-height: 62vh; overflow: auto; font-family: var(--sans); font-size: .92rem; color: #2c2a26; }
.extract mark { background: #fbe6a2; color: inherit; border-radius: 3px; padding: 0 2px; }
a.cite { color: var(--accent); text-decoration: none; font-size: .8rem; margin-left: .15rem; opacity: .65; }
a.cite:hover { opacity: 1; }

.redline { line-height: 1.8; }
.redline del { background: var(--err-soft); color: var(--err); text-decoration: line-through; padding: 0 3px; border-radius: 3px; }
.redline ins { background: var(--ok-soft); color: var(--ok); text-decoration: none; padding: 0 3px; border-radius: 3px; }
.edit-pick { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--muted); margin-bottom: .7rem; }
.edit-pick input { width: auto; }

.doc-render { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 2.4rem; box-shadow: var(--shadow-sm); font-family: var(--serif); font-size: 1.02rem; line-height: 1.75; color: var(--ink); }
.doc-render > :first-child { margin-top: 0; }
.doc-render h1, .doc-render h2, .doc-render h3, .doc-render h4 { font-weight: 600; line-height: 1.3; margin: 1.5rem 0 .5rem; }
.doc-render h1 { font-size: 1.5rem; } .doc-render h2 { font-size: 1.25rem; } .doc-render h3 { font-size: 1.08rem; }
.doc-render p { margin: 0 0 .8rem; }
.doc-render ul, .doc-render ol { margin: 0 0 .8rem 1.5rem; padding: 0; }
.doc-render li { margin: .2rem 0; }
.doc-render blockquote { margin: .8rem 0; padding-left: 1rem; border-left: 3px solid var(--border-2); color: var(--muted); }
.doc-render table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .92rem; }
.doc-render th, .doc-render td { border: 1px solid var(--border); padding: .45rem .65rem; text-align: left; vertical-align: top; }
.doc-render th { background: var(--paper); font-weight: 700; }

/* Client-side document viewer (docx-preview / SheetJS / xml) — white "paper" */
.doc-viewer { background: #fff; color: #1c1a17; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: auto; max-height: 85vh; margin-bottom: 1rem; }
.doc-viewer .doc-loading { padding: 2rem; text-align: center; }
.doc-viewer .docx-wrapper { background: transparent; padding: 1.5rem; }
.doc-viewer .docx-wrapper > section.docx { background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.14); margin: 0 auto 1rem; }
.doc-viewer table { border-collapse: collapse; font-size: .85rem; color: #1c1a17; }
.doc-viewer td, .doc-viewer th { border: 1px solid #d8d2c6; padding: .25rem .5rem; white-space: nowrap; }
.doc-viewer .sheet-name { font-weight: 700; padding: .5rem .7rem; background: var(--paper); border-bottom: 1px solid var(--border); }
.doc-viewer .sheet-wrap { overflow: auto; }
.doc-viewer .doc-xml { margin: 0; padding: 1rem 1.2rem; font-size: .8rem; white-space: pre-wrap; word-break: break-word; color: #1c1a17; font-family: var(--mono, monospace); }
.doc-viewer .doc-baseline { padding: 1.5rem 1.8rem; font-family: var(--serif); line-height: 1.7; }
.doc-viewer .doc-baseline h1 { font-size: 1.4rem; margin: 0 0 .6rem; }
.doc-viewer .doc-baseline h2, .doc-viewer .doc-baseline h3 { margin: 1.2rem 0 .4rem; font-weight: 600; }
.doc-viewer .doc-baseline p { margin: 0 0 .7rem; }
.doc-viewer .doc-baseline table { width: 100%; border-collapse: collapse; }
.doc-viewer .doc-baseline th, .doc-viewer .doc-baseline td { border: 1px solid #d8d2c6; padding: .4rem .6rem; }
.extract-details > summary { cursor: pointer; color: var(--muted); font-weight: 600; margin: .4rem 0; }

/* Upload progress + processing modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; background: rgba(20,18,15,.55); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(420px, 92vw); background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 48px rgba(0,0,0,.35); padding: 1.4rem 1.5rem; }
.modal h3 { margin: 0 0 .9rem; font-size: 1.1rem; }
.um-bar-wrap { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin: .2rem 0 .5rem; }
.um-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s ease; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1.1rem; }

/* Donna Review (structured document review) */
.doc-review:not(:empty) { margin-top: .6rem; border-top: 1px solid var(--border); padding-top: .6rem; }
.doc-review h2 { font-size: 1.02rem; font-weight: 700; margin: 1.1rem 0 .35rem; }
.doc-review h2:first-child { margin-top: 0; }
.doc-review h3 { font-size: .96rem; font-weight: 600; margin: .8rem 0 .3rem; }
.doc-review p { margin: 0 0 .6rem; }
.doc-review ul, .doc-review ol { margin: 0 0 .6rem 1.3rem; padding: 0; }
.doc-review li { margin: .15rem 0; }
.doc-review strong { font-weight: 600; }
.doc-review blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid var(--border-2); color: var(--muted); }
.doc-review { overflow-wrap: anywhere; }
.doc-review h1 { font-size: 1.1rem; font-weight: 700; margin: .2rem 0 .55rem; }
.doc-review table { border-collapse: collapse; display: block; width: max-content; max-width: 100%; overflow-x: auto; margin: .4rem 0 .8rem; font-size: .9rem; }
.doc-review th, .doc-review td { border: 1px solid var(--border); padding: .3rem .55rem; text-align: left; vertical-align: top; }
.doc-review th { background: rgba(0, 0, 0, .035); font-weight: 600; }
.doc-review pre { white-space: pre-wrap; overflow-x: auto; background: rgba(0, 0, 0, .045); padding: .6rem .7rem; border-radius: 6px; font-size: .85rem; }
.doc-review pre code { font-size: inherit; background: none; padding: 0; }

/* Storage quota bars (profile) */
.quota-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .3rem; }
.quota-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.quota-bar > span { display: block; height: 100%; min-width: 2px; background: var(--link, #2f6f4f); border-radius: 999px; transition: width .3s; }
.quota-bar.over > span { background: #c0392b; }

/* User guide */
.guide-toc { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .5rem; }
.guide-toc a { color: var(--accent); font-size: .9rem; }
.guide-sec { margin: 1.6rem 0; }
.guide-sec h2 { margin: 0 0 .5rem; }
.guide-sec ul, .guide-sec ol { margin: .4rem 0 .4rem 1.3rem; }
.guide-sec li { margin: .3rem 0; }
.guide-sec p { margin: .4rem 0; }
.guide-sec code { background: var(--accent-soft); padding: 0 .3rem; border-radius: 3px; font-size: .88em; }

.model-pick { font-size: .85rem; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); max-width: 220px; }

.cell-retry { opacity: 0; background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: .8rem; line-height: 1; padding: .12rem .32rem; color: var(--muted); margin-left: .15rem; vertical-align: middle; transition: opacity .12s; }
.grid td:hover .cell-retry { opacity: .6; }
.cell-retry:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }

.empty { color: var(--muted); padding: 1.5rem; text-align: center; border: 1px dashed var(--border-2); border-radius: var(--radius); }

.facets { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; margin-top: .75rem; }
.facet-group { border: 0; padding: 0; margin: 0; }
.facet-group legend { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0; margin-bottom: .3rem; }
.facet { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--ink); padding: .12rem 0; cursor: pointer; }
.facet input { width: auto; margin: 0; }

/* Nested source tree: group (heading) -> jurisdiction (select-all) -> sources */
.source-tree { display: flex; flex-direction: column; gap: .35rem; margin-top: .55rem; }
.src-filter { width: 100%; box-sizing: border-box; font-size: .85rem; padding: .4rem .6rem; margin-bottom: .25rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); }
.src-grouphead { display: flex; align-items: center; gap: .4rem; width: 100%; text-align: left; background: none; border: 0; padding: .25rem 0; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; }
.src-grouphead .muted { font-weight: 600; letter-spacing: 0; text-transform: none; }
.src-caret { display: inline-block; width: .65rem; font-size: .6rem; color: var(--muted); transition: transform .12s ease; }
.src-group:not(.collapsed) > .src-grouphead .src-caret,
.src-juris:not(.collapsed) .src-caret { transform: rotate(90deg); }
.src-group.collapsed > .src-groupbody { display: none; }
.src-groupbody { display: flex; flex-direction: column; gap: .15rem; margin: .1rem 0 .35rem .3rem; padding-left: .65rem; border-left: 1px solid var(--border); }
.src-jurishead { display: flex; align-items: center; gap: .25rem; }
.src-caret-btn { background: none; border: 0; padding: .1rem; line-height: 1; cursor: pointer; }
.src-parent { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; font-weight: 600; color: var(--ink); cursor: pointer; }
.src-parent input { width: auto; margin: 0; }
.src-parent .muted { font-weight: 400; font-size: .8rem; }
.src-juris.collapsed > .src-children { display: none; }
.src-children { display: flex; flex-direction: column; gap: .05rem; margin: .1rem 0 .25rem 1.1rem; padding-left: .7rem; border-left: 1px solid var(--border); }
.src-child { display: flex; align-items: center; gap: .4rem; font-size: .87rem; color: var(--ink); padding: .1rem 0; cursor: pointer; }
.src-child input { width: auto; margin: 0; }
.src-child .muted { font-size: .8rem; }
.chat-scope { margin: .35rem 0 0; font-size: .85rem; }
.chat-scope > summary { cursor: pointer; color: var(--muted); padding: .15rem 0; }
.scope-opt { display: inline-flex; align-items: center; gap: .35rem; margin: .2rem .9rem .2rem 0; color: var(--ink); }
.scope-opt input { width: auto; }
.scope-law { margin-top: .25rem; }
.scope-label { color: var(--muted); margin-right: .4rem; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; flex-direction: row; align-items: center; padding: .8rem 1rem; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; font-size: 1.25rem; }
  .nav { flex-direction: row; margin-left: 1rem; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .foot-tools { display: none; }
  .who-name { display: none; }
  .page { padding: 1.4rem 1.1rem 3rem; }
  .msg { max-width: 90%; }
}

/* Corpus control panel */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-cards .stat { margin-bottom: 0; }
.stat-label {
  font-size: .76rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.stat-value {
  font-family: var(--serif); font-size: 1.8rem; line-height: 1.1;
  margin: .35rem 0 .2rem; color: var(--ink);
}
.data-table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td {
  text-align: left; padding: .7rem .85rem;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.data-table thead th {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--paper);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td form { display: inline; margin: 0; }

/* ── Search: framed resource quadrants ─────────────────────── */
.resource-search { display: flex; gap: .5rem; margin: 0 0 1.6rem; }
.resource-search input[type="search"] {
  flex: 1 1 auto; border-radius: 999px; padding: .6rem 1rem;
  border: 1px solid var(--border-2); background: var(--surface);
}
.resource-search input[type="search"]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.resource-search button { flex: 0 0 auto; border-radius: 999px; }

.search-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.search-quad {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.quad-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .7rem 1rem; border-bottom: 1px solid var(--border); background: var(--sidebar);
}
.quad-head h2 { margin: 0; font-size: 1.02rem; letter-spacing: -.01em; }
.quad-count {
  font-size: .72rem; font-weight: 600; color: var(--muted);
  background: var(--paper); border: 1px solid var(--border-2); border-radius: 999px;
  padding: .05rem .5rem; min-width: 1.5rem; text-align: center;
}
.quad-body { padding: .35rem; overflow-y: auto; max-height: 360px; }
.quad-row {
  display: flex; flex-direction: column; gap: .12rem;
  padding: .5rem .6rem; border-radius: var(--radius-sm); color: var(--ink);
}
.quad-row:hover { background: var(--accent-soft); }
.quad-title {
  font-weight: 500; font-size: .92rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.quad-meta { font-size: .78rem; color: var(--muted); }
.quad-empty { padding: 1.2rem .6rem; text-align: center; color: var(--faint); font-size: .88rem; }

@media (max-width: 760px) { .search-grid { grid-template-columns: 1fr; } }
