/* Zorum v1 design system (ZS-DIS-01). Source of truth copied verbatim into web/chat/,
   web/platform/, web/admin/ by tools/build_ui.py -- edit only here.
   Palette/type follow the legacy web/chat.html sample; --muted and --amber are tuned darker than
   the legacy sample so text on --bg/--white/--soft still clears WCAG AA (>=4.5:1), verified by
   tests/test_web_backend.py::TokenContrastTests. --on-accent/--on-danger are the text color for
   filled --green/--danger surfaces (buttons, marks, error toast) -- white in light theme, dark in
   dark theme, because --green/--danger themselves flip from dark-on-light to light-on-dark
   (FIX-r01/R6: white text on dark theme's light --green was 2.22:1). No external fonts/CDN/icons:
   system font stack, inline SVG icons via ZorumUI.icon(). */
:root {
  --bg: #fafbf9;
  --side: #f0f2ef;
  --white: #ffffff;
  --ink: #222d28;
  --muted: #5f6960;
  --line: #e2e7e1;
  --green: #285e48;
  --green-dark: #1a4835;
  --soft: #e7efe8;
  --amber: #8a5c17;
  --amber-dot: #bd9349;
  --amber-soft: #faf4e7;
  --danger: #a45135;
  --danger-soft: #f7e9e4;
  --on-accent: #ffffff;
  --on-danger: #ffffff;
  --radius-lg: 17px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-card: 0 5px 22px rgba(43, 73, 48, 0.04);
  --shadow-pop: 0 14px 55px rgba(41, 59, 44, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151915;
    --side: #1c221d;
    --white: #1f251f;
    --ink: #e7ede8;
    --muted: #9aa79c;
    --line: #2b332c;
    --green: #7fbb9a;
    --green-dark: #6fae8d;
    --soft: #20291f;
    --amber: #e0ab5a;
    --amber-dot: #e0ab5a;
    --amber-soft: #2a2419;
    --danger: #e2896f;
    --danger-soft: #2c1f19;
    --on-accent: #0f1f16;
    --on-danger: #2c1f19;
    --shadow-card: 0 5px 22px rgba(0, 0, 0, 0.28);
    --shadow-pop: 0 14px 55px rgba(0, 0, 0, 0.45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
}
button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible,
a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #85b69b;
  outline-offset: 2px;
}
svg.icon {
  width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-weight: 600; margin: 0 0 12px; letter-spacing: -.3px; }
p { margin: 0 0 10px; }

/* --- layout shells ------------------------------------------------------------------------ */

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--white) 96%, transparent);
  flex-wrap: wrap;
}
.app-header .brand-row { display: flex; align-items: center; gap: 12px; font-weight: 650; font-size: 18px; }
.app-header .brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--green); color: var(--on-accent);
  display: grid; place-items: center; font: 18px/1 Georgia, serif;
}
.app-header .crumb { color: var(--muted); font-weight: 400; font-size: 13px; }
.badge-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.page-main { flex: 1; min-width: 0; padding: 26px 28px 40px; max-width: 1040px; width: 100%; margin: 0 auto; }
.page-main.wide { max-width: 1180px; }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow-card); margin-bottom: 22px;
}
.card > h2 { font-size: 15px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

/* --- sidebar + conversation layout (chat) -------------------------------------------------- */

.app-layout { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  background: var(--side); border-right: 1px solid var(--line); padding: 26px 16px 16px;
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar .brand { display: flex; gap: 10px; align-items: center; padding: 0 10px; font-size: 20px; font-weight: 650; letter-spacing: -.6px; }
.sidebar .brand small { font-size: 9px; letter-spacing: 1px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; margin-left: auto; }
.new-item {
  display: flex; align-items: center; gap: 10px; background: var(--white); border: 1px solid var(--line);
  box-shadow: var(--shadow-card); border-radius: var(--radius-sm); padding: 11px 13px; margin: 24px 0 20px;
  text-align: left; font-weight: 600; width: 100%;
}
.new-item:hover { border-color: #95ad9a; }
.section-label { text-transform: uppercase; letter-spacing: 1.2px; font-size: 10px; font-weight: 650; color: var(--muted); padding: 0 10px; margin-bottom: 8px; }
.nav-list { overflow: auto; flex: 1; }
.nav-item {
  width: 100%; padding: 10px 11px; text-align: left; display: flex; align-items: center; gap: 9px;
  border-radius: 8px; margin-bottom: 3px; color: var(--ink);
}
.nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.nav-item.active { color: var(--green); background: var(--soft); font-weight: 600; }
.nav-empty { font-size: 12px; color: var(--muted); padding: 0 10px; max-width: 190px; }
.sidebar-bottom { border-top: 1px solid var(--line); padding: 14px 8px 0; margin-top: 12px; }
.profile { display: flex; align-items: center; gap: 10px; }
.avatar { height: 30px; width: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); font-size: 11px; font-weight: 600; flex-shrink: 0; }
.profile strong { display: block; font-size: 12px; font-weight: 600; word-break: break-word; }
.profile small { font-size: 11px; color: var(--muted); }
.link-button { font-size: 11px; color: var(--muted); padding: 0; margin-top: 6px; }
.link-button:hover { color: var(--ink); text-decoration: underline; }

.main-column { min-width: 0; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.mobile-menu { display: none; }
.overlay { display: none; }
.overlay.open { display: block; position: fixed; inset: 0; background: rgba(34, 59, 40, .25); z-index: 11; }

/* --- forms / auth card ---------------------------------------------------------------------- */

.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--side); }
.auth-card {
  width: min(400px, 100%); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 34px; box-shadow: var(--shadow-pop);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--green); color: var(--on-accent); display: grid; place-items: center; font: 20px Georgia, serif; }
