:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1e23;
  --muted: #667085;
  --accent: #3a66d6;
  --accent-hover: #2f56ba;
  --danger: #d64545;
  --warn: #b3790f;
  --ok: #1c9a5b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.07);
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
#app { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
h1, h2, h3 { font-weight: 600; }
.hidden { display: none !important; }

/* ---- Login ---- */
.login-card { max-width: 380px; margin: 12vh auto 0; text-align: center; }
.login-card h2 { margin: 0 0 4px; font-size: 20px; }
.login-card .field { text-align: left; }
.login-card button { width: 100%; margin-top: 4px; }

/* ---- Topbar & tabs ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
  padding-bottom: 16px; margin-bottom: 20px; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .who { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tabs button {
  background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  font-weight: 500; transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tabs button:hover:not(.active) { border-color: var(--accent); color: var(--text); }
.tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ---- Buttons & form controls ---- */
button {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background 0.12s, filter 0.12s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover:not(:disabled) { background: var(--border); }
button.danger { background: var(--danger); }
button.danger:hover:not(:disabled) { filter: brightness(0.92); }
button:disabled { opacity: 0.5; cursor: default; }
button + button { margin-left: 8px; }

input, select, textarea {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 14px; width: 100%;
  font-family: inherit; transition: border-color 0.12s, background 0.12s;
}
input::placeholder, textarea::placeholder { color: #9aa3b0; }
input:hover, select:hover, textarea:hover { border-color: #c4cad3; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); background: var(--panel);
  box-shadow: 0 0 0 3px rgba(58, 102, 214, 0.14);
}
button:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="file"] { padding: 7px 8px; cursor: pointer; }

label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 14px; }
.field-narrow { max-width: 260px; }
.field-hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.card-desc { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.page-intro { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.status-msg { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.status-ok { color: var(--ok); font-size: 13px; margin: 12px 0 0; font-weight: 500; }
.status-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; font-weight: 500; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card > h3:first-child, .card > h2:first-child { margin: 0 0 4px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 220px; }
.button-group { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.button-group button { flex: none; margin-left: 0; }

.card:has(table) { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
td.nowrap-actions { white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tbody tr:hover td { background: var(--panel2); }
tr.clickable { cursor: pointer; }
tr.clickable.selected td { background: rgba(58,102,214,0.1); }
tr.clickable.selected { box-shadow: inset 3px 0 0 var(--accent); }
.empty-row { color: var(--muted); text-align: center; padding: 18px 10px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.high { background: rgba(214,69,69,0.12); color: var(--danger); }
.badge.medium { background: rgba(179,121,15,0.12); color: var(--warn); }
.badge.low { background: rgba(28,154,91,0.12); color: var(--ok); }
.badge.repository { background: rgba(58,102,214,0.12); color: var(--accent); }
.badge.ai { background: rgba(102,112,133,0.12); color: var(--muted); }
.badge.low_confidence { background: rgba(179,121,15,0.12); color: var(--warn); border: 1px dashed var(--warn); }
.badge.ok { background: rgba(28,154,91,0.1); color: var(--ok); }
.badge.status_done { background: rgba(28,154,91,0.12); color: var(--ok); }
.badge.status_processing, .badge.status_reviewing { background: rgba(179,121,15,0.12); color: var(--warn); }
.badge.status_error { background: rgba(214,69,69,0.12); color: var(--danger); }
.badge.status_approved { background: rgba(28,154,91,0.12); color: var(--ok); }
.badge.status_pending { background: rgba(179,121,15,0.12); color: var(--warn); }
.badge.status_rejected { background: rgba(214,69,69,0.12); color: var(--danger); }

.finding { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; background: var(--panel2); transition: box-shadow 0.3s, border-color 0.3s; }
.finding-head { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 8px; }
.finding-collapsed .finding-head { margin-bottom: 0; }
.finding-collapsed .meta { margin-bottom: 0; }
.collapse-toggle {
  background: none; border: none; padding: 0; color: var(--muted); font-size: 12px;
  width: 14px; flex: none; cursor: pointer; line-height: 1;
}
.finding .meta { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; align-items: center; }
.finding-body {
  max-height: 3000px; overflow: hidden; opacity: 1;
  transition: max-height 0.28s ease, opacity 0.2s ease, margin-top 0.28s ease;
}
.finding-collapsed .finding-body { max-height: 0; opacity: 0; margin-top: -8px; }
.finding .quote { margin: 6px 0; padding: 6px 12px; border-left: 3px solid var(--accent); color: var(--muted); font-size: 13px; font-style: italic; }
.finding .desc { color: var(--text); margin: 6px 0; }
.finding .rec { color: var(--muted); font-size: 13px; }
.finding .comment { color: var(--warn); font-size: 13px; margin-top: 6px; }
.finding .decision { color: var(--accent); font-size: 13px; margin-top: 6px; font-weight: 500; }
.finding-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.finding-actions button { font-size: 12px; padding: 6px 10px; margin-left: 0; }
.quick-decision-btn { font-size: 11px; padding: 3px 8px; margin-left: auto; }
.finding-quick-decision {
  margin: -4px 0 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel);
}
.finding-quick-decision textarea { width: 100%; box-sizing: border-box; margin-bottom: 8px; }
.finding-quick-decision .finding-actions { margin-top: 0; }
.finding-dismissed { opacity: 0.55; }
.finding-editing { background: var(--panel); border-color: var(--accent); }
.finding-decision-active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,102,214,0.15); }
.finding-flash { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,102,214,0.25); }
.clickable-tag { cursor: pointer; }
.clickable-tag:hover { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }

.cd-findings-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cd-findings-head h3 { margin: 0; margin-right: auto; }
.cd-findings-head button { font-size: 12px; padding: 6px 10px; }
.findings-filter { width: auto; font-size: 12px; padding: 6px 8px; }

#add-finding-float-btn {
  position: fixed; z-index: 1010; font-size: 12px; padding: 8px 12px;
  box-shadow: 0 4px 14px rgba(16,24,40,0.25);
}

/* ---- Прогресс проверки договора ---- */
.stepper { display: flex; align-items: center; gap: 6px; margin: 14px 0; flex-wrap: wrap; }
.stepper-step { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.stepper-step:not(:last-child)::after { content: ""; width: 24px; height: 1px; background: var(--border); margin-left: 6px; }
.stepper-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); flex: none; }
.stepper-step.active { color: var(--text); font-weight: 600; }
.stepper-step.active .stepper-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(58,102,214,0.18); }
.stepper-step.done { color: var(--ok); }
.stepper-step.done .stepper-dot { background: var(--ok); }
.stepper-step.error { color: var(--danger); font-weight: 600; }
.stepper-step.error .stepper-dot { background: var(--danger); }

