:root {
  --bg: #f4f7f5;
  --panel: #ffffff;
  --text: #18231c;
  --muted: #68766e;
  --line: #dce5df;
  --line-strong: #c7d4cd;
  --accent: #137348;
  --accent-dark: #0d5938;
  --accent-soft: #e8f4ee;
  --danger: #a52820;
  --danger-soft: #fee5e2;
  --warn: #966300;
  --warn-soft: #fff3d8;
  --ok: #087443;
  --ok-soft: #ddf3e8;
  --shadow: 0 8px 24px rgba(20, 43, 31, .06);
  --radius: 12px;
  --sidebar: 220px;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
}
.hidden { display: none !important; }
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  padding: 14px 12px;
  background: rgba(255,255,255,.95);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 8px; border-bottom: 1px solid var(--line); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 17px; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }
.nav-list { display: grid; gap: 5px; }
.nav-btn { border: 1px solid transparent; border-radius: 9px; padding: 8px 10px; background: transparent; color: #253a30; font-weight: 700; text-align: left; cursor: pointer; }
.nav-btn:hover { background: #f8faf9; border-color: var(--line); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent-dark); border-color: #c7ead7; }
.app { min-width: 0; padding: 14px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.15; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.top-actions, .section-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.grow-actions { flex: 1 1 auto; }
.series-picker { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
button, input, select, textarea { font: inherit; }
input, select, textarea { border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 9px; background: #fbfdfc; color: var(--text); outline: none; min-height: 32px; }
textarea { line-height: 1.35; }
input:focus, select:focus, textarea:focus { border-color: #86caa5; box-shadow: 0 0 0 3px rgba(17,114,70,.08); }
.btn { border: 0; border-radius: 8px; padding: 7px 10px; cursor: pointer; text-decoration: none; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 5px; line-height: 1.15; min-height: 32px; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { color: white; background: var(--accent); }
.btn.secondary { color: var(--accent-dark); background: var(--accent-soft); border: 1px solid #cae8d7; }
.btn.danger { color: white; background: var(--danger); }
.btn.ghost { color: var(--muted); background: #f5f8f6; border: 1px solid var(--line); padding: 5px 8px; min-height: 26px; font-size: 11px; }
.button-row { display: flex; gap: 7px; flex-wrap: wrap; }
.button-row.vertical { flex-direction: column; align-items: stretch; }
.kpi-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.kpi, .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi { padding: 9px 11px; }
.kpi span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.kpi strong { display: block; margin-top: 3px; color: var(--accent-dark); font-size: 20px; }
.page { display: none; }
.page.active { display: block; }
.card { padding: 12px; margin-bottom: 10px; min-width: 0; }
.inner-card { box-shadow: none; margin-bottom: 10px; }
.section-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 9px; }
.section-title.compact { align-items: center; }
.section-title h2 { margin: 0; font-size: 15px; }
.section-title p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.status-badge { border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-badge.ok { color: var(--ok); background: var(--ok-soft); }
.status-badge.warning { color: var(--warn); background: var(--warn-soft); }
.status-badge.error { color: var(--danger); background: var(--danger-soft); }
.status-badge.neutral { color: #475569; background: #edf2f7; }
.status-line { color: var(--muted); font-size: 11px; line-height: 1.4; margin-top: 7px; }
.collapsible.collapsed .collapsible-body { display: none !important; }
.collapsible.collapsed { padding-bottom: 8px; }
.collapsible.collapsed .section-title { margin-bottom: 0; }
.upload-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) 250px; gap: 10px; align-items: stretch; }
.drop-zone { height: 128px; border: 2px dashed #9dccae; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 5px; text-align: center; color: var(--accent-dark); background: #fbfffd; cursor: pointer; }
.drop-zone strong { font-size: 14px; }
.drop-zone span { font-size: 11px; color: var(--muted); }
.drop-zone input { display: none; }
.drop-zone.disabled { opacity: .55; cursor: not-allowed; background: #f6f8f7; border-color: var(--line-strong); color: var(--muted); }
.drop-zone.drag { background: #eaf8f0; border-color: var(--accent); }
.progress { height: 7px; border-radius: 999px; overflow: hidden; background: #e8efeb; margin-top: 9px; }
.progress span { display: block; width: 0%; height: 100%; background: var(--accent); transition: width .15s ease; }
.search { min-width: 280px; flex: 1 1 280px; }
.list-head { align-items: center; }
.document-table, .result-table, .data-list { display: grid; gap: 6px; }
.table-header, .doc-row, .result-row, .data-row { display: grid; align-items: center; gap: 8px; min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: #fbfdfc; }
.table-header { padding: 7px 9px; background: #f4f8f6; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.doc-row { grid-template-columns: 28px 54px minmax(190px, 1.15fr) 110px 104px minmax(160px, 1fr) 70px 76px; padding: 8px 9px; }
.table-header.docs { grid-template-columns: 28px 54px minmax(190px, 1.15fr) 110px 104px minmax(160px, 1fr) 70px 76px; }
.result-row { grid-template-columns: 62px 96px 128px 150px minmax(170px, .9fr) minmax(220px, 1.2fr) minmax(190px, 1fr); padding: 8px 9px; align-items: start; }
.table-header.results { grid-template-columns: 62px 96px 128px 150px minmax(170px, .9fr) minmax(220px, 1.2fr) minmax(190px, 1fr); }
.data-row { grid-template-columns: 54px minmax(170px, 1fr) minmax(160px, 1fr) minmax(90px, .55fr) auto; padding: 8px 9px; }
.file-name { font-weight: 750; overflow-wrap: anywhere; }
.cell-muted { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.cell-cut { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.checkbox { width: 16px; height: 16px; }
.doc-row button { padding: 5px 8px; min-height: 27px; font-size: 11px; }
.annotation-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 10px; align-items: start; }
.doc-list-panel { position: sticky; top: 14px; max-height: calc(100vh - 28px); overflow: auto; }
.doc-list { display: grid; gap: 6px; }
.doc-mini { border: 1px solid var(--line); border-radius: 10px; background: #fbfdfc; padding: 8px; cursor: pointer; }
.doc-mini:hover { border-color: #a8d5ba; }
.doc-mini.active { border-color: #73bf91; background: #f2fbf6; box-shadow: 0 0 0 2px rgba(17,114,70,.07); }
.doc-mini strong { display: block; font-size: 11px; overflow-wrap: anywhere; }
.doc-mini span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.annotation-workspace { min-height: 620px; }
.workspace-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 9px; }
.workspace-head h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.workspace-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.empty-panel { min-height: 240px; display: grid; place-items: center; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); background: #fbfdfc; }
.field-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 0; }
.field-grid.slim { grid-template-columns: 1fr; }
.field { border: 1px solid var(--line); border-radius: 9px; padding: 7px; background: #fbfdfc; }
.field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; }
.field input, .field textarea { width: 100%; }
.field textarea { min-height: 56px; resize: vertical; }
.field.wide { grid-column: span 3; }
.field.full { grid-column: 1 / -1; }
.field .bind { margin-top: 5px; width: auto; padding: 4px 8px; min-height: 24px; font-size: 11px; }
.review-grid.simplified { display: grid; grid-template-columns: minmax(420px, 1fr) 330px; gap: 10px; align-items: start; }
.ocr-panel, .annotations-panel { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 38px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f6faf8; }
.panel-head span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
#ocrText { margin: 0; height: 560px; overflow: auto; padding: 12px; background: #fff; color: var(--text); white-space: pre-wrap; font: 12px/1.5 "Consolas", "Menlo", monospace; user-select: text; }
#ocrText::selection { background: #bfe7cf; color: #0f2418; }
.annotations { display: grid; gap: 6px; padding: 8px; max-height: 560px; overflow: auto; }
.annotation-item { border: 1px solid var(--line); border-radius: 9px; background: white; padding: 8px; }
.annotation-item strong { display: block; color: var(--accent-dark); font-size: 11px; }
.annotation-item p { margin: 4px 0 0; color: var(--text); font-size: 11px; line-height: 1.35; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .5fr); gap: 10px; align-items: start; }
.pareto-chart { display: grid; gap: 7px; }
.pareto-row { display: grid; grid-template-columns: minmax(180px, 330px) minmax(160px, 1fr) 52px; gap: 8px; align-items: center; }
.pareto-name { font-weight: 700; overflow-wrap: anywhere; }
.pareto-bar { height: 18px; background: #e8efeb; border-radius: 999px; overflow: hidden; }
.pareto-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 2px; }
.pareto-count { text-align: right; color: var(--muted); font-weight: 800; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 100; max-width: 460px; padding: 10px 12px; border-radius: 10px; background: #13251a; color: white; box-shadow: 0 16px 38px rgba(0,0,0,.18); font-weight: 800; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--accent-dark); }
@media (max-width: 1500px) { .field-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } .field.wide { grid-column: span 2; } .review-grid.simplified { grid-template-columns: 1fr; } #ocrText { height: 460px; } .annotations { max-height: 280px; } }
@media (max-width: 1180px) { .shell { grid-template-columns: 1fr; } .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; overflow: auto; } .nav-list { display: flex; flex-wrap: wrap; } .nav-btn { white-space: nowrap; } .upload-layout, .annotation-layout, .two-col { grid-template-columns: 1fr; } .doc-list-panel { position: relative; max-height: none; } .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 780px) { .app { padding: 10px; } .topbar, .workspace-head, .section-title { flex-direction: column; align-items: stretch; } .top-actions, .section-actions { justify-content: flex-start; } .kpi-row { grid-template-columns: repeat(2, 1fr); } .field-grid { grid-template-columns: 1fr; } .field.wide, .field.full { grid-column: auto; } .doc-row, .table-header.docs, .result-row, .table-header.results, .data-row, .pareto-row { grid-template-columns: 1fr; } .search { min-width: 0; width: 100%; } }

/* v6.3 compact UI refinements */
.sidebar-toggle {
  border: 1px solid var(--line);
  background: #f6faf8;
  color: var(--accent-dark);
  border-radius: 8px;
  padding: 5px 7px;
  min-height: 26px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
body.sidebar-collapsed .shell { grid-template-columns: 54px minmax(0, 1fr); }
body.sidebar-collapsed .sidebar { padding: 10px 7px; align-items: center; }
body.sidebar-collapsed .brand { border-bottom: 0; padding: 0; flex-direction: column; gap: 6px; }
body.sidebar-collapsed .brand-mark,
body.sidebar-collapsed .brand > div:not(.brand-mark) { display: none; }
body.sidebar-collapsed .nav-list { width: 100%; gap: 4px; }
body.sidebar-collapsed .nav-btn { font-size: 0; padding: 7px 0; text-align: center; min-height: 30px; }
body.sidebar-collapsed .nav-btn::first-letter { font-size: 13px; }
body.sidebar-collapsed .nav-btn::after { content: attr(data-page); font-size: 0; }

.btn { min-height: 28px; padding: 5px 8px; font-size: 12px; }
.btn.ghost { min-height: 24px; padding: 4px 7px; font-size: 10px; }
.field .bind { width: auto; max-width: max-content; padding: 3px 7px; min-height: 22px; font-size: 10px; }
.card { padding: 10px; }
.kpi { padding: 7px 9px; }
.kpi strong { font-size: 18px; }
.drop-zone { height: 110px; }

.annotation-split { display: grid; grid-template-columns: minmax(460px, 1.15fr) minmax(360px, .85fr); gap: 10px; align-items: start; }
.right-editor { min-width: 0; display: grid; gap: 10px; }
.right-editor .inner-card { margin-bottom: 0; }
.annotation-split .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.annotation-split .field.wide,
.annotation-split .field.full { grid-column: 1 / -1; }
.annotation-split #ocrText { height: 690px; }
.annotation-split .annotations { max-height: 240px; }

.monthly-chart { display: grid; gap: 7px; }
.monthly-row { display: grid; grid-template-columns: 110px minmax(160px, 1fr) 52px; gap: 8px; align-items: center; }
.monthly-name { font-weight: 700; }
.monthly-bar { height: 18px; background: #e8efeb; border-radius: 999px; overflow: hidden; }
.monthly-fill { height: 100%; background: var(--accent-dark); border-radius: 999px; min-width: 2px; }
.monthly-count { text-align: right; color: var(--muted); font-weight: 800; }

@media (max-width: 1380px) {
  .annotation-split { grid-template-columns: 1fr; }
  .annotation-split #ocrText { height: 460px; }
}
@media (max-width: 1180px) {
  body.sidebar-collapsed .shell { grid-template-columns: 1fr; }
  body.sidebar-collapsed .sidebar { display: none; }
}
@media (max-width: 780px) {
  .annotation-split .field-grid { grid-template-columns: 1fr; }
  .monthly-row { grid-template-columns: 1fr; }
}

/* v6.4 agent mode and menu toggle */
.topbar { align-items: center; }
.top-title { min-width: 0; flex: 1 1 auto; }
.icon-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f6faf8;
  color: var(--accent-dark);
  display: inline-grid;
  place-items: center;
  font-weight: 900;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { border-color: #a9d7bb; background: #edf8f2; }
.icon-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.menu-toggle { align-self: flex-start; }
.agent-nav { display: none; }
body.agent-enabled .agent-nav { display: block; }
body.sidebar-collapsed .shell { grid-template-columns: minmax(0, 1fr); }
body.sidebar-collapsed .sidebar { display: none; }
body.sidebar-collapsed .app { padding-left: 14px; }
.agent-actions { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.agent-split { display: grid; grid-template-columns: minmax(520px, 1.05fr) minmax(420px, .95fr); gap: 10px; align-items: start; }
.agent-split #agentOcrText { margin: 0; height: 720px; overflow: auto; padding: 12px; background: #fff; color: var(--text); white-space: pre-wrap; font: 12px/1.5 "Consolas", "Menlo", monospace; user-select: text; }
.agent-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.agent-fields .field.wide { grid-column: 1 / -1; }
.agent-fields-card { margin-bottom: 0; }
.agent-workspace-card { min-height: 620px; }
@media (max-width: 1380px) {
  .agent-split { grid-template-columns: 1fr; }
  .agent-split #agentOcrText { height: 460px; }
}
@media (max-width: 780px) {
  .topbar { display: grid; grid-template-columns: auto 1fr; }
  .top-actions { grid-column: 1 / -1; }
  .agent-fields { grid-template-columns: 1fr; }
}


/* v6.5: компактная привязка OCR-фрагментов в режиме агента */
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.agent-bind {
  min-height: 24px;
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
  line-height: 1;
  border-radius: 7px;
  white-space: nowrap;
}
.agent-fields .field label { margin-bottom: 0; }
.field-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}
#agentSelectionInfo {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}
