/* Реестр дел BATYS — мобильный интерфейс. Фирменные цвета: тёмно-синий + золото. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #e9eef2;
  --fg: #16232d;
  --muted: #5d6c78;
  --line: #d6dee5;
  --ink: #101722;          /* фирменный тёмно-синий */
  --ink-fg: #ffffff;
  --brass: #a8783f;        /* фирменное золото: сроки и заседания */
  --ok: #2f7a4f;
  --warn: #b26a00;
  --danger: #b3261e;
  --ok-bg: #e3f1e8;
  --warn-bg: #fbeed6;
  --danger-bg: #f9e1df;
  --muted-bg: #e6eaee;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171d;
    --surface: #16212a;
    --surface-2: #1d2b36;
    --fg: #e6edf2;
    --muted: #93a3b0;
    --line: #2a3a46;
    --ink: #d9b07a;
    --ink-fg: #101722;
    --brass: #e0b97f;
    --ok: #6cc28f;
    --warn: #e8a64a;
    --danger: #f08a82;
    --ok-bg: #18332a;
    --warn-bg: #3a2c14;
    --danger-bg: #3b1d1b;
    --muted-bg: #22313c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ink); }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }

/* ---------- Верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
  background: var(--ink); color: var(--ink-fg);
}
@media (prefers-color-scheme: dark) { .topbar { background: var(--surface); color: var(--fg); } }
.topbar h1 { flex: 1; min-width: 0; margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: block; font-size: 12px; font-weight: 400; opacity: .75; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(127,127,127,.18); }
.icon-btn svg { width: 22px; height: 22px; }

.demo-banner {
  padding: 8px max(16px, env(safe-area-inset-left, 0px));
  background: var(--warn-bg); color: var(--warn); font-size: 13px; text-align: center;
}

/* ---------- Раскладка ---------- */
main {
  max-width: 760px; margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(96px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: grid; gap: 14px;
}
.section-title {
  margin: 8px 0 0; font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Поиск и фильтры ---------- */
.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 46px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--ink-fg); }

/* ---------- Список дел ---------- */
.case-list { display: grid; gap: 10px; }
.case-item {
  display: grid; gap: 6px; padding: 14px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.case-item:active { background: var(--surface-2); }
.case-item .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; min-width: 0; }
.case-item .title { font-weight: 620; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.case-no { font-family: var(--mono); font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--muted); }

.pill { flex: none; display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.active { background: var(--ok-bg); color: var(--ok); }
.pill.paused { background: var(--warn-bg); color: var(--warn); }
.pill.closed { background: var(--muted-bg); color: var(--muted); }

.hearing { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: var(--brass); }
.hearing.soon { color: var(--warn); }
.hearing.past { color: var(--danger); }
.hearing svg { width: 15px; height: 15px; }

/* ---------- Карточка дела ---------- */
.case-title { margin: 2px 0 0; font-size: 21px; line-height: 1.25; text-wrap: balance; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0; padding: 4px 0; }
.fact { padding: 10px 14px; min-width: 0; }
.fact dt { font-size: 12px; color: var(--muted); }
.fact dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.notes { padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px solid var(--line); }
.hearing-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.hearing-icon { display: grid; place-items: center; color: var(--brass); flex: none; }
.hearing-icon.past { color: var(--danger); }
.hearing-icon svg { width: 30px; height: 30px; }
.hearing-card .date { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- Документы ---------- */
.folder { overflow: hidden; }
.folder-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 14px;
  background: transparent; border: 0; cursor: pointer; text-align: left; font-weight: 600;
}
.folder-head .count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 14px; }
.folder-head svg { width: 18px; height: 18px; color: var(--muted); transition: transform .15s; flex: none; }
.folder[data-open="false"] .folder-head svg.chev { transform: rotate(-90deg); }
.folder[data-open="false"] .doc-list { display: none; }
.doc-list { border-top: 1px solid var(--line); }
.doc {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px;
  background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer;
}
.doc:last-child { border-bottom: 0; }
.doc:active { background: var(--surface-2); }
.ext {
  flex: none; display: grid; place-items: center; width: 40px; height: 46px; border-radius: 6px;
  font: 700 10px/1 var(--mono); letter-spacing: .02em; text-transform: uppercase;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
}
.ext.pdf { color: #c0392b; } .ext.doc, .ext.docx { color: #2b5797; } .ext.xls, .ext.xlsx { color: #217346; }
.ext.jpg, .ext.jpeg, .ext.png, .ext.heic { color: var(--brass); }
.doc .info { min-width: 0; flex: 1; }
.doc .name { overflow-wrap: anywhere; }
.doc .sub { font-size: 13px; color: var(--muted); }

.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Журнал ---------- */
.log { list-style: none; margin: 0; padding: 4px 0; }
.log li { padding: 8px 14px; font-size: 14px; display: grid; gap: 1px; }
.log time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--fg);
}
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--ink-fg); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink); cursor: pointer; font-weight: 600; font-size: 14px; }

