/* ==========================================================================
   Помощник по договорам — design tokens & layout
   Палитра: light / фон #F5F7FA / поверхности #FFFFFF / текст #0F172A /
   границы #E2E8F0 / акцент #2553A0
   ========================================================================== */

:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-muted: #5B6B82;
  --border: #E2E8F0;
  --accent: #E01020;
  --accent-dark: #A80A18;
  --accent-soft: #FCE7E8;
  --danger: #C0362C;
  --danger-soft: #FBEBEA;
  --warn: #B7791F;
  --warn-soft: #FDF3E1;
  --ok: #1E7A4C;
  --ok-soft: #E7F5EC;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .08);
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Тёмный слой бренда (шапка / герой / подвал) — сильный контраст,
     энергичная подача поверх делового light-интерфейса */
  --ink: #0B0D10;
  --ink-soft: #17191E;
  --ink-border: #2B2E35;
  --ink-text: #F5F6F8;
  --ink-text-muted: #9AA0AC;
}

@media (prefers-reduced-motion: no-preference) {
  .mode-panel { transition: opacity .18s ease; }
  .risk-card-body { transition: grid-template-rows .18s ease; }
  .kb-panel { transition: opacity .15s ease, transform .15s ease; }
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

h1, h2, h3 { font-family: var(--font-body); font-weight: 700; color: var(--text); margin: 0 0 .5rem; letter-spacing: -.01em; }
h1, .h1 { font-size: 28px; font-weight: 800; }
h2, .h2 { font-size: 20px; }

a { color: var(--accent); }

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-dark);
  --bs-btn-hover-border-color: var(--accent-dark);
  --bs-btn-active-bg: var(--accent-dark);
  --bs-btn-active-border-color: var(--accent-dark);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13.5px;
  letter-spacing: .03em;
  padding: 10px 22px;
}
.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
  font-weight: 700;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.risk-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Header ───────────────────────────────────────────────────────── */

.app-header {
  background: var(--ink);
  border-bottom: 3px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.brand-name {
  font-weight: 800;
  font-size: 16.5px;
  color: var(--ink-text);
  text-transform: uppercase;
  letter-spacing: .02em;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--ink-soft);
  border: 1px solid var(--ink-border);
  border-radius: 999px;
  padding: 4px;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.mode-tab {
  border: none;
  background: transparent;
  color: var(--ink-text-muted);
  font-weight: 700;
  font-size: 13.5px;
  text-transform: uppercase;
  letter-spacing: .02em;
  padding: 9px 18px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.mode-tab i { margin-right: 6px; }

.mode-tab.active {
  background: var(--accent);
  color: #fff;
}

.mode-tab:not(.active):hover { background: rgba(255,255,255,.08); color: var(--ink-text); }

/* ── Disclaimer bar ───────────────────────────────────────────────── */

.disclaimer-bar {
  background: var(--ink-soft);
  color: #E8B85C;
  border-bottom: 1px solid var(--ink-border);
  font-size: 13.5px;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  text-align: center;
}

.disclaimer-bar i { color: #E8B85C; flex-shrink: 0; }

/* ── Main ─────────────────────────────────────────────────────────── */

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.mode-panel.d-none { display: none !important; }

/* Empty state (check) */

.check-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding-top: 0;
}

/* Асимметричный «герой»: текст слева, фирменный знак справа, диагональная
   акцентная полоса — сигнатурный приём поверх делового light-интерфейса. */
.check-hero {
  width: 100%;
  background: var(--ink);
  color: var(--ink-text);
  position: relative;
  overflow: hidden;
  margin: -32px -24px 8px;
  width: calc(100% + 48px);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.check-hero-stripe {
  position: absolute;
  top: 0;
  right: -10%;
  width: 55%;
  height: 100%;
  background: linear-gradient(100deg, transparent 0%, transparent 38%, var(--accent) 38%, var(--accent-dark) 100%);
  clip-path: polygon(38% 0, 100% 0, 100% 100%, 12% 100%);
  opacity: .92;
}

.check-hero-inner {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  padding: 56px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: center;
  gap: 24px;
}

.check-hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #FF6B75;
  margin-bottom: 14px;
}

.check-hero-copy h1 {
  color: var(--ink-text);
  font-size: 34px;
  font-weight: 800;
  line-height: 1.18;
  margin-bottom: 14px;
}

.check-hero-copy p {
  color: var(--ink-text-muted);
  font-size: 15.5px;
  max-width: 46ch;
  margin: 0;
}

.check-hero-mark {
  justify-self: end;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  color: var(--accent);
  flex-shrink: 0;
}

.dropzone {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 56px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}

.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-icon { font-size: 40px; color: var(--accent); margin-bottom: 12px; }
.dropzone-title { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
.dropzone-hint { color: var(--text-muted); font-size: 13.5px; margin: 0 0 20px; }

.example-card { width: 100%; max-width: 620px; }
.example-card-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Loading state */

.check-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-muted);
}
.check-loading p { margin: 0; font-size: 16px; color: var(--text); }
.loading-hint { font-size: 13.5px !important; color: var(--text-muted) !important; }

/* Results: two-column layout */

.results-summary {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 14.5px;
}

.results-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.risks-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.risk-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.risk-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.risk-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}

.risk-card-title { font-weight: 500; flex: 1; }
.risk-card-chevron { color: var(--text-muted); transition: transform .15s ease; flex-shrink: 0; }
.risk-card.is-expanded .risk-card-chevron { transform: rotate(180deg); }