/* ---- Разделённый вид: текст договора + риски ---- */
.cd-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.cd-toolbar button { font-size: 12px; padding: 6px 10px; }
.cd-split { align-items: stretch; }
.cd-text-card, .cd-findings-card {
  flex: 1; min-width: 320px; height: 640px;
  display: flex; flex-direction: column; overflow: hidden;
}
/* "На весь экран" — растягиваем блок на всю область браузера (не на весь экран ОС),
   поэтому используем position:fixed внутри страницы, а не Fullscreen API. */
.cd-workspace-maximized {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg); padding: 20px; box-sizing: border-box;
  display: flex; flex-direction: column;
}
.cd-workspace-maximized .cd-toolbar { flex: none; }
.cd-workspace-maximized .cd-split,
.cd-workspace-maximized .cmp-row { flex: 1; min-height: 0; }
.cd-workspace-maximized .cd-text-card, .cd-workspace-maximized .cd-findings-card,
.cd-workspace-maximized .cmp-doc-card, .cd-workspace-maximized .cmp-changes-card {
  height: 100%; display: flex; flex-direction: column;
}
.cd-workspace-maximized .cmp-panel, .cd-workspace-maximized .cmp-changes {
  flex: 1; min-height: 0; max-height: none;
}
.cd-workspace-maximized .cmp-doc-card > h3, .cd-workspace-maximized .cmp-changes-card > h3 { flex: none; }
body.no-scroll { overflow: hidden; }
.cd-text-card > h3, .cd-findings-card > h3, .cd-findings-card > .cd-findings-head { flex: none; margin: 2px 0 16px; }
.cd-text-panel, .cd-findings-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.cd-text-panel { max-height: none; }
.cd-section { padding: 8px 10px; border-radius: 8px; margin-bottom: 4px; transition: background 0.2s; }
.cd-section-label { font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.02em; }
.cd-section-text { white-space: pre-wrap; }
.cd-section.section-highlight { background: rgba(58,102,214,0.12); outline: 1px solid var(--accent); }