.auth-card h1 { font-size: 22px; letter-spacing: -.5px; margin-bottom: 8px; }
.auth-card > p { font-size: 13px; color: var(--muted); }
.step-hint { font-size: 12px; color: var(--muted); margin-bottom: 18px; }

.field { display: block; font-size: 12px; font-weight: 600; margin: 16px 0 6px; }
.field:first-of-type { margin-top: 0; }
input, textarea, select {
  width: 100%; border: 1px solid #cdd9cf; border-radius: var(--radius-sm); padding: 10px 12px;
  background: var(--white); color: var(--ink);
}
select { appearance: auto; }
textarea { resize: vertical; }
.form-grid { display: flex; flex-direction: column; gap: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 600; font-size: 13px;
  border: 1px solid transparent; white-space: nowrap;
}
.btn-primary { background: var(--green); color: var(--on-accent); }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: var(--white); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #95ad9a; }
.btn-danger { background: var(--white); border-color: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-pill { border-radius: 999px; padding: 6px 13px; font-size: 12px; border: 1px solid var(--line); background: var(--white); }
.btn-pill:hover { border-color: #95ad9a; }
.btn-block { width: 100%; }

.form-error {
  color: var(--danger); min-height: 18px; font-size: 12px; margin: 12px 0 0;
}
.form-status { color: var(--muted); font-size: 12px; }

pre.recovery-codes {
  background: var(--soft); border-radius: var(--radius-sm); padding: 14px; font-size: 13px;
  line-height: 1.7; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* --- badges / status chips -------------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.badge-neutral { background: var(--side); color: var(--muted); border-color: var(--line); }
.badge.active, .badge.approved, .badge.completed, .badge.done, .badge.succeeded { background: var(--soft); color: var(--green); }
.badge.suspended, .badge.blocked, .badge.failed, .badge.cancelled, .badge.expired { background: var(--danger-soft); color: var(--danger); }
.badge.provisioning, .badge.pending, .badge.draft, .badge.running, .badge.queued { background: var(--amber-soft); color: var(--amber); }
.badge.retired, .badge.synthetic { background: var(--side); color: var(--muted); }
.badge.readonly {
  background: var(--amber-soft); color: var(--amber); border-radius: 7px; font-size: 10px;
  letter-spacing: .3px; text-transform: uppercase; padding: 4px 8px;
}
.badge.readonly::before { display: none; }

/* --- tables -------------------------------------------------------------------------------- */

.table-wrap { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--white); }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; background: var(--side); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--ink) 3%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.state-row { font-size: 11px; color: var(--muted); margin-top: 4px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- lists (invitations/connections/methodologies) ------------------------------------------ */

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px; background: var(--white);
}
.item-row .item-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.item-empty { color: var(--muted); font-size: 12px; }

/* --- run / job status indicator (chat) -------------------------------------------------------- */

.run-state {
  max-width: 760px; margin: 0 auto 10px; display: flex; align-items: center; gap: 9px;
  font-size: 12px; color: var(--muted);
}
.run-state.error { color: var(--danger); }
.run-dot { width: 7px; height: 7px; background: #769e72; border-radius: 50%; animation: zorum-pulse 1.2s infinite; flex-shrink: 0; }
.run-state.error .run-dot { background: var(--danger); animation: none; }
.run-events { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.run-events .run-event-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-run { color: var(--muted); font-size: 11px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; flex-shrink: 0; }
.stop-run:hover { border-color: #95ad9a; color: var(--ink); }
@keyframes zorum-pulse { 50% { opacity: .3; } }

/* --- toasts / dialogs ------------------------------------------------------------------------ */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: var(--radius-sm); padding: 11px 17px;
  font-size: 12px; box-shadow: 0 4px 20px rgba(0, 0, 0, .18); z-index: 40; max-width: 90vw;
}
.toast.toast-error { background: var(--danger); color: var(--on-danger); }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); max-width: 460px; width: calc(100% - 40px);
  padding: 24px; color: var(--ink); background: var(--white); box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: rgba(34, 59, 40, .25); }
dialog h2 { font-size: 18px; margin-bottom: 12px; }
dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12px; margin: 0 0 16px; }
dialog dt { color: var(--muted); }
dialog dd { margin: 0; overflow-wrap: anywhere; }
dialog form { display: flex; flex-direction: column; }
dialog .form-actions { justify-content: flex-end; }
.dialog-actions { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
pre.dialog-output { background: var(--side); border-radius: var(--radius-sm); padding: 12px; font-size: 12px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* --- evidence side panel (chat "Основание") --------------------------------------------------- */

.side-panel {
  width: 300px; flex-shrink: 0; border-left: 1px solid var(--line); padding: 26px 22px;
  background: var(--side); overflow: auto;
}
.side-panel .panel-title { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 650; margin-bottom: 20px; }
.icon-button { padding: 5px; display: grid; place-items: center; border-radius: 6px; }
.icon-button:hover { background: var(--soft); }
.evidence-field { margin-bottom: 14px; }
.evidence-field .label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 3px; }
.evidence-field .value { font-size: 13px; overflow-wrap: anywhere; }
.evidence-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); padding: 12px; margin-bottom: 10px; font-size: 12px; overflow-wrap: anywhere; }
.evidence-empty { color: var(--muted); font-size: 12px; }