.risk-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-high { background: var(--danger-soft); color: var(--danger); }
.badge-medium { background: var(--warn-soft); color: var(--warn); }
.badge-low { background: var(--ok-soft); color: var(--ok); }

.risk-card-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 12px;
}
.risk-card.is-expanded .risk-card-body { display: block; }

.risk-quote {
  font-family: var(--font-mono);
  font-size: 14px;
  background: #F1F4F8;
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
}

.law-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
}
.law-link:hover { text-decoration: underline; }

.risk-detail-panel {
  position: sticky;
  top: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 200px;
}

.risk-detail-empty { color: var(--text-muted); font-size: 14px; }

.risk-detail-title { font-weight: 600; font-size: 17px; margin-bottom: 10px; }

/* Compose mode */

.compose-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.compose-form-col label.form-label { font-weight: 500; font-size: 13.5px; margin-top: 14px; }
.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-weight: 500; font-size: 13.5px; margin-bottom: 6px; }
.field-group .req { color: var(--danger); }
.field-group textarea, .field-group input, .field-group select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 14.5px;
  background: var(--surface);
  color: var(--text);
}
.field-group textarea { min-height: 76px; resize: vertical; }
.field-group.has-error input,
.field-group.has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; display: none; }
.field-group.has-error .field-error { display: block; }

.btn-generate { margin-top: 8px; }
.download-row { display: flex; gap: 10px; flex-wrap: wrap; }

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 420px;
  position: sticky;
  top: 90px;
}

.preview-empty { color: var(--text-muted); font-size: 14px; }

.preview-content h3 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 18px;
  margin-bottom: 6px;
}
.preview-content .preview-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}
.preview-content p { white-space: pre-wrap; margin: 0 0 8px; font-size: 14px; }
.preview-content.is-draft { opacity: .68; }
.preview-draft-tag {
  display: inline-block;
  font-size: 11.5px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 2px 10px;
  margin-bottom: 10px;
}

/* Buttons with loading state */

.btn .spinner-border { width: 14px; height: 14px; }
button.is-loading .btn-label { visibility: hidden; position: absolute; }
button.is-loading { position: relative; }
button.is-loading .spinner-border { display: inline-block !important; position: absolute; left: 50%; margin-left: -7px; }

/* ── Toasts ───────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 480px);
}

.app-toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in .18s ease;
}
.app-toast.toast-info { border-left-color: var(--accent); }
.app-toast i { color: var(--danger); margin-top: 2px; }
.app-toast.toast-info i { color: var(--accent); }
.app-toast .toast-retry {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Footer ───────────────────────────────────────────────────────── */

.app-footer {
  background: var(--ink);
  border-top: 3px solid var(--accent);
  padding: 20px 24px 32px;
  text-align: center;
  color: var(--ink-text-muted);
  font-size: 12.5px;
}
.app-footer p { max-width: 720px; margin: 0 auto 8px; }
.footer-admin-link { font-size: 12px; color: var(--ink-text-muted); text-decoration: underline; }
.footer-admin-link:hover { color: var(--ink-text); }

/* ── KB floating widget ──────────────────────────────────────────── */

.kb-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 20px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 40;
}
.kb-fab:hover { background: var(--accent-dark); }

.kb-panel {
  position: fixed;
  right: 20px;
  bottom: 84px;
  width: min(92vw, 340px);
  max-height: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}
.kb-panel.d-none { display: none !important; }

.kb-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}
.kb-panel-close { background: none; border: none; color: var(--text-muted); cursor: pointer; }

.kb-panel-body {
  padding: 12px 14px;
  overflow-y: auto;
  flex: 1;
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kb-hint { color: var(--text-muted); margin: 0; }
.kb-msg { padding: 8px 10px; border-radius: 8px; font-size: 13.5px; }
.kb-msg-question { background: var(--accent-soft); align-self: flex-end; }
.kb-msg-answer { background: #F1F4F8; align-self: flex-start; }

.kb-panel-form {
  display: flex;
  border-top: 1px solid var(--border);
}
.kb-panel-form input {
  flex: 1;
  border: none;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: var(--font-body);
}
.kb-panel-form input:focus { outline: none; }
.kb-panel-form button {
  border: none;
  background: var(--accent);
  color: #fff;
  width: 44px;
  cursor: pointer;
}

/* ==========================================================================
   Responsive < 768px — по дизайн-контракту
   ========================================================================== */

@media (max-width: 767px) {
  .header-inner { padding: 12px 16px; gap: 12px; }
  .mode-tabs { width: 100%; justify-content: flex-start; }

  .app-main { padding: 20px 14px 48px; }

  .check-hero { margin: -20px -14px 8px; width: calc(100% + 28px); }
  .check-hero-inner { grid-template-columns: 1fr; padding: 36px 20px; gap: 20px; }
  .check-hero-copy h1 { font-size: 26px; }
  .check-hero-mark { justify-self: start; width: 88px; height: 88px; font-size: 34px; }
  .check-hero-stripe { width: 70%; right: -20%; opacity: .5; }

  .dropzone { padding: 36px 18px; }

  .results-columns { grid-template-columns: 1fr; }
  .risk-detail-panel { position: static; top: auto; margin-top: 16px; }

  .compose-columns { grid-template-columns: 1fr; }
  .preview-panel { position: static; top: auto; margin-top: 20px; }

  .kb-panel { right: 12px; left: 12px; width: auto; bottom: 80px; }
  .kb-fab { right: 16px; bottom: 16px; }
}
