/* profAuto — «электронный гроссбух».
   Палитра и типографика: бумага с зелёным смещением, чернила,
   обложка-сукно (сайдбар), PT Serif + Golos Text + PT Mono. */

:root {
  --paper: #f4f6f1;
  --sheet: #ffffff;
  --ink: #1c231e;
  --muted: #5f6b62;
  --line: #d9e0d7;
  --ruling: rgba(28, 35, 30, 0.05);
  --accent: #256d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e6efe8;
  --cover: #13291f;
  --cover-text: #b9c9bd;
  --cover-line: rgba(185, 201, 189, 0.18);
  --cover-field: rgba(0, 0, 0, 0.28);
  --stamp: #8fbf9f;
  --ok-bg: #e3efe6;
  --ok-fg: #1e5c40;
  --busy-bg: #f4ecd7;
  --busy-fg: #8a6a1f;
  --err-bg: #f6e3e0;
  --err-fg: #a83226;
  --shadow: 0 1px 2px rgba(19, 41, 31, 0.06), 0 8px 24px rgba(19, 41, 31, 0.05);
  --font-ui: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --font-display: "PT Serif", Georgia, serif;
  --font-mono: "PT Mono", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1512;
    --sheet: #151c17;
    --ink: #e4eae3;
    --muted: #93a096;
    --line: #263029;
    --ruling: rgba(228, 234, 227, 0.045);
    --accent: #4cb98a;
    --accent-ink: #0d1410;
    --accent-soft: #1c2b22;
    --cover: #0c120e;
    --cover-text: #a7b6aa;
    --cover-line: rgba(167, 182, 170, 0.16);
    --cover-field: rgba(0, 0, 0, 0.35);
    --stamp: #6ea981;
    --ok-bg: #16281e;
    --ok-fg: #7fd0a8;
    --busy-bg: #2b2416;
    --busy-fg: #d9b45e;
    --err-bg: #2e1a17;
    --err-fg: #e07a6d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="light"] {
  --paper: #f4f6f1;
  --sheet: #ffffff;
  --ink: #1c231e;
  --muted: #5f6b62;
  --line: #d9e0d7;
  --ruling: rgba(28, 35, 30, 0.05);
  --accent: #256d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e6efe8;
  --cover: #13291f;
  --cover-text: #b9c9bd;
  --cover-line: rgba(185, 201, 189, 0.18);
  --cover-field: rgba(0, 0, 0, 0.28);
  --stamp: #8fbf9f;
  --ok-bg: #e3efe6;
  --ok-fg: #1e5c40;
  --busy-bg: #f4ecd7;
  --busy-fg: #8a6a1f;
  --err-bg: #f6e3e0;
  --err-fg: #a83226;
  --shadow: 0 1px 2px rgba(19, 41, 31, 0.06), 0 8px 24px rgba(19, 41, 31, 0.05);
}

:root[data-theme="dark"] {
  --paper: #0f1512;
  --sheet: #151c17;
  --ink: #e4eae3;
  --muted: #93a096;
  --line: #263029;
  --ruling: rgba(228, 234, 227, 0.045);
  --accent: #4cb98a;
  --accent-ink: #0d1410;
  --accent-soft: #1c2b22;
  --cover: #0c120e;
  --cover-text: #a7b6aa;
  --cover-line: rgba(167, 182, 170, 0.16);
  --cover-field: rgba(0, 0, 0, 0.35);
  --stamp: #6ea981;
  --ok-bg: #16281e;
  --ok-fg: #7fd0a8;
  --busy-bg: #2b2416;
  --busy-fg: #d9b45e;
  --err-bg: #2e1a17;
  --err-fg: #e07a6d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  background: var(--paper);
  color: var(--ink);
}

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.app {
  display: grid;
  grid-template-columns: 304px 1fr;
  height: 100vh;
}

/* ── Сайдбар: обложка гроссбуха ─────────────────────────── */

