:root {
  --bg: #ffffff;
  --panel: #f7f7f9;
  --panel-2: #eeeef2;
  --border: #e6e6ec;
  --text: #1c1d22;
  --muted: #8b8b95;
  --accent: #6d5efc;
  --accent-2: #5a4ce0;
  --accent-weak: #efecff;
  --danger: #e5484d;
  --ok: #2e9e6b;
  --ok-weak: #e7f6ee;
  --danger-weak: #fdecec;
  --shadow: 0 1px 2px rgba(20,20,40,.05), 0 10px 30px rgba(20,20,40,.10);
  --side-bg: #1b1c22;
  --side-text: #e7e7ec;
  --side-muted: #9595a1;
  --side-hover: #2a2b34;
  --side-active: rgba(109,94,252,.26);
  --side-border: #2e2f3a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-size: 15px; color: var(--text); background: var(--bg);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}
svg.lucide { width: 18px; height: 18px; flex-shrink: 0; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ shell */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--side-bg); color: var(--side-text);
  border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column; gap: 6px; padding: 14px 12px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 16px; font-weight: 800; letter-spacing: .18em; padding: 4px 0 4px 10px; }
.side-icon { color: var(--side-muted); }
.side-icon:hover { background: var(--side-hover); color: var(--side-text); }