/* --- chat conversation ------------------------------------------------------------------------ */

.chat-scroll { flex: 1; overflow-y: auto; padding: 32px 34px 14px; scroll-behavior: smooth; }
.chat-empty { max-width: 640px; margin: clamp(10px, 6vh, 60px) auto 0; }
.chat-empty .eyebrow { display: flex; align-items: center; gap: 8px; color: var(--green); font-size: 11px; font-weight: 650; letter-spacing: 1.3px; text-transform: uppercase; }
.chat-empty h1 { font-size: clamp(24px, 3vw, 34px); line-height: 1.24; letter-spacing: -1px; font-weight: 500; margin: 16px 0 12px; }
.chat-empty .lead { max-width: 460px; color: var(--muted); font-size: 14px; line-height: 1.7; margin-bottom: 24px; }
.example-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.example-prompt {
  padding: 15px 16px; text-align: left; background: var(--white); border: 1px solid var(--line);
  border-radius: 10px; min-height: 78px; font-size: 13px; line-height: 1.5;
}
.example-prompt:hover { border-color: #90ac97; }

.conversation { max-width: 760px; margin: 0 auto; }
.message { margin-bottom: 24px; }
.message.user { display: flex; justify-content: flex-end; }
.message.user .bubble {
  background: var(--soft); border: 1px solid var(--line); border-radius: 15px 15px 3px 15px;
  padding: 12px 16px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px;
}
.message.assistant .assistant-head { display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 650; margin-bottom: 12px; }
.assistant-mark { width: 24px; height: 24px; background: var(--green); color: var(--on-accent); border-radius: 7px; display: grid; place-items: center; font-family: Georgia, serif; flex-shrink: 0; }
.answer-body { padding-left: 33px; line-height: 1.75; font-size: 13.5px; overflow-wrap: anywhere; }
.answer-body p { margin: 0 0 13px; }
.answer-body h3 { font-size: 14px; margin: 16px 0 8px; }
.answer-body ul, .answer-body ol { padding-left: 20px; margin: 0 0 13px; }
.answer-body code { background: var(--side); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.answer-body .table-wrap { margin: 12px 0; }
.evidence-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.citation {
  font-size: 11px; color: var(--green); background: var(--soft); border: 1px solid #dce7d7;
  padding: 5px 9px; border-radius: 6px; display: inline-flex; gap: 6px; align-items: center;
}
.citation:hover { border-color: #809a7e; }
/* SPEC-r01 ZS-MVP-23 point 4 (FIX-r01/F6): Refusal(NO_DOCUMENT|OUT_OF_SCOPE) rendered as an
   honest object, never folded silently into the answer's own prose. */
.refusal-banner {
  margin-top: 10px; font-size: 12.5px; color: #7a5a12; background: #fff6e0; border: 1px solid #f0dca0;
  border-radius: 8px; padding: 8px 11px;
}
.answer-actions { display: flex; gap: 8px; margin-top: 12px; padding-left: 33px; }
.answer-actions .btn-pill { font-size: 10px; color: var(--muted); }

/* SPEC-r01 ZS-MVP-25 point 7/8: assumptions_block (применённое определение/базис/период/версия
   данных/провайдер), alternatives[] (follow-up -- click re-asks without a clarifying round-trip),
   the verification badge ("Рассчитано / Указано в источнике / Вывод" + статус проверки) and
   server-rendered SVG charts (backend/charts/svg.py). */
.verification-badge {
  font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 5px; background: var(--soft); color: var(--green); margin-left: 6px;
}
.verification-badge.draft_method, .verification-badge.preliminary { background: #fff6e0; color: #7a5a12; }
.verification-badge.exploratory { background: #eef1fb; color: #3a4bab; }
.assumptions-block {
  margin-top: 10px; font-size: 12px; color: var(--text); background: var(--soft);
  border: 1px solid #dce7d7; border-radius: 8px; padding: 9px 12px;
}
.assumptions-block dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; margin: 4px 0 0; }
.assumptions-block dt { color: var(--muted); }
.alternatives { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 9px; }
.alt-button {
  font-size: 11.5px; border-radius: 999px; padding: 6px 12px; border: 1px dashed #95ad9a;
  background: var(--white); color: var(--green); cursor: pointer;
}
.alt-button:hover { background: var(--soft); }
.chart-svg { max-width: 100%; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; }
.promote-button { font-size: 10px; }

.composer-wrap { padding: 14px 34px 20px; flex-shrink: 0; }
.composer {
  max-width: 760px; margin: 0 auto; border: 1px solid #cdd9cf; border-radius: 15px; background: var(--white);
  box-shadow: var(--shadow-card); overflow: hidden;
}
.composer:focus-within { border-color: #87a991; }
.composer textarea {
  resize: none; border: 0; background: transparent; display: block; width: 100%;
  min-height: 64px; max-height: 170px; padding: 16px 18px 4px; line-height: 1.6; outline: none;
}
.composer-bottom { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 10px 17px; gap: 10px; }
.model-slot { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.send-button { width: 34px; height: 34px; background: var(--green); color: var(--on-accent); border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.send-button:hover { background: var(--green-dark); }
.composer-note { max-width: 760px; margin: 8px auto 0; display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 10px; }

/* --- documents: attachments, upload progress, viewer (ZS-MVP-21) ----------------------------- */

.pending-attachments { max-width: 760px; margin: 0 auto 8px; display: flex; gap: 7px; flex-wrap: wrap; }
.pending-attachment {
  font-size: 11px; color: var(--ink); background: var(--white); border: 1px solid var(--line);
  padding: 5px 9px; border-radius: 6px; display: inline-flex; gap: 6px; align-items: center;
}
.pending-attachment .remove-attachment { color: var(--muted); }
.pending-attachment .remove-attachment:hover { color: var(--danger); }
.upload-progress { max-width: 760px; margin: 0 auto 8px; font-size: 11px; color: var(--muted); }
.document-card {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink);
  background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  margin-top: 8px;
}
.document-card .document-name { font-weight: 600; overflow-wrap: anywhere; }
.document-card .document-meta { color: var(--muted); font-size: 11px; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.viewer-body { max-height: 60vh; overflow: auto; }
pre.viewer-text { white-space: pre-wrap; word-break: break-word; font-size: 12.5px; line-height: 1.6; margin: 0; }

/* SPEC-r01 ZS-MVP-23 point 5: citation viewer -- anchor precision banner + highlight (web/shared/
   viewer.js, kept byte-identical in web/chat/viewer.js -- tools/build_ui.py does not copy it). */
.viewer-citation { margin-top: 10px; }
.viewer-precision-banner { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.viewer-pdf-page { display: inline-block; }
.viewer-anchor-highlight {
  position: absolute; border: 2px solid #e0a000; background: rgba(224, 160, 0, 0.18); pointer-events: none;
}
.viewer-row-highlight td { background: rgba(224, 160, 0, 0.22); }

/* ZS-UI-001 §2.3: the document viewer takes the whole screen -- a pinned head (name + toolbar) and
   one scrolling body; zoom/rotation come from viewer.js createDocumentView. */
dialog.viewer-dialog {
  width: min(96vw, 1400px); max-width: none; height: 94vh; max-height: none; padding: 0;
  flex-direction: column; overflow: hidden;
}
dialog.viewer-dialog[open] { display: flex; }
.viewer-dialog .viewer-head {
  flex: none; display: flex; align-items: center; gap: 10px; margin: 0; padding: 8px 10px 8px 20px;
  border-bottom: 1px solid var(--line); background: var(--white);
}
.viewer-dialog .viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.viewer-toolbar { flex: none; display: flex; align-items: center; gap: 4px; }
.viewer-tool {
  min-width: 36px; height: 36px; padding: 0 8px; display: grid; place-items: center; border-radius: 8px;
  font-size: 18px; line-height: 1; color: var(--ink);
}
.viewer-tool:hover:not(:disabled) { background: var(--soft); }
.viewer-tool:disabled { opacity: .4; cursor: default; }
.viewer-zoom-level { min-width: 58px; font-size: 12.5px; font-variant-numeric: tabular-nums; border: 1px solid var(--line); }
.viewer-dialog .viewer-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px 16px 24px; }
.viewer-dialog .viewer-body { max-height: none; overflow: visible; }
.viewer-dialog .viewer-citation { margin-top: 0; }
.viewer-pdf-pages, .viewer-rendition-pages { width: max-content; min-width: 100%; }
.viewer-pdf-frame { width: fit-content; margin: 0 auto 16px; }
.viewer-page-label { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.viewer-pdf-frame .viewer-pdf-page { display: block; background: #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .16); }
.viewer-pdf-frame canvas { display: block; }
.rendition-gallery.viewer-rendition-pages { display: block; }
.viewer-rendition-pages .rendition-page { width: fit-content; margin: 0 auto 16px; }
.viewer-image-box { position: relative; margin: 0 auto; }
.viewer-image-box img { position: absolute; left: 50%; top: 50%; max-width: none; transform-origin: center; }
.viewer-zoom-text { font-size: calc(13px * var(--viewer-font-scale, 1)); }
.viewer-zoom-text .content-table, .viewer-zoom-text pre.viewer-text { font-size: inherit; }
.extraction-details > summary { cursor: pointer; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --- responsive ------------------------------------------------------------------------------ */

@media (max-width: 1120px) {
  .side-panel { width: 250px; padding: 22px 16px; }
  .app-layout { grid-template-columns: 216px minmax(0, 1fr); }
  .app-header, .page-main { padding-left: 22px; padding-right: 22px; }
  .chat-scroll, .composer-wrap { padding-left: 22px; padding-right: 22px; }
}

@media (max-width: 900px) {
  .side-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 6; width: 270px; box-shadow: -12px 0 35px rgba(40, 59, 37, .1); }
}

@media (max-width: 640px) {
  .app-layout { display: block; min-height: 0; }
  .main-column { height: 100dvh; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(84vw, 300px); z-index: 12;
    transform: translateX(-100%); transition: transform .2s; box-shadow: 18px 0 45px rgba(24, 42, 31, .14);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; min-width: 40px; min-height: 40px; }
  .app-header {
    /* FIX-r01/R2: a fixed height + overflow:hidden clipped the "1С" badge whenever the
       row wrapped (e.g. readonly badge + visible "Основание" toggle together) -- min-height
       lets the header grow by one row instead of cutting content. */
    padding: 8px 12px; min-height: 56px; flex-wrap: wrap; row-gap: 6px; overflow: visible;
  }
  .app-header .brand-row { min-width: 0; overflow: hidden; }
  .app-header .brand-row span:not(.mobile-menu) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-header .crumb { display: none; }
  /* FIX-r01/F2: tenant/role identify the user in the sidebar profile block already; hiding
     these two badges keeps the mobile header to a single compact row. */
  .badge-row #tenantBadge, .badge-row #roleBadge { display: none; }
  .badge-row .badge.readonly { padding: 4px 6px; font-size: 0; }
  .badge-row .badge.readonly::after { content: '1С'; font-size: 10px; }
  .page-main { padding: 18px 16px 30px; }
  .chat-scroll { padding: 22px 16px 10px; }
  .composer-wrap { padding: 10px 12px 14px; }
  .example-grid { grid-template-columns: 1fr; }
  .message.user .bubble { max-width: 94%; }
  .answer-body, .answer-actions { padding-left: 0; }
  .side-panel { top: 0; width: 100%; max-width: none; }
  .card { padding: 16px; }
  /* ZS-UI-001 §2.3.1-2: on a phone the viewer is the whole screen with 40 px buttons. */
  dialog.viewer-dialog { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .viewer-dialog .viewer-head { gap: 4px; padding: 6px 6px 6px 12px; }
  .viewer-tool { min-width: 40px; height: 40px; }
  .viewer-zoom-level { min-width: 52px; padding: 0 4px; }
  .viewer-dialog .viewer-scroll { padding: 10px 8px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
