/* ═══════════════════════════════════════════════════════════
   КГД МФ РК — Unified Frontend
   Design: Official government style, clean and modern
   ═══════════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────────── */
:root {
  --blue-900: #07193a;
  --blue-800: #0c2d6b;
  --blue-700: #10388a;
  --blue-600: #1a4fa0;
  --blue-100: #e8eef8;
  --blue-50:  #f0f4fb;

  --gold:       #c8962b;
  --gold-light: #fdf3e0;
  --gold-dark:  #9e7520;

  --green:       #1b6b3a;
  --green-light: #e8f5ee;
  --green-mid:   #2d8a4e;

  --red:       #9b1c1c;
  --red-light: #fdeaea;
  --red-mid:   #c53030;

  --amber:       #b45309;
  --amber-light: #fef3e2;

  --bg:      #f0f4f9;
  --surface: #ffffff;
  --border:  #d0d9e8;
  --border-strong: #a8b8d0;

  --text:       #0f1f35;
  --text-muted: #4a5f7a;
  --text-light: #6b7f96;

  --header-h: 60px;
  --wf-h: 60px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(12,45,107,.08), 0 1px 2px rgba(12,45,107,.04);
  --shadow:    0 4px 12px rgba(12,45,107,.10), 0 1px 3px rgba(12,45,107,.06);
  --shadow-lg: 0 8px 24px rgba(12,45,107,.14);

  --transition: 180ms ease;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── App shell ──────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ══════════════════════════════════════════════ HEADER ══ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--blue-800);
  border-bottom: 3px solid var(--gold);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}

/* Brand */
.header-brand { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.brand-emblem { width: 36px; height: 36px; flex-shrink: 0; }
.brand-text { line-height: 1.2; }
.brand-title {
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .02em;
}
.brand-subtitle {
  font-size: .72rem;
  color: rgba(255,255,255,.65);
  letter-spacing: .01em;
}

/* Nav tabs */
.header-nav {
  display: flex;
  gap: .375rem;
  flex: 1;
  justify-content: center;
}
.nav-tab {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem 1.1rem;
  border-radius: var(--radius);
  font-size: .84rem;
  font-weight: 500;
  color: rgba(255,255,255,.7);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.nav-tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-tab.active {
  background: var(--gold);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(200,150,43,.35);
}
.tab-icon { width: 15px; height: 15px; flex-shrink: 0; }
.tab-badge {
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: .65rem;
  font-weight: 600;
  padding: .1rem .4rem;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.nav-tab.active .tab-badge { background: rgba(255,255,255,.25); }

/* Meta */
.header-meta { flex-shrink: 0; }
.header-date { font-size: .78rem; color: rgba(255,255,255,.55); }

/* ══════════════════════════════════════════ PANEL SWITCH ══ */
.panel { display: none; flex: 1; flex-direction: column; }
.panel.active { display: flex; }

/* ══════════════════════════════════════ EVAL TOOL PANEL ══ */

/* Search hero */
.search-hero {
  background: linear-gradient(135deg, var(--blue-800) 0%, var(--blue-700) 60%, var(--blue-600) 100%);
  padding: 3rem 1.5rem;
  display: flex;
  justify-content: center;
}
.search-container { max-width: 640px; width: 100%; text-align: center; }
.search-eyebrow {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: .5rem;
}
.search-heading {
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: .5rem;
  line-height: 1.2;
}
.search-sub {
  font-size: .9rem;
  color: rgba(255,255,255,.7);
  margin-bottom: 1.75rem;
}
.search-row { display: flex; gap: .625rem; }
.search-input-wrap {
  flex: 1;
  position: relative;
}
.search-icon {
  position: absolute;
  left: .875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-light);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: .75rem 1rem .75rem 2.5rem;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.95);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: .08em;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,150,43,.25);
}
.search-input::placeholder { letter-spacing: .12em; color: var(--text-light); }
.btn-analyze {
  padding: .75rem 1.5rem;
  background: var(--gold);
  color: #fff;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 12px rgba(200,150,43,.35);
}
.btn-analyze:hover { background: var(--gold-dark); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(200,150,43,.4); }
.btn-analyze:active { transform: translateY(0); }
.search-hint { margin-top: .75rem; font-size: .78rem; color: rgba(255,255,255,.5); }