/* свёрнутый сайдбар — узкая полоска с иконками */
body.sb-collapsed .sidebar { width: 62px; padding: 14px 8px; }
body.sb-collapsed .brand,
body.sb-collapsed .nav-item span,
body.sb-collapsed .nav-count { display: none; }
body.sb-collapsed .sidebar-top { justify-content: center; }
body.sb-collapsed .nav-item { justify-content: center; padding: 9px 0; }
.divider { height: 1px; background: var(--side-border); margin: 4px 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 8px; color: var(--side-muted); font-weight: 600; text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--side-hover); color: var(--side-text); text-decoration: none; }
.nav-item.active { background: var(--side-active); color: var(--side-text); }
.nav-item.active svg { color: var(--accent); }
.nav-count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--side-hover); color: var(--side-muted);
  border-radius: 999px; padding: 1px 8px;
}
.nav-item.active .nav-count { background: rgba(109,94,252,.35); color: var(--side-text); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page-head {
  display: flex; align-items: center; gap: 12px; padding: 0 24px; height: 58px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.page-head h1 { font-size: 16px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 10px; }
.page-head h1:empty { display: none; }
.head-actions { display: flex; gap: 6px; align-items: center; }
.page-head .notif-wrap { margin-left: auto; }

/* фильтры страницы отзывов */
.filter-wrap { position: relative; }
.filter-dot {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px;
  border-radius: 999px; background: var(--accent); pointer-events: none;
}
.filter-panel {
  position: absolute; left: 0; top: 42px; width: 300px; z-index: 80;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 16px;
}
.filter-panel form { display: flex; flex-direction: column; gap: 12px; }
.filter-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.primary.small-primary { height: 34px; padding: 0 14px; border-radius: 10px; font-size: 13px; }
.page-body {
  flex: 1; overflow-y: auto; padding: 20px 24px 40px;
  display: flex; flex-direction: column; gap: 16px; align-items: stretch;
}
/* Дочерние блоки не сжимаются под высоту экрана (иначе overflow:hidden
   у карточек обрезает таблицы) — прокручивается сам .page-body */
.page-body > * { flex-shrink: 0; }
.count-pill {
  background: var(--accent-weak); color: var(--accent-2); border-radius: 999px;
  font-size: 12px; font-weight: 600; padding: 2px 10px;
}
.back-link { display: inline-flex; color: var(--muted); }
.back-link:hover { color: var(--text); }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }
.card h2 svg.lucide { color: var(--accent); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }

/* ------------------------------------------------------------------ forms */
input, textarea, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
}
/* контролы одной высоты с кнопками (44px), чтобы ряды выглядели ровно */
input:not([type="checkbox"]):not([type="radio"]), select {
  height: 44px; padding-top: 0; padding-bottom: 0;
}
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b8b95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.inline { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.inline .grow, .filters .grow { flex: 1; min-width: 180px; }

button.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border: none; border-radius: 13px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
button.primary:hover { background: var(--accent-2); }
button.primary:disabled { opacity: .5; cursor: default; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 13px; font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn-ghost:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.btn-ghost:disabled { opacity: .5; cursor: default; }
.btn-ghost.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.icon {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 8px; border: none; background: transparent; color: var(--muted); cursor: pointer;
}
.icon:hover { background: var(--panel-2); color: var(--text); }
.icon.danger:hover { background: var(--danger-weak); color: var(--danger); }
.icon:disabled { opacity: .35; cursor: default; }
.icon:disabled:hover { background: transparent; color: var(--muted); }

/* ---------------------------------------------------------------- filters */
.filters {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 12px 16px;
}
.filters select { min-width: 160px; }
.filters .btn-ghost { background: var(--bg); }

/* ----------------------------------------------------------------- tables */
.table-wrap { padding: 0; overflow: hidden; }
.table-wrap h2 { padding: 16px 18px 0; }
.table-title { display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.table-title h2 { margin: 0; padding: 0; font-size: 14px; font-weight: 600; }
table { border-collapse: collapse; width: 100%; }
th {
  text-align: left; font-size: 12px; color: #fff; font-weight: 600;
  padding: 12px 14px; border-bottom: none; background: var(--side-bg);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 14px; }
tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--panel); }
tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 32px; }
.col-date { white-space: nowrap; width: 100px; }
.col-mp { white-space: nowrap; width: 140px; }
.col-side { width: 70px; }
.filename { word-break: break-all; }
.sort-link { display: inline-flex; align-items: center; gap: 4px; color: #b9b1ff; }
.sort-link:hover { color: #fff; text-decoration: none; }
.sort-link svg.lucide { width: 14px; height: 14px; }
.cat-link { font-weight: 600; }
.row-actions { width: 44px; }
.row-actions form { margin: 0; }

.review-cell { width: 38%; }
.review-text { white-space: pre-wrap; word-break: break-word; }

/* ------------------------------------------------------------------- tags */
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-weak); color: var(--accent-2);
  border-radius: 999px; padding: 2px 8px 2px 10px; font-size: 12px; font-weight: 600;
}
.tag-llm { background: var(--panel-2); color: var(--text); }
.tag .dot {
  width: 8px; height: 8px; border-radius: 999px; display: inline-block;
  margin-right: 5px; flex-shrink: 0;
}
.tag .dot.positive { background: var(--ok); }
.tag .dot.negative { background: var(--danger); }
.tag .dot.mixed { background: #d9a545; }
.tag .dot.neutral { background: var(--muted); }
.tag-x {
  border: none; background: transparent; color: inherit; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px; opacity: .55; border-radius: 999px;
}
.tag-x:hover { opacity: 1; }
.tag-add {
  width: 22px; height: 22px; border-radius: 999px; border: 1px dashed var(--border);
  background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
}
.tag-add:hover { border-color: var(--accent); color: var(--accent-2); background: var(--accent-weak); }

.tag-menu {
  position: absolute; z-index: 30; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
  min-width: 200px; padding: 6px;
}
.tag-menu button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text);
}
.tag-menu button:hover { background: var(--accent-weak); color: var(--accent-2); }
.tag-menu .none { color: var(--muted); cursor: default; }
.tag-menu .none:hover { background: transparent; color: var(--muted); }