.risk-mark { padding: 1px 2px; border-radius: 3px; cursor: pointer; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.risk-mark-high { background: rgba(214,69,69,0.18); }
.risk-mark-medium { background: rgba(179,121,15,0.18); }
.risk-mark-low { background: rgba(28,154,91,0.18); }
.risk-mark.risk-mark-active {
  background: rgba(58,102,214,0.35) !important; outline: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(58,102,214,0.4); border-radius: 2px;
}
.risk-mark-pending {
  background: rgba(179,121,15,0.25); outline: 2px dashed var(--warn);
  border-radius: 2px;
}
.error-box { background: rgba(214,69,69,0.08); border: 1px solid var(--danger); color: var(--danger); padding: 10px 14px; border-radius: 8px; margin: 14px 0; }

.service-card { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.service-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(16,24,40,0.09); transform: translateY(-1px); }
.service-card h3 { margin: 0 0 8px; }

/* ---- Compare tool ---- */
.cmp-row { align-items: flex-start; }
.cmp-doc-card { flex: 1; min-width: 280px; }
.cmp-changes-card { flex: 0 0 280px; }

.cmp-panel {
  max-height: 480px; overflow-y: auto; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; padding: 4px 2px;
}
.preview-panel {
  max-height: 240px; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; background: var(--panel2); color: var(--muted);
}
.cmp-panel del { background: rgba(214,69,69,0.15); color: var(--danger); text-decoration: line-through; }
.cmp-panel ins { background: rgba(28,154,91,0.15); color: var(--ok); text-decoration: none; }
.cmp-panel .change-highlight {
  position: relative; z-index: 1;
  outline: 2px solid var(--accent); border-radius: 2px;
  background: rgba(58,102,214,0.3) !important; color: var(--text) !important;
  box-shadow: 0 1px 4px rgba(58,102,214,0.4);
}

.cmp-changes { list-style: none; max-height: 480px; overflow-y: auto; margin: 0; padding: 0; }
.cmp-changes li { padding: 8px; border-radius: 6px; margin-bottom: 6px; font-size: 12px; cursor: pointer; transition: outline 0.1s; }
.cmp-changes li:hover { outline: 1px solid var(--accent); }
.cmp-changes li.deleted { background: rgba(214,69,69,0.08); }
.cmp-changes li.added { background: rgba(28,154,91,0.08); }
.cmp-changes li .tag { font-weight: 600; display: block; margin-bottom: 2px; }

/* ---- Модальное окно (история изменений) ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,18,22,0.5); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--panel); border-radius: 12px; padding: 20px; max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; }
.modal-header button { padding: 4px 10px; font-size: 14px; }
.history-entry { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel2); }
.history-entry-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.history-entry .desc { margin: 4px 0; }
.history-entry button { margin-top: 8px; font-size: 12px; padding: 6px 10px; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  #app { padding: 16px 12px 40px; }
  .login-card { margin-top: 6vh; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .topbar h1 { font-size: 19px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
  .tabs button { white-space: nowrap; }
  .card { padding: 16px; }
  table { min-width: 420px; }
}
