/* „Досие" design system — inherited from kolko-struva/DESIGN.md.
   Premium-editorial restraint: Sofia Sans + Sofia Sans Condensed, one hero green,
   warm neutrals, document-forward, mobile-first. */
:root {
  --bg: #faf8f4;
  --ink: #1b1a18;
  --ink-soft: #565049;
  --ink-faint: #8a8278;
  --surface: #f4f5f7;
  --surface-2: #fffdf9;
  --line: #e7e2da;
  --line-soft: #efeae2;
  --green: #1d7d5a;
  --green-ink: #14563e;
  --green-wash: #e9f3ee;
  --ochre: #c08a3a;
  --ochre-wash: #f6edddff;
  --terracotta: #b0544b;
  --terracotta-wash: #f6e7e4;
  --r-card: 10px;
  --r-btn: 9px;
  --r-pill: 99px;
  --shadow: 0 1px 2px rgba(27, 26, 24, 0.04), 0 8px 24px rgba(27, 26, 24, 0.06);
  --shadow-soft: 0 1px 2px rgba(27, 26, 24, 0.05);
  --font: 'Sofia Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-cond: 'Sofia Sans Condensed', 'Sofia Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* Respect the `hidden` attribute even when an element sets its own display. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.muted { color: var(--ink-faint); }
.num { font-family: var(--font-cond); font-weight: 700; letter-spacing: 0.01em; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: baseline; gap: 8px; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 4px; align-self: center;
  background: linear-gradient(135deg, var(--green), var(--green-ink));
}
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }
.brand-by { color: var(--ink-faint); font-size: 13px; font-weight: 600; }
.topbar-lib { color: var(--ink-soft); font-weight: 600; font-size: 14px; }
.topbar-lib:hover { color: var(--green); }

main { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- landing / hero ---------- */
.page-landing main { max-width: 760px; }
.hero { padding: 56px 0 8px; text-align: center; }
.hero h1 { font-size: clamp(30px, 7vw, 46px); font-weight: 800; letter-spacing: -0.025em; margin: 0 0 12px; }
.lede { font-size: clamp(16px, 3.4vw, 19px); color: var(--ink-soft); margin: 0 auto 28px; max-width: 30em; }

.dropzone {
  position: relative; display: block; border: 1.5px dashed var(--line);
  border-radius: 16px; background: var(--surface-2); padding: 44px 24px;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}
.dropzone.dragover { border-color: var(--green); background: var(--green-wash); transform: translateY(-1px); }
.dropzone.busy .dz-inner, .dropzone.busy .dz-staged { display: none; }

/* staged files (before starting) */
.dz-staged { display: flex; flex-direction: column; align-items: stretch; gap: 8px; text-align: left; }
.dz-staged-title { font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: 0; }
.staged-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.staged-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-btn); padding: 8px 12px;
}
.staged-name { font-size: 14px; font-weight: 600; word-break: break-all; }
.staged-x { border: 0; background: transparent; color: var(--ink-faint); font-size: 18px; line-height: 1; cursor: pointer; flex: none; }
.staged-x:hover { color: var(--terracotta); }
.dz-staged .dz-pick { align-self: flex-start; font-size: 13px; }