/* Workflow bar */
.workflow-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  padding: 0 1.5rem;
  height: var(--wf-h);
  align-items: center;
  box-shadow: var(--shadow-sm);
}
.workflow-inner {
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 700px;
  width: 100%;
}
.wf-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  min-width: 80px;
  cursor: default;
}
.wf-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-light);
  font-size: .78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.wf-dot svg { width: 12px; height: 12px; }
.wf-label {
  font-size: .68rem;
  color: var(--text-light);
  white-space: nowrap;
  font-weight: 500;
  transition: color var(--transition);
}
.wf-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin-bottom: 14px; /* align with dot center */
  transition: background var(--transition);
}
.wf-step.active .wf-dot {
  border-color: var(--blue-800);
  background: var(--blue-800);
  color: #fff;
}
.wf-step.active .wf-label { color: var(--blue-800); font-weight: 600; }
.wf-step.done .wf-dot {
  border-color: var(--green-mid);
  background: var(--green-mid);
  color: #fff;
}
.wf-step.done .wf-label { color: var(--green-mid); }
.wf-step.done + .wf-line { background: var(--green-mid); }

/* Loading */
.eval-loading {
  padding: 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue-700);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: .875rem; color: var(--text-muted); }

/* Results area */
#results-area { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* Summary card */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}
.summary-info { flex: 1; min-width: 180px; }
.summary-label { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-light); margin-bottom: .35rem; }
.summary-bin { font-size: 1.4rem; font-weight: 700; color: var(--blue-800); letter-spacing: .1em; font-family: 'Courier New', monospace; margin-bottom: .6rem; }
.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .8rem;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
}
.summary-badge.badge-green { background: var(--green-light); color: var(--green); border: 1px solid #b7dfc8; }
.summary-badge.badge-amber { background: var(--amber-light); color: var(--amber); border: 1px solid #fcd9a4; }
.summary-badge.badge-red   { background: var(--red-light);   color: var(--red);   border: 1px solid #f5bebe; }

.summary-score-area { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.score-circle { position: relative; width: 80px; height: 80px; }
.score-svg { width: 80px; height: 80px; transform: rotate(-90deg); }
.score-track { fill: none; stroke: var(--blue-100); stroke-width: 6; }
.score-fill {
  fill: none;
  stroke: var(--blue-700);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 188.5;
  stroke-dashoffset: 188.5;
  transition: stroke-dashoffset .6s ease, stroke .3s;
}
.score-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue-800);
}
.score-caption { font-size: .7rem; color: var(--text-light); text-align: center; }

.summary-actions { display: flex; flex-direction: column; gap: .5rem; min-width: 160px; }
.btn-export-xl, .btn-export-dc {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 600;
  transition: all var(--transition);
  justify-content: center;
}
.btn-export-xl svg, .btn-export-dc svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-export-xl {
  background: var(--blue-800);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-export-xl:hover { background: var(--blue-700); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-export-xl:disabled {
  opacity: .8;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}
.btn-export-xl.is-loading {
  background: var(--blue-700);
}
.btn-export-xl.is-loading svg {
  display: none;
}
.btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
.btn-export-dc {
  background: var(--surface);
  color: var(--blue-800);
  border: 1.5px solid var(--border-strong);
}
.btn-export-dc:hover { background: var(--blue-50); border-color: var(--blue-600); }

/* Analysis sub-nav */
.analysis-nav {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.analysis-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 1rem 1.25rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.analysis-tab svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .6; transition: opacity var(--transition); }
.analysis-tab:hover { color: var(--blue-800); background: var(--blue-50); }
.analysis-tab:hover svg { opacity: 1; }
.analysis-tab.active {
  color: var(--blue-800);
  border-bottom-color: var(--blue-800);
  font-weight: 700;
  background: var(--surface);
}
.analysis-tab.active svg { opacity: 1; }

/* Section content */
.section-content { display: none; }
.section-content.active { display: block; }

.section-intro {
  padding: 1.25rem 1.5rem .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.section-h2 { font-size: 1.05rem; font-weight: 700; color: var(--blue-800); margin-bottom: .2rem; }
.section-p { font-size: .82rem; color: var(--text-muted); }

/* ── Reliability checks grid ── */
.checks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}
.check-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  border-left: 4px solid transparent;
}
.check-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.check-card.check-passed { border-left-color: var(--green-mid); }
.check-card.check-failed { border-left-color: var(--red-mid); }
.check-header { display: flex; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; }
.check-status-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
}
.check-passed .check-status-icon { background: var(--green-light); }
.check-failed .check-status-icon { background: var(--red-light); }
.check-name { font-size: .9rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.check-value-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .5rem; }
.check-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--blue-800);
}
.check-threshold {
  font-size: .75rem;
  color: var(--text-light);
  background: var(--bg);
  padding: .15rem .5rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.check-details {
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.45;
  border-top: 1px solid var(--border);
  padding-top: .6rem;
  margin-top: .6rem;
}

/* ── Counterparties ── */
.cp-filters {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.filter-row { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.filter-label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.filter-input {
  padding: .45rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  outline: none;
  transition: border-color var(--transition);
}
.filter-input:focus { border-color: var(--blue-600); }
.btn-sm-outline {
  padding: .45rem .9rem;
  border: 1.5px solid var(--blue-700);
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 600;
  color: var(--blue-700);
  background: transparent;
  transition: all var(--transition);
  cursor: pointer;
}
.btn-sm-outline:hover { background: var(--blue-50); }

.cp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 1.25rem;
}
.cp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0; /* allow grid to shrink below content width */
}
.cp-card-hd {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--blue-50);
  border-bottom: 1px solid var(--border);
}
.cp-card-wide { grid-column: 1 / -1; }
.cp-emoji { font-size: 1.25rem; line-height: 1; }
.cp-card-title { font-size: .88rem; font-weight: 700; color: var(--blue-800); }
.cp-card-sub { font-size: .72rem; color: var(--text-light); }

