/* 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; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-family: var(--sans); font-weight: 700; font-size: .95rem;
  letter-spacing: 0;
}

.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; align-items: center; justify-content: space-between; gap: .5rem; }
.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; }
.page { 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: .3rem; }
.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 { 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: flex; align-items: center; justify-content: flex-end; gap: 1rem; margin-bottom: 1.2rem; }
.topbar-search { margin: 0; flex: 0 1 auto; }
.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; }

.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); }

/* ── 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; }
  .who-name { display: none; }
  .page { padding: 1.4rem 1.1rem 3rem; }
  .msg { max-width: 90%; }
}