/* primary start button */
.start-btn {
  display: block; width: 100%; max-width: 34em; margin: 16px auto 0;
  border: 0; border-radius: var(--r-btn); background: var(--green); color: #fff;
  font-weight: 800; font-size: 16px; padding: 14px 20px;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
.start-btn:not(:disabled):hover { background: var(--green-ink); }
.start-btn:not(:disabled):active { transform: translateY(1px); }
.start-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dz-icon {
  width: 46px; height: 46px; border-radius: 12px; margin-bottom: 6px;
  background: var(--green-wash);
  -webkit-mask: center / 24px no-repeat var(--doc-svg); mask: center / 24px no-repeat var(--doc-svg);
  background-color: var(--green);
}
.dz-icon {
  --doc-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M14 3v4a1 1 0 0 0 1 1h4'/><path d='M17 21H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7l5 5v11a2 2 0 0 1-2 2z'/><path d='M9 13h6M9 17h4'/></svg>");
}
.dz-title { font-size: 19px; font-weight: 700; margin: 0; }
.dz-or { margin: 0; color: var(--ink-soft); }
.dz-pick { color: var(--green); font-weight: 700; cursor: pointer; border-bottom: 1.5px solid transparent; }
.dz-pick:hover { border-color: var(--green); }
.dz-caption { font-size: 13px; color: var(--ink-faint); margin: 8px 0 0; }
.dz-progress { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 8px 0; }
.dz-status { font-weight: 600; margin: 0; }
.dz-spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green); animation: spin 0.8s linear infinite;
}
.dz-error { color: var(--terracotta); font-weight: 600; margin: 14px 0 0; }

.prompt-box { max-width: 34em; margin: 18px auto 0; text-align: left; }
.prompt-box label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.prompt-box .opt { color: var(--ink-faint); font-weight: 400; }
.prompt-box textarea {
  width: 100%; resize: vertical; min-height: 46px; font-family: inherit; font-size: 14px;
  color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-btn); padding: 10px 12px; outline: none;
}
.prompt-box textarea:focus { border-color: var(--green); }

.consent {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  margin: 18px auto 0; max-width: 34em; font-size: 13px; color: var(--ink-soft);
}
.consent input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--green); flex: none; }

.privacy { font-size: 13px; color: var(--ink-faint); margin: 26px 0 0; }