/* ── Data tables ── */
.tbl-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-height: 320px;
}
.tbl-wrapper::-webkit-scrollbar { width: 5px; height: 5px; }
.tbl-wrapper::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--blue-50);
  color: var(--blue-800);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .55rem .75rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--blue-50); }
.data-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #eef3fb;
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}
.tbl-placeholder { padding: 1.5rem; color: var(--text-light); font-size: .85rem; text-align: center; }
.tbl-empty { padding: 1.5rem; color: var(--text-light); font-size: .85rem; text-align: center; font-style: italic; }
.tbl-error { padding: 1.5rem; color: var(--red-mid); font-size: .85rem; text-align: center; }
.lazy-sentinel { height: 1px; }
.goods-load-more { display: block; margin: .75rem auto; }

/* ── Goods section ── */
#section-goods .section-content-body { padding: 1.25rem; }
.metrics-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.metric-card {
  flex: 1;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.metric-val { font-size: 2rem; font-weight: 700; color: var(--blue-800); line-height: 1; margin-bottom: .3rem; }
.metric-lbl { font-size: .75rem; color: var(--text-muted); font-weight: 500; }
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .84rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-warning { background: var(--amber-light); color: var(--amber); border-color: #fcd9a4; }
.alert-success { background: var(--green-light); color: var(--green); border-color: #b7dfc8; }
.goods-section-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.5rem 0 .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.flag-chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.flag-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .25rem .65rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
}
/* ── Goods inner tabs (mirrors Streamlit tab layout) ── */
.goods-detail-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: 1.5rem;
  overflow: hidden;
}
.goods-detail-label {
  padding: .75rem 1.25rem;
  font-size: .88rem;
  font-weight: 700;
  color: var(--blue-800);
  background: var(--blue-50);
  border-bottom: 1px solid var(--border);
}
.inner-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}
.inner-tab {
  padding: .6rem 1.1rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.inner-tab:hover { color: var(--blue-800); background: var(--blue-50); }
.inner-tab.active { color: var(--blue-800); border-bottom-color: var(--blue-800); font-weight: 600; }
.inner-tab-pane { display: none; }
.inner-tab-pane.active { display: block; }
#goods-content { padding: 1.25rem; }

/* ── Goods loading state ── */
.goods-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3.5rem 2rem;
  text-align: center;
}
.goods-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid var(--blue-100);
  border-top-color: var(--blue-700);
  animation: spin .9s linear infinite;
}
.goods-loading-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue-800);
}
.goods-loading-sub {
  font-size: .8rem;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.5;
}

