/* СоцПульс AI — дизайн-система (чистый UI, без внешних зависимостей) */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --border: #e3e6ec;
  --border-strong: #cdd2dc;
  --text: #1a1f2b;
  --text-2: #5a6473;
  --text-3: #8a93a3;
  --accent: #4f46e5;
  --accent-600: #4338ca;
  --accent-soft: #eef0fe;
  --green: #15803d;
  --green-soft: #e7f6ec;
  --amber: #b45309;
  --amber-soft: #fdf2e2;
  --red: #b91c1c;
  --red-soft: #fdecec;
  --blue: #1d4ed8;
  --blue-soft: #e8effe;
  --shadow: 0 1px 2px rgba(20,26,40,.04), 0 4px 16px rgba(20,26,40,.06);
  --shadow-lg: 0 10px 40px rgba(20,26,40,.16);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PT Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
::selection { background: var(--accent-soft); }
/* размер иконок по умолчанию (специфичные .nav-item .ic / .btn .ic переопределяют) */
.ic { width: 18px; height: 18px; flex: none; }
.card-h .ic { color: var(--text-2); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: #11151f; color: #c7ccd6; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; flex: none; }
.brand .logo svg { width: 18px; height: 18px; }
.brand b { color: #fff; font-size: 15px; letter-spacing: -.02em; }
.brand small { display: block; color: #6b7280; font-size: 11px; font-weight: 500; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #5b6373; padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: #c7ccd6; cursor: pointer; font-weight: 500; font-size: 13.5px;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav-item:hover { background: #1b2130; color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .ic { width: 18px; height: 18px; flex: none; opacity: .9; }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 22px; position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 16px; font-weight: 650; }
.topbar .grow { flex: 1; }
.content { padding: 22px; max-width: 1280px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; font-size: 13.5px;
  cursor: pointer; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-600); }
.btn.danger { color: var(--red); border-color: #eccaca; background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn .ic { width: 16px; height: 16px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card .card-h { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; gap: 10px; }
.card .card-h h3 { font-size: 14.5px; }
.card .card-b { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2,1fr);} }

.stat { padding: 16px 18px; }
.stat .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.stat .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 80px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }

/* ---------- Table ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; color: var(--text-2); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.clickable { cursor: pointer; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 100px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.accent { background: var(--accent-soft); color: var(--accent-600); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 14px; cursor: pointer; font-weight: 550; font-size: 13.5px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Misc ---------- */
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.pill-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty { text-align: center; color: var(--text-3); padding: 40px 20px; }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 10px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex.between { justify-content: space-between; }
.flex.wrap { flex-wrap: wrap; }
.gap-6 { gap: 6px; } .gap-16 { gap: 16px; }
.mt-12 { margin-top: 12px; } .mt-18 { margin-top: 18px; } .mb-12 { margin-bottom: 12px; }
.scroll-x { overflow-x: auto; }

/* citations / sources */
.source-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
  background: var(--surface-2); font-size: 12.5px; }
.cite-ref { color: var(--accent); font-weight: 600; }
.answer-body { line-height: 1.65; white-space: pre-wrap; }
.answer-body sup { color: var(--accent); font-weight: 700; }

/* spinner */
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-2); padding: 30px; justify-content: center; }

/* toast */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column;
  gap: 10px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 11px 15px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 360px; animation: slideup .2s ease; }
.toast.err { background: #7f1d1d; } .toast.ok { background: #14532d; }
@keyframes slideup { from { transform: translateY(8px); opacity: 0; } }

/* modal */
#modal-root:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,20,30,.45); display: grid; place-items: center;
  z-index: 90; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; }
.modal .modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex;
  justify-content: space-between; align-items: center; }
.modal .modal-b { padding: 20px; }
.modal .modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex;
  justify-content: flex-end; gap: 10px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 70% -10%, #eef0fe, transparent), var(--bg); }
.login-card { width: 380px; max-width: 92vw; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }

/* switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 100px; transition: .15s; }
.switch .track::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }
.setting-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }

/* reasoning steps (RLM) */
.rlm-step { border-left: 2px solid var(--accent); padding: 6px 0 6px 12px; margin: 8px 0; }
.rlm-step .step-act { font-weight: 600; font-size: 12.5px; }
.rlm-badge { background: linear-gradient(90deg, #4f46e5, #7c3aed); color: #fff; }

/* chart */
.chart-bar-row { display: grid; grid-template-columns: 1fr 46px; gap: 10px; align-items: center; margin: 7px 0; }
.chart-bar-label { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-track { height: 22px; background: var(--surface-2); border-radius: 5px; overflow: hidden; position: relative; }
.chart-bar-fill { height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.chart-bar-val { font-size: 12px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