/* ---------- library (/my) ---------- */
.library { padding: 8px 0 64px; }
.library h1 { font-size: 30px; font-weight: 800; margin: 0 0 2px; }
.library.empty { text-align: center; padding-top: 48px; }
.library.empty .start-btn-link { display: inline-block; width: auto; margin-top: 20px; padding: 12px 24px; text-decoration: none; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 18px; }
.doc-card-wrap { position: relative; transition: opacity 0.22s ease, transform 0.22s ease; }
.doc-card-wrap.removing { opacity: 0; transform: scale(0.95); }
.doc-card {
  display: flex; flex-direction: column; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden;
  box-shadow: var(--shadow-soft); transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.doc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.doc-card-del {
  position: absolute; top: 7px; right: 7px; z-index: 2; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: rgba(28, 25, 23, 0.5); color: #fff;
  font-size: 19px; line-height: 1; cursor: pointer; backdrop-filter: blur(2px);
  transition: background 0.15s ease, transform 0.15s ease;
}
.doc-card-del:hover { background: var(--terracotta); transform: scale(1.08); }
.doc-card-del:disabled { opacity: 0.5; cursor: default; }
.doc-card-thumb { height: 110px; background: var(--surface) center / cover no-repeat; border-bottom: 1px solid var(--line-soft); }
.doc-card-thumb.is-text {
  display: flex; align-items: center; justify-content: center;
  background:
    var(--surface)
    center / 30px no-repeat
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231d7d5a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M14 3v4a1 1 0 0 0 1 1h4'/><path d='M17 21H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7l5 5v11a2 2 0 0 1-2 2z'/><path d='M9 13h6M9 17h4'/></svg>");
}
.doc-card-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.doc-card-type { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.doc-card-name { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-high { background: var(--green); }
.dot-review { background: var(--ochre); }
.dot-uncertain { background: var(--terracotta); }

/* ---------- workspace ---------- */
.page-workspace main { max-width: 1180px; padding-bottom: 0; }
.workspace { display: flex; flex-direction: column; min-height: calc(100dvh - 57px); }
.ws-bar { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.ws-back { color: var(--ink-soft); font-weight: 600; font-size: 14px; flex: none; }
.ws-back:hover { color: var(--green); }
.ws-file { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.btn-summary {
  flex: none; border: 1px solid var(--green); background: var(--green); color: #fff;
  font-weight: 700; font-size: 13px; padding: 8px 16px; border-radius: var(--r-btn);
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn-summary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-summary:not(:disabled):hover { background: var(--green-ink); }
.btn-summary:not(:disabled):active { transform: translateY(1px); }

.ws-tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: var(--r-btn); margin-bottom: 10px; }
.ws-tab { flex: 1; border: 0; background: transparent; color: var(--ink-soft); font-weight: 700; font-size: 14px; padding: 9px; border-radius: 7px; }
.ws-tab.is-active { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow-soft); }

/* documents-in-conversation strip (the dossier) */
.ws-docs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 0 12px; }
.ws-docs-label { font-size: 12px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--ink-faint); }
.ws-docs-list { display: flex; gap: 6px; flex-wrap: wrap; }
.ws-doc-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  padding: 5px 11px; border-radius: var(--r-pill); cursor: pointer; text-decoration: none;
}
.ws-doc-chip:hover { border-color: var(--green); }
.ws-doc-chip.is-current { border-color: var(--green); background: var(--green-wash); color: var(--green-ink); }
.ws-doc-chip.pending .ws-doc-name { color: var(--ink-faint); font-style: italic; }
.ws-doc-name { color: inherit; text-decoration: none; }
.ws-doc-chip:hover .ws-doc-name { color: var(--green); }
.ws-doc-x {
  border: 0; background: transparent; color: var(--ink-faint); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 0 0 2px; border-radius: 50%;
}
.ws-doc-x:hover { color: var(--terracotta); }
.ws-add {
  font-size: 13px; font-weight: 700; color: var(--green); background: transparent;
  border: 1px dashed var(--green); border-radius: var(--r-pill); padding: 5px 12px;
}
.ws-add:hover { background: var(--green-wash); }
.ws-add:disabled { opacity: 0.5; cursor: not-allowed; }

.ws-panes { flex: 1; min-height: 0; }
.pane { display: none; min-height: 0; }
.pane.is-active { display: flex; flex-direction: column; }
.pane { padding-bottom: 18px; }

/* viewer */
.viewer { display: flex; flex-direction: column; gap: 10px; }
.viewer-stage {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); overflow: hidden; min-height: 320px;
  display: flex; align-items: center; justify-content: center;
}
.viewer-stage img { max-width: 100%; max-height: 70dvh; display: block; transition: opacity 0.3s ease; }
.viewer-stage img:not([src]) { display: none; } /* no broken-image icon before a page renders */
.page-text {
  margin: 0; width: 100%; max-height: 70dvh; overflow: auto; padding: 18px 20px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px;
  line-height: 1.55; color: var(--ink); white-space: pre-wrap; word-break: break-word; text-align: left;
}
.viewer-stage img.scanning { opacity: 0.5; filter: blur(1px); }
.scan-shimmer { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.scan-shimmer.on {
  opacity: 1;
  background: linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--green) 22%, transparent) 50%, transparent 100%);
  background-size: 100% 40%; background-repeat: no-repeat; animation: scan 1.5s ease-in-out infinite;
}
.viewer-bar { display: flex; align-items: center; justify-content: center; gap: 14px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--r-btn); width: 36px; height: 32px; color: var(--ink-soft); }
.icon-btn:hover { border-color: var(--green); color: var(--green); }
.pager { font-family: var(--font-cond); font-weight: 700; min-width: 64px; text-align: center; }

/* recognized header + stepper */
.recognized { margin-bottom: 4px; }
.stepper { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0 14px; }
.step { font-size: 13px; font-weight: 700; color: var(--ink-faint); padding: 4px 12px; border-radius: var(--r-pill); background: var(--surface); position: relative; }
.step.is-active { color: var(--green-ink); background: var(--green-wash); }
.step.done { color: var(--green); }
.step.done::after { content: '✓'; margin-left: 6px; }
.recognized-head { display: flex; align-items: center; gap: 10px; padding: 4px 0 12px; border-bottom: 1px solid var(--line-soft); }
.recognized-head .rk { color: var(--green); font-size: 22px; }
.recognized-head h2 { font-size: 20px; font-weight: 800; margin: 0; }
.alt-correct { margin-left: auto; font-size: 12px; }
.alt-correct select { font-family: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; color: var(--ink-soft); }