/* ══════════════════════════════════════════ RAG PANEL ══ */
.rag-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 230px;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* Sidebars */
.rag-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1rem;
  overflow-y: auto;
}
.rag-sidebar-right { border-right: none; border-left: 1px solid var(--border); }
.sidebar-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-light);
  padding: .25rem 0;
}
.sidebar-sep { border-top: 1px solid var(--border); margin: .25rem 0; }

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem;
  background: var(--blue-800);
  color: #fff;
  border-radius: var(--radius);
  font-size: .84rem;
  font-weight: 600;
  transition: background var(--transition);
}
.btn-new-chat svg { width: 15px; height: 15px; }
.btn-new-chat:hover { background: var(--blue-700); }

.chat-history-list { flex: 1; display: flex; flex-direction: column; gap: .25rem; overflow-y: auto; min-height: 0; }
.chat-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .65rem;
  border-radius: var(--radius);
  font-size: .82rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  gap: .5rem;
}
.chat-history-item:hover { background: var(--blue-50); color: var(--text); }
.chat-history-item.active { background: var(--blue-100); color: var(--blue-800); font-weight: 600; }
.chat-history-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-history-delete { font-size: .75rem; opacity: 0; color: var(--red-mid); padding: .1rem .25rem; border-radius: 4px; }
.chat-history-item:hover .chat-history-delete { opacity: 1; }
.chat-history-delete:hover { background: var(--red-light); }

.btn-ghost-danger {
  font-size: .78rem;
  font-weight: 500;
  color: var(--red-mid);
  padding: .4rem .5rem;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  background: none;
  border: none;
  transition: background var(--transition);
}
.btn-ghost-danger:hover { background: var(--red-light); }

/* Upload */
.upload-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .75rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: .8rem;
  color: var(--blue-700);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  justify-content: center;
}
.upload-label svg { width: 15px; height: 15px; flex-shrink: 0; }
.upload-label:hover { background: var(--blue-50); border-color: var(--blue-600); }
.file-input-hidden { display: none; }
.upload-status { font-size: .75rem; color: var(--text-muted); margin-top: .35rem; min-height: 1.2em; }
.upload-status.status-info    { color: var(--blue-800); }
.upload-status.status-success { color: var(--green-mid); }
.upload-status.status-error   { color: var(--red); }

.prompt-textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .8rem;
  color: var(--text);
  resize: vertical;
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.45;
}
.prompt-textarea:focus { border-color: var(--blue-600); }

