:root {
  --bg: #f6f5f1; --surface: #ffffff; --text: #1f2421; --muted: #6b716c; --border: #e2e0d8;
  --accent: #3f6b3a; --accent-soft: #e6efe3; --warn: #8a5a00; --warn-soft: #fbf0d9;
  --error: #a3312a; --error-soft: #fbe6e4; --project: #2f5d7c; --project-soft: #e3edf4;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917; --surface: #1f2321; --text: #e7e9e6; --muted: #9aa19b; --border: #333a35;
    --accent: #8fc286; --accent-soft: #263325; --warn: #e5b55a; --warn-soft: #3a2f19;
    --error: #ef8a82; --error-soft: #3d2220; --project: #8fbbd9; --project-soft: #1f2e38;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .4rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
main { max-width: 1280px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Top bar: logo and search on the left, actions and administration on the right. */
.topbar { position: relative; display: grid; grid-template-columns: auto minmax(0, 600px) minmax(max-content, 1fr);
  align-items: center; gap: 1.25rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.topbar .search-box { max-width: none; }
.topbar-action { display: inline-flex; align-items: center; gap: .4rem; height: 2.15rem; padding: 0 .95rem 0 .7rem; border-radius: 999px;
  font-size: .9rem; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.topbar-action:hover { text-decoration: none; }
.topbar-action svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.topbar-action.topbar-ask { color: var(--project); background: var(--project-soft); }
.topbar-action.topbar-ask:hover, .topbar-action.topbar-ask.active { border-color: var(--project); }
.topbar-action.topbar-upload { color: #fff; background: var(--accent); }
.topbar-action.topbar-upload:hover, .topbar-action.topbar-upload.active { background: color-mix(in srgb, var(--accent) 85%, #000); }
.topbar-action.topbar-upload svg { stroke-width: 2.4; }
@media (prefers-color-scheme: dark) { .topbar-action.topbar-upload { color: #111; } }
.menu { position: relative; display: flex; margin: 0; }
.menu summary { list-style: none; cursor: pointer; color: var(--muted); user-select: none; display: flex; align-items: center; gap: .4rem;
  height: 2.15rem; padding: 0 .7rem; border-radius: 999px; font-size: .92rem; }
.menu summary svg { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.menu summary:hover, .menu[open] summary { background: var(--bg); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: ""; display: inline-block; width: .38em; height: .38em; margin: -.2em 0 0 .05em;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.menu[open] summary::after { transform: rotate(-135deg); margin-top: .2em; }
.menu summary:hover, .menu[open] summary, .menu summary.active { color: var(--text); }
.menu summary.active { font-weight: 600; }
.menu-items { position: absolute; top: calc(100% + .55rem); right: 0; z-index: 20; min-width: 210px; display: flex; flex-direction: column;
  padding: .35rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / .12); }
.menu-items a, .menu-items button.link { display: block; width: 100%; text-align: left; padding: .45rem .7rem; border-radius: 6px; color: var(--text); font-size: .92rem; }
.menu-items a:hover, .menu-items button.link:hover { background: var(--bg); text-decoration: none; }
.menu-items a.active { font-weight: 600; background: var(--accent-soft); }
.menu-items hr { border: 0; border-top: 1px solid var(--border); margin: .3rem .2rem; }
.menu-items form { margin: 0; }
.menu-items button.link { color: var(--muted); }

input[type=text], input[type=search], input[type=email], input[type=password], select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; max-width: 100%;
}
textarea { width: 100%; }
.button, input[type=submit], button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: .45rem .9rem; display: inline-block; }
.button:hover { text-decoration: none; }
.button.primary, input[type=submit].primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .button.primary, input[type=submit].primary { color: #111; } }
.button.small { padding: .25rem .6rem; font-size: .85rem; }
.button.danger { color: var(--error); }
button.link { background: none; border: 0; color: var(--muted); padding: 0; }
form.button_to { display: inline; }

.flash { padding: .6rem .8rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash.notice { background: var(--accent-soft); }
.flash.alert { background: var(--error-soft); color: var(--error); }

.search .q { width: 100%; font-size: 1.1rem; padding: .7rem .9rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .6rem 0 1rem; }
.summary { margin-bottom: .6rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; text-align: left; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
table.documents td.what { max-width: 420px; }
tr.dup { opacity: .55; }
.tags { min-width: 180px; }
.empty-state { text-align: center; color: var(--muted); padding: 2rem; }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; }
.pager a { padding: .2rem .55rem; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); }
.pager a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.badge { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin: 1px 0; white-space: nowrap; }
.badge.project { background: var(--project-soft); color: var(--project); }
.badge.empty { background: transparent; color: var(--muted); border: 1px dashed var(--border); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--error-soft); color: var(--error); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card h2 { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: .7rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
.stack label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
fieldset.company { border: 0; padding: 0; margin: .4rem 0 0; }
fieldset.company legend { font-weight: 600; color: var(--text); margin-bottom: .2rem; padding: 0; }
fieldset.company .row { align-items: flex-start; }
fieldset.company .row label { flex: 1 1 8rem; }
.inline { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

.doc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.preview { position: sticky; top: 1rem; }
.preview iframe { width: 100%; height: 85vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.preview img { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.amount { font-size: 1.6rem; font-weight: 700; margin: .2rem 0 .6rem; }
table.kv { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.kv th { width: 140px; color: var(--muted); font-weight: 500; }
details { margin-top: 1rem; }
pre { white-space: pre-wrap; font-size: .8rem; background: var(--surface); border: 1px solid var(--border); padding: .8rem; border-radius: var(--radius); }
.actions { margin-top: 1.5rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.category-row { padding: .3rem 0; border-bottom: 1px solid var(--border); }
.category-row input[type=text] { flex: 1; min-width: 120px; }
.category-row.new { border-bottom: 0; padding-top: .7rem; }
table.report td, table.report th { white-space: nowrap; }
table.report tfoot td, table.report tfoot th { border-top: 2px solid var(--border); }

.login { max-width: 340px; margin: 12vh auto; text-align: center; }
.login .stack { margin-top: 1.5rem; }

@media (max-width: 860px) {
  .doc, .two-col { grid-template-columns: 1fr; }
  .preview { position: static; order: 2; }
  .preview iframe { height: 60vh; }
}

@media (max-width: 640px) {
  .filters select { flex: 1 1 45%; }
  table.documents thead { display: none; }
  table.documents, table.documents tbody, table.documents tr, table.documents td { display: block; }
  table.documents tr { display: grid; grid-template-columns: 1fr auto; gap: .15rem .6rem; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
  table.documents td { border: 0; padding: 0; }
  table.documents td:nth-child(1) { grid-column: 1; color: var(--muted); font-size: .85rem; }
  table.documents td.num { grid-column: 2; grid-row: 1 / 3; font-weight: 600; }
  table.documents td:nth-child(2) { grid-column: 1; }
  table.documents td.what, table.documents td.tags { grid-column: 1 / -1; max-width: none; min-width: 0; font-size: .9rem; }
}

/* --- Search --- */
mark { background: var(--warn-soft); color: inherit; font-weight: 600; padding: 0 1px; border-radius: 2px; }
.search-box { position: relative; max-width: 720px; }
.search-field { display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .15rem 1rem; }
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 1px 6px rgba(0,0,0,.08); }
.search-field svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; }
.search-field input[type=search] { border: 0; background: transparent; flex: 1; min-width: 0; padding: .55rem 0; font-size: 1rem; outline: none; }
.search-box.big { margin: 1.2rem auto 0; }
.search-box.big .search-field { padding: .35rem 1.2rem; }
.search-box.big input[type=search] { font-size: 1.15rem; }
.suggestions { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 20; padding: .3rem 0; }
.suggestion { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 1.1rem; color: var(--text); }
.suggestion:hover, .suggestion.active { background: var(--bg); text-decoration: none; }
.suggestion .hint { color: var(--muted); font-size: .85rem; white-space: nowrap; }

.home { max-width: 760px; margin: 8vh auto 0; text-align: center; }
.home .logo { font-size: 3rem; letter-spacing: -.02em; color: var(--accent); margin: 0; }
.home .search-box { text-align: left; }
.try { margin: 1rem 0 2rem; display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; align-items: center; }
.browse { text-align: left; display: grid; gap: 1rem; }
.browse h2, .recent h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .4rem; }
.recent { text-align: left; margin-top: 1.8rem; }
.recent-item { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--border); color: var(--text); }
.help { text-align: left; margin: 1.5rem 0 3rem; color: var(--muted); }
.help summary { cursor: pointer; }
.help li { margin: .35rem 0; }

.chip { display: inline-block; padding: .25rem .7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .88rem; margin: 0 .15rem .3rem 0; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.project { color: var(--project); }
.chip.ghost { border-style: dashed; color: var(--muted); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.tools { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: .9rem 0 .2rem; max-width: 1080px; }
.tools .spacer { flex: 1; }
.tools .sort select { padding: .3rem .5rem; font-size: .88rem; }
.stats { color: var(--muted); margin: .3rem 0 1rem; }
.stats strong { color: var(--text); }

.serp { display: grid; grid-template-columns: minmax(0, 720px) 240px; gap: 2.5rem; align-items: start; }
.result { padding: .2rem 0 1.1rem; }
.result h3 { font-size: 1.08rem; font-weight: 500; margin: 0 0 .1rem; }
.result h3 a { color: var(--accent); }
.result .meta { margin: 0; font-size: .88rem; color: var(--muted); }
.result .meta strong { color: var(--text); }
.result .snippet { margin: .3rem 0 .2rem; font-size: .92rem; line-height: 1.5; }
.result .tags { margin: .2rem 0 0; }
.result.dup { opacity: .55; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1.1rem; margin-bottom: 1.4rem; }
.panel h2 { margin: 0; font-size: 1.25rem; }
.panel-stats { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; margin: .5rem 0; font-size: .92rem; }
.facets section { margin-bottom: 1.3rem; }
.facets h4 { margin: 0 0 .3rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.facet { display: flex; justify-content: space-between; gap: .5rem; padding: .22rem .5rem; border-radius: 6px; color: var(--text); font-size: .9rem; }
.facet:hover { background: var(--surface); text-decoration: none; }

@media (max-width: 860px) {
  .serp { grid-template-columns: 1fr; }
  .facets { order: -1; display: flex; gap: .4rem; overflow-x: auto; }
  .facets section { margin: 0; flex: none; }
  .facets h4 { display: none; }
  .facets section { display: flex; gap: .3rem; }
  .facet { border: 1px solid var(--border); border-radius: 999px; background: var(--surface); white-space: nowrap; }
  /* Search drops to its own full-width row under the actions. */
  .topbar { grid-template-columns: 1fr auto; gap: .55rem 1rem; }
  .topbar-center { grid-column: 1 / -1; grid-row: 2; }
  .topbar-center:empty { display: none; }
  .topbar-right { grid-column: 2; grid-row: 1; }
  .home { margin-top: 3vh; }
  .home .logo { font-size: 2.3rem; }
}
/* Filter chips, count and totals on the left, downloads and sort on the right; details in the totals' title. */
.stats { display: flex; gap: .4rem 1rem; align-items: center; justify-content: space-between; max-width: 736px; margin-top: .8rem; }
.stats-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; min-width: 0; }
.stats-chips .chip { margin: 0; }
.stats-totals { font-size: .9rem; }
.stats-totals[title] { cursor: help; }
/* Phones: chips and actions share the first row, the totals get the full width under them. */
@media (max-width: 640px) {
  .stats { flex-wrap: wrap; gap: .4rem; }
  .stats-chips { display: contents; }
  .stats-actions { margin-left: auto; }
  .stats-totals { order: 1; flex: 1 1 100%; }
}
.stats-totals .nowrap { white-space: nowrap; }
.stats-actions { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.stats .sort { margin: 0; }
.stats .sort select { padding: .3rem .5rem; font-size: .88rem; }
.menu.export-menu { position: relative; }
.menu.export-menu summary { height: auto; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: .3rem .6rem; font-size: .88rem; }
.export-menu .menu-items { min-width: 250px; }
.export-menu .menu-items a:first-child { display: flex; flex-direction: column; gap: .1rem; }
.correction { margin: .8rem 0 0; font-size: .95rem; }

/* --- Document list (feed + results) --- */
.home { max-width: 960px; margin: 3rem auto 0; text-align: left; }
.hero { text-align: center; max-width: 760px; margin: 0 auto; }
.hero .search-box { text-align: left; }
.chip.ask { border-color: var(--project); color: var(--project); }

.shortcuts { display: flex; gap: .45rem; overflow-x: auto; padding: .2rem 0 .8rem; margin: .4rem 0 .6rem; scrollbar-width: thin; }
.shortcut { flex: none; display: inline-flex; align-items: center; gap: .45rem; padding: .4rem .8rem .4rem .45rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .9rem; }
.shortcut:hover { text-decoration: none; border-color: hsl(var(--h, 200) 40% 55%); }
.shortcut-icon { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: hsl(var(--h, 200) 55% 92%); font-size: .95rem; }
.shortcut.project .shortcut-icon { background: var(--project-soft); }
@media (prefers-color-scheme: dark) { .shortcut-icon { background: hsl(var(--h, 200) 25% 22%); } }

h3.month { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  font-size: .95rem; margin: 1.6rem 0 .5rem; padding: 0 .2rem; }
h3.month a { color: var(--text); }
h3.month .muted { font-weight: 400; font-size: .85rem; }
.center { text-align: center; }

.doc-list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.doc-row { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) auto 8.5rem; gap: .9rem; align-items: center;
  padding: .75rem 1rem; color: var(--text); border-bottom: 1px solid var(--border); }
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--bg); text-decoration: none; }
.doc-row.dup { opacity: .5; }
.doc-icon { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 12px; font-size: 1.25rem;
  background: hsl(var(--h, 200) 55% 92%); }
.doc-icon.empty { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 1rem; }
@media (prefers-color-scheme: dark) { .doc-icon { background: hsl(var(--h, 200) 25% 22%); } }
.doc-main { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.doc-title { font-weight: 600; font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub strong { color: var(--text); font-weight: 500; }
.doc-snippet { font-size: .86rem; color: var(--muted); margin-top: .15rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-snippet mark { color: var(--text); }
.doc-tags { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; max-width: 300px; }
.tag { font-size: .75rem; padding: .12rem .5rem; border-radius: 999px; white-space: nowrap;
  background: hsl(var(--h, 200) 55% 93%); color: hsl(var(--h, 200) 45% 28%); }
.tag.project { background: var(--project-soft); color: var(--project); }
.tag.pending { background: transparent; border: 1px dashed var(--warn); color: var(--warn); }
@media (prefers-color-scheme: dark) { .tag { background: hsl(var(--h, 200) 25% 22%); color: hsl(var(--h, 200) 50% 80%); } }
.doc-amount { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-amount strong { font-size: .98rem; }
.doc-amount .muted { font-size: .78rem; }

@media (max-width: 760px) {
  .home { margin-top: 1.2rem; }
  /* Title and supplier get the full width; tags and amount share the line below. */
  .doc-row { grid-template-columns: 2.4rem minmax(0, 1fr) auto; gap: .35rem .7rem; padding: .75rem .8rem; align-items: start; }
  .doc-icon { width: 2.4rem; height: 2.4rem; grid-row: span 2; border-radius: 10px; }
  .doc-main { grid-column: 2 / 4; }
  .doc-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .doc-tags { grid-column: 2; justify-content: flex-start; max-width: none; align-self: center; }
  .doc-tags:empty { visibility: hidden; }
  .doc-amount { grid-column: 3; grid-row: 2; align-self: center; }
  .doc-amount .muted { display: none; }
  h3.month { margin-top: 1.3rem; }
}

@media (max-width: 640px) {
  .topbar { padding: .55rem 12px; gap: .5rem; }
  .topbar-right { gap: .35rem; }
  .topbar-action { padding: 0 .75rem 0 .55rem; font-size: .86rem; }
  /* Administration shrinks to its icon; the menu opens as a full-width sheet under the top bar. */
  .menu summary { padding: 0 .5rem; }
  .menu summary .label { display: none; }
  .menu { position: static; }
  .menu-items { top: calc(100% - .2rem); left: 12px; right: 12px; }
  main { padding-top: 1rem; }
  .home { margin-top: .4rem; }
  .home .logo { font-size: 2rem; }
  .tools { gap: .4rem; }
  .doc-list, .panel { border-radius: 12px; }
  /* Long tables scroll sideways with the label column pinned. */
  table.report th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
  table.kv th { width: 110px; }
}

/* --- Ask Codex --- */
.ask { max-width: 820px; margin: 0 auto; }
.ask-form { display: flex; gap: .6rem; align-items: flex-end; margin: 1rem 0 .6rem; }
.ask-form textarea { flex: 1; font-size: 1.05rem; padding: .7rem .9rem; border-radius: 12px; resize: vertical; }
.ask .try { justify-content: flex-start; margin: .4rem 0 1.5rem; }
h1.question { font-size: 1.35rem; margin: .5rem 0 1rem; }
.answer { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--project); border-radius: 12px; padding: 1rem 1.2rem; line-height: 1.55; }
.answer p:first-child { margin-top: 0; } .answer p:last-child { margin-bottom: 0; }
.answer.pending { display: flex; gap: .7rem; align-items: center; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--project); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.answer-total { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: baseline; margin: 1.2rem 0 .6rem; }
.question-row { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); }
.question-row:last-child { border-bottom: 0; }
.question-row:hover { background: var(--bg); text-decoration: none; }
@media (max-width: 640px) { .ask-form { flex-direction: column; align-items: stretch; } }
.classify details summary { cursor: pointer; color: var(--accent); margin-top: .3rem; }
.classify details[open] summary { margin-bottom: .6rem; }
.classified { margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
@media (min-width: 761px) { .shortcuts { flex-wrap: wrap; overflow: visible; } }
.empty-state ul { list-style: none; padding: 0; }
/* Search results column is narrow: tags go under the title so titles stay readable. */
@media (min-width: 761px) {
  .serp .doc-row { grid-template-columns: 2.6rem minmax(0, 1fr) auto; align-items: start; row-gap: .4rem; }
  .serp .doc-icon { grid-row: span 2; }
  .serp .doc-title { white-space: normal; }
  .serp .doc-tags { grid-column: 2; grid-row: 2; justify-content: flex-start; max-width: none; }
  .serp .doc-amount { grid-column: 3; grid-row: 1; }
}

/* --- Bulk upload --- */
.upload-page { max-width: 960px; margin: 0 auto; }
.dropzone { display: grid; place-items: center; text-align: center; min-height: 190px; margin: 1rem 0; padding: 1.5rem 1rem;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: 14px; background: var(--surface);
  cursor: pointer; transition: background .15s, border-color .15s, transform .15s; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); outline: none; }
.dropzone.hot { border-color: var(--accent); border-style: solid; background: var(--accent-soft); transform: scale(1.01); }
.dropzone.busy { cursor: copy; }
.dropzone-idle, .dropzone-busy { display: flex; flex-direction: column; align-items: center; gap: .35rem; width: 100%; max-width: 520px; }
.dropzone [hidden] { display: none; }
.dropzone-idle strong { font-size: 1.05rem; }
.dropzone-icon { display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%; margin-bottom: .3rem;
  background: var(--accent-soft); color: var(--accent); font-size: 1.4rem; font-weight: 700; }
.dropzone.hot .dropzone-icon { background: var(--accent); color: var(--surface); }
.dropzone button.link { padding: 0; border: 0; background: none; color: var(--accent); font-size: inherit; }
.dropzone button.link:hover { text-decoration: underline; }
.progress { width: 100%; height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin: .35rem 0; }
.progress-bar { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .4s ease; }
.upload-notes { display: flex; flex-direction: column; gap: .4rem; margin: -.4rem 0 1rem; }
.upload-note { padding: .55rem .8rem; border-radius: var(--radius); font-size: .9rem; background: var(--surface); border: 1px solid var(--border); }
.upload-note.ok { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.upload-note.error { background: var(--error-soft); border-color: transparent; color: var(--error); }
.upload-note strong { font-weight: 500; }
.upload-note details { margin-top: .2rem; } .upload-note summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.upload-note ul { margin: .3rem 0 0; padding-left: 1.2rem; max-height: 220px; overflow: auto; }
.upload-summary { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.upload-summary > p:only-child { margin: 0; }
.upload-stats { display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin-bottom: .5rem; }
.upload-stats .stat { display: flex; flex-direction: column; }
.upload-stats .stat strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.upload-stats .stat span { color: var(--muted); font-size: .82rem; display: inline-flex; align-items: center; gap: .3rem; }
.upload-stats .reading strong { color: var(--project); }
.upload-stats .ok strong { color: var(--accent); }
.upload-stats .failed strong, .error-text { color: var(--error); }
.upload-summary .progress { height: 10px; }
.upload-summary.done .progress-bar { background: var(--accent); }
.batch-export { margin-top: .8rem; }
.batch-export .muted { flex-basis: 100%; }
details.rename { margin: -.2rem 0 1rem; }
details.rename summary { cursor: pointer; }
details.rename form { margin-top: .4rem; }
.upload-status { margin: .3rem 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; }
.spinner.tiny { width: 11px; height: 11px; border-width: 2px; display: inline-block; }
.upload-list:empty { display: none; }
.upload-list .doc-row { border-bottom: 1px solid var(--border); }
.upload-list > .upload-item:last-child .doc-row { border-bottom: 0; }
.upload-row:hover { background: transparent; }
.upload-row.pending .doc-title, .upload-row.extracting .doc-title { color: var(--muted); font-weight: 500; }
.upload-row.failed .doc-icon { border-color: var(--error); color: var(--error); font-weight: 700; }
.upload-row .doc-amount form { margin: 0; }
.recent-batches { margin-top: 2rem; }
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) { .touch-only { display: inline; } .pointer-only { display: none; } .dropzone { min-height: 150px; } }

/* --- Settings --- */
.settings { max-width: 860px; margin: 0 auto; }
.settings-section { margin-top: 2rem; }
.settings-section h2 { font-size: 1.15rem; margin-bottom: .3rem; }
.ai-status { margin: .8rem 0 1rem; padding: .7rem .9rem; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.ai-status.missing { background: var(--warn-soft); color: var(--warn); }
.ai-cards { display: grid; gap: .8rem; }
.ai-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .7rem; }
.ai-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ai-card header { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr) auto; gap: .8rem; align-items: start; }
.ai-card h3 { margin: 0; font-size: 1rem; }
.ai-card header p { margin: .1rem 0 0; }
.ai-card form, .ai-card p { margin: 0; }
.ai-card .stack { max-width: 460px; }
.ai-logo { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 10px; font-size: 1.2rem; background: var(--bg); }
.ai-logo.chatgpt { background: #e7f3ee; color: #10805f; }
.ai-logo.claude { background: #f8ebe4; color: #c2593a; }
@media (prefers-color-scheme: dark) { .ai-logo.chatgpt { background: #1d3229; color: #6fd1ad; } .ai-logo.claude { background: #3a2720; color: #ec9677; } }
.device-steps { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .7rem; }
.device-code { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; }
.device-code code { font-size: 1.6rem; font-weight: 700; letter-spacing: .12em; padding: .3rem .8rem; border-radius: 8px; background: var(--bg); border: 1px dashed var(--border); }
.ai-usage { margin-top: .8rem; }
.user-list { margin: .6rem 0; }
.user-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem; padding: .65rem 1rem; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.user-row form { margin: 0; }
.user-actions { display: flex; gap: .9rem; }
button.link.danger { color: var(--error); }
.add-user { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.add-user input[type=email], .add-user input[type=text] { flex: 1 1 220px; }
.stack.narrow { max-width: 360px; }
.menu-account { padding: .3rem .7rem .2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flash.ai-missing { background: var(--warn-soft); color: var(--warn); }
.flash.ai-missing a { font-weight: 600; color: var(--warn); }