.fields-head { padding: 14px 0 2px; }
.fields-head h2 { font-size: 16px; font-weight: 800; margin: 0; }
.fields { display: flex; flex-direction: column; }
.field-group { padding: 12px 0 4px; }
.field-group-title { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 6px; }
.field-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.field-key { width: 40%; color: var(--ink-soft); font-size: 13px; flex: none; }
.field-val { flex: 1; font-weight: 600; word-break: break-word; }
.field-val.is-num { font-family: var(--font-cond); font-weight: 700; }
.field-val.missing { color: var(--ink-faint); font-weight: 400; font-style: italic; }
.field-cite { font-size: 11px; color: var(--green); font-weight: 700; flex: none; cursor: pointer; opacity: 0.85; }
.field-cite:hover { text-decoration: underline; }
.field-settle { animation: settle 0.45s ease both; }
.field-pulse { animation: pulse 0.5s ease; }
.fields-empty { font-size: 13px; color: var(--ink-faint); padding: 18px 2px; }
.note-pii { font-size: 12px; color: var(--terracotta); background: var(--terracotta-wash); padding: 8px 12px; border-radius: var(--r-btn); margin-top: 12px; }
.note-offtopic { font-size: 12.5px; color: var(--ochre); background: var(--ochre-wash); padding: 8px 12px; border-radius: var(--r-btn); margin: 8px 0 0; }
.note-review { font-size: 12.5px; color: var(--ochre); background: var(--ochre-wash); padding: 8px 12px; border-radius: var(--r-btn); margin-top: 12px; }

/* ---------- loading states (viewer spinner + skeleton fields) ---------- */
.viewer-loading {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; color: var(--ink-faint);
}
.viewer-loading[hidden] { display: none; }
.vl-spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  animation: spin 0.8s linear infinite;
}
.vl-text { font-size: 13px; font-weight: 600; }
.page-text.is-loading { color: var(--ink-faint); font-style: italic; }
.fields-skeleton { display: flex; flex-direction: column; padding-top: 6px; }
.sk-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.sk-bar {
  flex: none; height: 11px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}

/* chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 360px; }
.chat-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 2px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: 14.5px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.assistant { background: var(--surface); color: var(--ink); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.user { background: var(--green); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble.streaming::after { content: '▍'; animation: blink 1s steps(2) infinite; color: var(--green); }
.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 2px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft); padding: 7px 13px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600; }
.chip:hover { border-color: var(--green); color: var(--green); }
.composer { display: flex; gap: 8px; padding: 10px 2px 4px; border-top: 1px solid var(--line-soft); }
.composer input { flex: 1; border: 1px solid var(--line); border-radius: var(--r-pill); padding: 11px 16px; font-size: 15px; background: var(--surface-2); outline: none; }
.composer input:focus { border-color: var(--green); }
.composer-send { flex: none; width: 44px; border: 0; border-radius: 50%; background: var(--green); color: #fff; font-size: 18px; font-weight: 700; }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scan { 0% { background-position: 0 -40%; } 100% { background-position: 0 120%; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes settle { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { background: var(--green-wash); } 100% { background: transparent; } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .scan-shimmer.on { opacity: 0.4; animation: none; }
}

/* ---------- wide screens: three-pane split ---------- */
@media (min-width: 920px) {
  .ws-tabs { display: none; }
  .ws-panes {
    display: grid; grid-template-columns: 1.05fr 1fr 1fr; gap: 18px;
    align-items: start;
  }
  .pane { display: flex !important; flex-direction: column; max-height: calc(100dvh - 120px); }
  .pane-page, .pane-data { overflow-y: auto; }
  .pane-data { border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); padding: 0 18px 18px; }
  .chat { height: calc(100dvh - 130px); }
}