/* Chat main area */
.rag-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rag-main-header {
  padding: .875rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.rag-main-title { font-size: 1rem; font-weight: 700; color: var(--blue-800); }
.rag-main-sub { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Messages */
.message { display: flex; gap: .75rem; max-width: 85%; animation: fadeInUp .2s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message.system { align-self: center; max-width: 100%; }
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.message.user .msg-avatar { background: var(--blue-800); color: #fff; }
.message.assistant .msg-avatar { background: var(--gold); color: #fff; font-size: .7rem; }
.msg-bubble {
  padding: .75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: .875rem;
  line-height: 1.55;
  max-width: 100%;
}
.message.user .msg-bubble { background: var(--blue-800); color: #fff; border-bottom-right-radius: 4px; }
.message.assistant .msg-bubble { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.message.system .msg-bubble { background: var(--blue-50); color: var(--text-muted); font-size: .82rem; border: 1px solid var(--border); text-align: center; }

/* Markdown in messages */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { margin: .6rem 0 .3rem; font-size: 1em; }
.msg-bubble p { margin-bottom: .5rem; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul,.msg-bubble ol { padding-left: 1.4rem; margin-bottom: .5rem; }
.msg-bubble li { margin-bottom: .2rem; }
.msg-bubble code { background: rgba(0,0,0,.08); padding: .1rem .3rem; border-radius: 4px; font-family: 'Courier New', monospace; font-size: .85em; }
.message.user .msg-bubble code { background: rgba(255,255,255,.2); }
.msg-bubble pre { background: rgba(0,0,0,.08); padding: .75rem; border-radius: var(--radius); overflow-x: auto; margin: .5rem 0; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble blockquote { border-left: 3px solid var(--border-strong); padding-left: .75rem; margin: .5rem 0; color: var(--text-muted); }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .85em; }
.msg-bubble th,.msg-bubble td { border: 1px solid var(--border); padding: .3rem .6rem; }
.msg-bubble th { background: var(--blue-50); font-weight: 700; }

/* Citations */
.msg-sources {
  margin-top: .75rem;
  padding-top: .6rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}
.sources-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-right: .25rem;
}
.citation-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 20px;
  background: var(--blue-50);
  border: 1px solid var(--border);
  color: var(--blue-800);
  font-size: .72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.citation-link:hover { background: var(--blue-800); color: #fff; border-color: var(--blue-800); }

.typing-indicator { display: flex; align-items: center; gap: .35rem; padding: .5rem 0; }
.typing-dot { width: 7px; height: 7px; background: var(--text-light); border-radius: 50%; animation: bounce .9s infinite; }
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Chat input */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: .875rem 1.25rem;
  display: flex;
  gap: .625rem;
  align-items: flex-end;
  background: var(--surface);
  flex-shrink: 0;
}
.chat-textarea {
  flex: 1;
  padding: .65rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color var(--transition);
}
.chat-textarea:focus { border-color: var(--blue-600); }
.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue-800);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
  cursor: pointer;
  border: none;
}
.btn-send svg { width: 16px; height: 16px; }
.btn-send:hover { background: var(--blue-700); transform: scale(1.05); }
.btn-send:disabled { background: var(--border-strong); cursor: not-allowed; transform: none; }

/* ══════════════════════════════════ MODAL ══ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7,25,58,.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: .95rem; font-weight: 700; color: var(--blue-800); }
.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .9rem;
  cursor: pointer;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-size: .875rem;
  line-height: 1.6;
  color: var(--text);
}
.modal-body strong { color: var(--blue-800); }

/* ══════════════════════════════════ TOAST ══ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: .65rem 1.25rem;
  border-radius: 20px;
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s ease, opacity .3s ease;
  white-space: nowrap;
  z-index: 9999;
}
.toast.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--red-mid); }
.toast.toast-success { background: var(--green-mid); }
.toast.toast-info { background: var(--blue-700); }

/* ══════════════════════════════════ UTILITIES ══ */
.btn { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; border: none; border-radius: var(--radius); font: inherit; font-weight: 600; transition: all var(--transition); }

/* ══════════════════════════════════ SCROLLBAR ══ */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ══════════════════════════════════ RESPONSIVE ══ */
@media (max-width: 900px) {
  .rag-layout { grid-template-columns: 0 1fr 0; }
  .rag-sidebar { display: none; }
  .checks-grid { grid-template-columns: 1fr; }
  .cp-grid { grid-template-columns: 1fr 1fr; }
  .summary-card { flex-direction: column; }
  .summary-actions { flex-direction: row; }
  .analysis-tab { font-size: .75rem; padding: .75rem .5rem; }
}
@media (max-width: 600px) {
  .search-row { flex-direction: column; }
  .btn-analyze { width: 100%; justify-content: center; }
  .header-nav .tab-badge { display: none; }
  .nav-tab { padding: .4rem .7rem; font-size: .78rem; }
  .brand-subtitle { display: none; }
}