/* -------------------------------------------------------------- side pill */
.side-pill { border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.side-pill.pros { background: var(--ok-weak); color: var(--ok); }
.side-pill.cons { background: var(--danger-weak); color: var(--danger); }
.side-pill.mixed { background: #f5efe1; color: #9a7b3f; }
.side-pill.neutral { background: var(--panel-2); color: var(--muted); }
.side-pill.formal { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.review-cell .side-pill { display: inline-block; margin-bottom: 6px; }

/* -------------------------------------------------------------- segmented */
.seg { display: inline-flex; gap: 4px; background: var(--panel-2); border-radius: 12px; padding: 4px; align-self: flex-start; }
.seg-item {
  padding: 6px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  color: var(--muted); text-decoration: none;
}
.seg-item:hover { color: var(--text); text-decoration: none; }
.seg-item.active { background: var(--bg); color: var(--accent-2); box-shadow: 0 1px 2px rgba(20,20,40,.08); }

/* ---------------------------------------------------------------- banners */
.banner { border-radius: 12px; padding: 10px 14px; font-size: 13.5px; }
.banner.ok { background: var(--ok-weak); color: var(--ok); }
.banner.error { background: var(--danger-weak); color: var(--danger); }
.banner.warn { background: #f5efe1; color: #9a7b3f; }
#import-result { display: flex; flex-direction: column; gap: 14px; }
.add-circle:disabled { opacity: .4; cursor: default; }
.add-circle:disabled:hover { border-color: var(--border); color: var(--muted); background: transparent; }

/* -------------------------------------------------------------------- llm */
.llm-options { display: flex; gap: 14px; flex-wrap: wrap; }
.llm-options select { min-width: 240px; }

/* ---------------------------------------------------------------- модалки */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(20,20,40,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg); border-radius: 16px; box-shadow: var(--shadow);
  padding: 20px 22px; width: 100%; max-width: 440px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal h2 { font-size: 14px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }
.modal h2 svg.lucide { color: var(--accent); }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.check-row {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 400; color: var(--text);
}
.check-row input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
.num-input { width: 110px; }

/* ------------------------------------------------------ добавить в таблице */
.table-add { display: flex; justify-content: center; padding: 12px 0 16px; }
.add-circle {
  width: 36px; height: 36px; border-radius: 999px; border: 1px dashed var(--border);
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: 20px; line-height: 1;
}
.add-circle:hover { border-color: var(--accent); color: var(--accent-2); background: var(--accent-weak); }

/* ------------------------------------------------------------ уведомления */
.notif-wrap { position: relative; flex-shrink: 0; }
.notif-badge {
  position: absolute; top: 1px; right: 1px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 700; min-width: 15px; height: 15px;
  line-height: 15px; text-align: center; padding: 0 4px; pointer-events: none;
}
.notif-panel {
  position: absolute; right: 0; top: 42px; width: 340px; max-height: 420px;
  overflow-y: auto; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 80; padding: 6px;
}
.notif-item { display: flex; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px; }
.notif-item:hover { background: var(--panel); }
.notif-item .ndot { width: 8px; height: 8px; border-radius: 999px; margin-top: 5px; flex-shrink: 0; }
.ndot.ok { background: var(--ok); }
.ndot.error { background: var(--danger); }
.ndot.warn { background: #d9a545; }
.ndot.info { background: var(--accent); }
.ndot.running { background: var(--accent); animation: blink 1.4s infinite; }
.notif-item.live { background: var(--accent-weak); }
.notif-item.live .notif-text { color: var(--accent-2); font-weight: 600; }
#btn-bell.bell-running { color: var(--accent-2); background: var(--accent-weak); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.notif-text { line-height: 1.4; }
.notif-time { font-size: 11px; color: var(--muted); margin-top: 2px; }
.notif-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 13px; }

/* -------------------------------------------------------------- аналитика */
.pills-card { gap: 10px; }
.pill-row { display: flex; gap: 12px; align-items: flex-start; }
.pill-label {
  flex-shrink: 0; width: 110px; font-size: 12px; font-weight: 600;
  color: var(--muted); padding-top: 6px;
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  border-radius: 999px; padding: 5px 13px; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .12s ease, color .12s ease;
}
.pill:hover { background: var(--panel-2); color: var(--text); }
.pill.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-2); }
.chart-card { overflow: visible; }
.chart-box { position: relative; height: 340px; }
.series-list { display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; align-items: center; }
.add-series-row { display: flex; align-items: center; gap: 12px; }
.modal.modal-wide { max-width: 560px; }
.template-list { display: flex; flex-direction: column; max-height: 380px; overflow-y: auto; }
.template-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border-bottom: 1px solid var(--panel-2);
}
.template-row:last-child { border-bottom: none; }
.tpl-load { flex-shrink: 0; color: var(--accent-2); }
.tpl-load:hover { background: var(--accent-weak); color: var(--accent-2); }
.tpl-info { flex: 1; min-width: 0; }
.tpl-name { font-size: 14px; font-weight: 600; }
.template-row .icon.danger { flex-shrink: 0; font-size: 18px; }

/* комментарий и примеры под графиком */
.card textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.comment-actions { display: flex; align-items: center; gap: 12px; }
.comment-counter { margin-left: auto; }
.examples-controls { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.examples-controls .num-input { height: 34px; width: 80px; }
.series-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 10px 5px 12px; font-size: 13px; font-weight: 600;
  cursor: grab; position: relative;
}
.series-chip.dragging { opacity: .45; }
.series-chip.drop-target { border-color: var(--accent); background: var(--accent-weak); }
.series-chip.drop-before { box-shadow: -3px 0 0 0 var(--accent); }
.series-chip.drop-after { box-shadow: 3px 0 0 0 var(--accent); }
.series-chip .sdot {
  width: 12px; height: 12px; border-radius: 999px; flex-shrink: 0;
  cursor: pointer; border: 2px solid transparent; transition: box-shadow .12s ease;
}
.series-chip .sdot:hover { box-shadow: 0 0 0 3px var(--accent-weak); }
.color-menu {
  position: absolute; left: 0; top: calc(100% + 8px); z-index: 120; background: var(--bg);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px; display: grid; grid-template-columns: repeat(6, 22px); gap: 8px;
  cursor: default;
}
.color-swatch {
  width: 22px; height: 22px; border-radius: 999px; border: 2px solid transparent;
  cursor: pointer; padding: 0; transition: transform .1s ease;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.current { border-color: var(--text); }
.series-stack {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  border: 1px dashed var(--accent); border-radius: 14px; padding: 5px 8px;
  background: var(--accent-weak); cursor: grab;
}
.series-stack.dragging { opacity: .45; }
.series-stack.drop-target { border-style: solid; box-shadow: 0 0 0 3px var(--accent-weak); }
.series-stack.drop-before { box-shadow: -3px 0 0 0 var(--accent); }
.series-stack.drop-after { box-shadow: 3px 0 0 0 var(--accent); }
.stack-badge {
  font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent-2);
}

/* ------------------------------------------------------ отчёты (Аналитика) */
.report-actions { margin-left: auto; display: flex; gap: 4px; flex-shrink: 0; }
.report-add-row { display: flex; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; flex-wrap: wrap; }
.report-block { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.report-block h3 {
  margin: 0; font-size: 13px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.report-block h3 svg.lucide { width: 15px; height: 15px; color: var(--accent); }
.report-block .block-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.report-table-wrap { overflow-x: auto; margin: 0 -18px -16px; }
.report-name-pill { font-weight: 600; color: var(--accent-2); }

/* ------------------------------------------------------------- статистика */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.card.stat { gap: 4px; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent-2); }
.stat-label { font-size: 13px; color: var(--muted); }
.info-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .info-columns { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ pager */
.pager { display: flex; align-items: center; gap: 14px; justify-content: center; }

/* ------------------------------------------------------------------- вход */
.nav-bottom { margin-top: auto; }
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; background: var(--side-bg); padding: 20px;
}
.login-card {
  background: var(--bg); border-radius: 16px; box-shadow: var(--shadow);
  padding: 28px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 18px; font-weight: 800; letter-spacing: .18em; text-align: center; }
.login-sub { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); text-align: center; }

@media (max-width: 760px) {
  .sidebar { width: 62px; }
  .sidebar .brand { display: none; }
  .nav-item span { display: none; }
  .page-body { padding: 14px 12px 32px; }
  input, select, textarea { font-size: 16px; }
  .col-mp, .col-date { width: auto; }
}