.sidebar {
  background: var(--cover);
  color: var(--cover-text);
  padding: 1.5rem 1.35rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  padding-bottom: 1.35rem;
  border-bottom: 1px solid var(--cover-line);
}

/* круглая печать организации */
.brand-mark {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1.5px solid var(--stamp);
  display: grid;
  place-items: center;
  color: var(--stamp);
  transform: rotate(-8deg);
  position: relative;
}

.brand-mark::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 1px solid var(--stamp);
  opacity: 0.7;
}

.brand-mark span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
}

.brand-text p {
  font-size: 0.72rem;
  opacity: 0.75;
  margin-top: 0.15rem;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  opacity: 0.6;
  margin-bottom: 0.7rem;
}

.panel label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.65rem;
}

.panel select,
.report-question-label input {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  border: 1px solid var(--cover-line);
  background: var(--cover-field);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
}

.panel select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23b9c9bd' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 1.8rem;
}

.role-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--cover-line);
  border-radius: 8px;
  overflow: hidden;
}

.role-switch button {
  padding: 0.55rem;
  border: none;
  background: transparent;
  color: var(--cover-text);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  transition: background 0.15s, color 0.15s;
}

.role-switch button + button { border-left: 1px solid var(--cover-line); }

.role-switch button.active {
  background: var(--stamp);
  color: var(--cover);
  font-weight: 600;
}

.report-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.report-btns button {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--cover-line);
  background: transparent;
  color: var(--cover-text);
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.report-btns button:hover {
  border-color: var(--stamp);
  color: #fff;
  background: rgba(143, 191, 159, 0.08);
}

.report-btns button:disabled { opacity: 0.4; cursor: wait; }

.report-question-label {
  display: block;
  margin-top: 0.7rem;
  font-size: 0.74rem;
  opacity: 0.85;
}

.stats { margin-top: auto; }

.stats #statsContent {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.9;
  font-variant-numeric: tabular-nums;
}

.stats #statsContent b { color: #fff; font-weight: 400; }

/* ── Основная колонка ───────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--paper);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.75rem;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
}

.topbar-title h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  text-wrap: balance;
}

.topbar-title p {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.1rem;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: none;
}

/* статус-штамп */
.status {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok-fg);
  border: 1px solid currentColor;
  white-space: nowrap;
}

.status.busy { background: var(--busy-bg); color: var(--busy-fg); }
.status.error { background: var(--err-bg); color: var(--err-fg); }

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

.tabs {
  display: flex;
  gap: 1.4rem;
  padding: 0 1.75rem;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
}