.fab {
  position: fixed; z-index: 15;
  right: max(18px, calc(env(safe-area-inset-right, 0px) + 18px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: inline-flex; align-items: center; gap: 8px; height: 54px; padding: 0 20px;
  border: 0; border-radius: 16px; background: var(--ink); color: var(--ink-fg);
  font-weight: 650; box-shadow: 0 6px 18px rgba(10,25,35,.28); cursor: pointer; text-decoration: none;
}
.fab svg { width: 22px; height: 22px; }

form.stack, .stack { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { border-color: var(--ink); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }
.error { color: var(--danger); font-size: 14px; }

/* ---------- Вход ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth { width: 100%; max-width: 380px; display: grid; gap: 18px; }
.brand { display: grid; gap: 14px; justify-items: start; }
.brand picture, .brand img { display: block; width: 100%; max-width: 340px; height: auto; }
.brand p { margin: 0; color: var(--muted); font-size: 15px; letter-spacing: .02em; }
.topbar .mark { width: 30px; height: 30px; flex: none; }
.topbar .mark + h1 { margin-left: 2px; }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: linear-gradient(90deg, #e8c28a, #9a6a3a); opacity: .9; }

/* ---------- Нижний лист (меню действий) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(5,12,18,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: grid; gap: 10px;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 4px; }
.sheet h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }

#toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px;
  background: var(--fg); color: var(--bg); font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

.staff-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.staff-row:last-child { border-bottom: 0; }
.staff-row .who { flex: 1; min-width: 160px; }
.staff-row select { width: auto; min-width: 150px; }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------- ИИ-помощник ---------- */
.ai-btn { justify-content: flex-start; color: var(--fg); }
.ai-btn svg { color: var(--brass); }
.chat-row { display: grid; gap: 2px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.chat-row:first-child { border-top: 0; }
.chat-row .t { font-weight: 600; overflow-wrap: anywhere; }
.card .small.muted + .chat-row { border-top: 0; }

.chat-main { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
.thread { display: grid; gap: 14px; }
.msg-user {
  justify-self: end; max-width: 88%; padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  background: var(--ink); color: var(--ink-fg); overflow-wrap: anywhere;
}
.msg-ai { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.status-line { display: flex; align-items: center; gap: 10px; color: var(--brass); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.status-line .spinner { flex: none; }
.md { line-height: 1.55; overflow-wrap: anywhere; min-width: 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md li + li { margin-top: 4px; }
.md h3, .md h4, .md h5 { margin: 16px 0 6px; font-size: 16px; line-height: 1.3; }
.md h3 { font-size: 17px; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md blockquote { border-left: 3px solid var(--brass); padding-left: 10px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md a { color: var(--brass); }
.sources { display: grid; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; }
.sources a { color: var(--brass); overflow-wrap: anywhere; }
.msg-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.msg-foot .copy { display: inline-flex; align-items: center; gap: 6px; }
.msg-foot .copy svg { width: 16px; height: 16px; }

.ai-intro { display: grid; gap: 14px; justify-items: start; padding: 8px 0; }
.ai-intro p { margin: 0; color: var(--muted); max-width: 60ch; }
.ai-badge { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--ink); color: #e0b97f; }
.ai-badge svg { width: 26px; height: 26px; }
.examples { display: grid; gap: 8px; width: 100%; }
.examples .chip { text-align: left; white-space: normal; border-radius: 12px; padding: 10px 13px; line-height: 1.35; }

.composer {
  position: fixed; z-index: 15; left: 0; right: 0; bottom: 0;
  padding: 10px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: var(--bg); border-top: 1px solid var(--line);
}
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; min-width: 0; min-height: 46px; max-height: 180px; resize: none; padding: 11px 13px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--ink); }
.composer .send { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border: 0; border-radius: 12px; background: var(--ink); color: var(--ink-fg); cursor: pointer; }
.composer .send svg { width: 22px; height: 22px; }
.composer .send:disabled { opacity: .5; }
.disclaimer { max-width: 760px; margin: 6px auto 0; font-size: 11.5px; color: var(--muted); text-align: center; }
body:has(.composer) #toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 140px); }

/* ---------- База законов ---------- */
mark { background: color-mix(in srgb, var(--brass) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.snippet { color: var(--muted); overflow-wrap: anywhere; }
.toc { overflow: hidden; }
.toc-path { padding: 12px 14px 6px; font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border-top: 1px solid var(--line); }
.toc-path:first-child { border-top: 0; }
.toc-row { display: grid; grid-template-columns: 52px 1fr; gap: 8px; padding: 9px 14px; text-decoration: none; color: inherit; border-top: 1px solid var(--line); line-height: 1.35; }
.toc-row:active { background: var(--surface-2); }
.toc-row .num { font-family: var(--mono); font-size: 13px; color: var(--brass); padding-top: 2px; font-variant-numeric: tabular-nums; }
.toc-row span:last-child { min-width: 0; overflow-wrap: anywhere; }
.law-text { padding: 6px 16px; line-height: 1.6; }
.law-text p { margin: 10px 0; overflow-wrap: anywhere; }
.law-text p.note { font-size: 13px; color: var(--muted); font-style: italic; }
.hearing-icon.ok { color: var(--ok); font-size: 22px; font-weight: 700; width: 30px; }
.hearing-icon.past { font-size: 22px; font-weight: 700; width: 30px; }
.hearing-card .t { font-weight: 600; overflow-wrap: anywhere; }
.art-nav .btn { min-width: 0; }
label.fab { cursor: pointer; }