.tab {
  padding: 0.7rem 0.15rem;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.tab:hover { color: var(--ink); }

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.tab-panel.active { display: flex; }

/* ── Диалог: лента на линованной бумаге ─────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.75rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  background: repeating-linear-gradient(
    var(--paper) 0,
    var(--paper) 27px,
    var(--ruling) 27px,
    var(--ruling) 28px
  );
}

.msg {
  max-width: 760px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1.15rem 1rem;
  box-shadow: var(--shadow);
}

.msg.assistant { border-left: 3px solid var(--accent); }

.msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: transparent;
}

.msg-role {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.msg-body {
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 65ch;
}

.msg.user .msg-body { white-space: pre-wrap; }

.msg-body p { margin: 0.35rem 0; }

.msg-body h3, .msg-body h4, .msg-body h5,
.report-view h3, .report-view h4, .report-view h5 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 1rem 0 0.35rem;
  text-wrap: balance;
}

.msg-body h3, .report-view h3 { font-size: 1.1rem; }
.msg-body h4, .report-view h4 { font-size: 1rem; }
.msg-body h5, .report-view h5 { font-size: 0.92rem; }

.msg-body ul, .report-view ul { margin: 0.4rem 0 0.4rem 1.3rem; }
.msg-body li, .report-view li { margin: 0.22rem 0; }

.msg-body b, .report-view b { font-weight: 600; }

.msg-body code, .report-view code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--accent-soft);
  padding: 0.08rem 0.35rem;
  border-radius: 4px;
}

.msg-body hr, .report-view hr {
  border: none;
  border-top: 1px dashed var(--line);
  margin: 0.85rem 0;
}

.msg-processing {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.msg-processing b { color: var(--accent); font-weight: 400; }

/* ход рассуждений — сворачиваемая «служебная записка» */
.msg-reasoning {
  margin-top: 0.7rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.msg-reasoning summary {
  cursor: pointer;
  padding: 0.45rem 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.64rem;
  user-select: none;
  list-style-position: inside;
}

.msg-reasoning summary:hover { color: var(--accent); }

.msg-reasoning[open] summary { border-bottom: 1px dashed var(--line); }

.msg-reasoning ol {
  margin: 0.5rem 0.75rem 0.65rem 2rem;
  line-height: 1.7;
}

.msg-reasoning li::marker { color: var(--accent); }

.msg-sources {
  margin-top: 0.8rem;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--line);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.9;
  color: var(--muted);
}

/* выгрузка в PDF/DOC */
.msg-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.export-btn {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  transition: color 0.15s, border-color 0.15s;
}

.export-btn:hover { color: var(--accent); border-color: var(--accent); }
.export-btn:disabled { opacity: 0.5; cursor: wait; }

.msg-sources a,
.doc-item .path a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}

.msg-sources a:hover,
.doc-item .path a:hover { border-bottom-color: var(--accent); }

/* ── Композер ───────────────────────────────────────────── */

.composer {
  display: flex;
  gap: 0.7rem;
  padding: 1rem 1.75rem 1.25rem;
  background: var(--sheet);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  resize: vertical;
  min-height: 56px;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: 0.92rem;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s;
}

.composer textarea:focus { border-color: var(--accent); outline: none; }

.composer-btns {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: none;
}

button.primary {
  padding: 0.6rem 1.35rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  transition: filter 0.15s;
}

button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.5; cursor: wait; }

button.secondary {
  padding: 0.45rem 1rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  transition: color 0.15s, border-color 0.15s;
}

button.secondary:hover { color: var(--err-fg); border-color: var(--err-fg); }
button.secondary:disabled { opacity: 0.5; cursor: wait; }

/* ── Документы: строки реестра ──────────────────────────── */

.search-row {
  display: flex;
  gap: 0.6rem;
  padding: 1.1rem 1.75rem;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
}

.search-row input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s;
}

.search-row input:focus { border-color: var(--accent); outline: none; }

.doc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.75rem 1.5rem;
}

.doc-item {
  padding: 0.7rem 0.25rem;
  border-bottom: 1px solid var(--line);
  transition: background 0.12s;
}

.doc-item:hover { background: var(--accent-soft); }

.doc-item .path {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  word-break: break-all;
  line-height: 1.5;
}

.doc-item .meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

/* ── Отчёт: лист ────────────────────────────────────────── */

.report-view {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  background: var(--sheet);
  margin: 1.25rem 1.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  line-height: 1.65;
  font-size: 0.93rem;
}

.report-view p { margin: 0.4rem 0; max-width: 70ch; }

.muted { color: var(--muted); }

/* ── Скроллбары ─────────────────────────────────────────── */

.messages::-webkit-scrollbar,
.doc-list::-webkit-scrollbar,
.report-view::-webkit-scrollbar,
.sidebar::-webkit-scrollbar { width: 8px; }

.messages::-webkit-scrollbar-thumb,
.doc-list::-webkit-scrollbar-thumb,
.report-view::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.sidebar::-webkit-scrollbar-thumb { background: var(--cover-line); border-radius: 4px; }

/* ── Мобильная раскладка ────────────────────────────────── */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .stats { margin-top: 0; }
  .main { min-height: 70vh; }
  .msg { max-width: 100%; }
  .topbar { flex-wrap: wrap; }
}
