/* ==========================================================================
   Design tokens
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #14161c;
  --surface: #1b1e26;
  --surface-raised: #21242e;
  --border: #2a2d38;
  --border-soft: #23262f;

  /* text */
  --text: #e8e9ee;
  --text-muted: #9a9dab;
  --text-faint: #666a78;

  /* accent — single, reserved for interactive/primary state */
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --accent-text: #8fb4ff;

  /* deviation scale — separate from accent, meaning: severity of plan/fact gap */
  --dev-neutral: #9a9dab;
  --dev-neutral-bg: rgba(154, 157, 171, 0.12);
  --dev-warning: #d9a441;
  --dev-warning-bg: rgba(217, 164, 65, 0.14);
  --dev-critical: #e2583e;
  --dev-critical-bg: rgba(226, 88, 62, 0.14);

  /* direction swatches — muted, distinguishable, decorative only (mirrors js/data.js colorAccent) */
  --dir-analytics: #6fb98f;
  --dir-backend: #c17a4a;
  --dir-frontend: #6f8fc4;
  --dir-qa: #a685c9;
  --dir-design: #d98a9e;
  --dir-devops: #4f9e93;

  /* type */
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --radius-s: 4px;
  --radius-m: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}

body { min-width: 1080px; }

a { color: inherit; text-decoration: none; }

.num, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Shell / layout
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: #0b1220;
  font-weight: 800;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 15px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}

.nav-item:hover { background: var(--surface-raised); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-item--disabled {
  color: var(--text-faint);
  cursor: default;
  font-size: 13px;
}

.nav-item--disabled:hover { background: none; color: var(--text-faint); }

.nav-roadmap {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.nav-roadmap-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0 10px 6px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border-soft);
}

.sidebar-footer-name { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.sidebar-footer-hint { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.main {
  padding: 28px 36px 60px;
  max-width: 1240px;
}

/* ==========================================================================
   Page header / toolbar
   ========================================================================== */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  max-width: 62ch;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 2px;
  flex-shrink: 0;
}

.segmented-option {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-ui);
}

.segmented-option.is-active {
  background: var(--accent);
  color: #0b1220;
}

.segmented-option:not(.is-active):hover { color: var(--text); }

/* ==========================================================================
   Summary callout — короткое текстовое объяснение "почему так вышло"
   ========================================================================== */

.summary-callout {
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 14px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 76ch;
  line-height: 1.55;
}

/* ==========================================================================
   Cards / sections
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 18px 20px;
}

.card + .card { margin-top: 16px; }

.card-title {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 2px;
}

.card-caption {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 0 0 14px;
}

.section-grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: 1.3fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ==========================================================================
   Metric hero (dominant number)
   ========================================================================== */

.metric-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 22px 24px;
  margin-bottom: 16px;
}

.metric-hero-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.metric-hero-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.metric-hero-value {
  font-family: var(--font-mono);
  font-size: 46px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-hero-unit {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-hero-caption {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px 16px;
}

.metric-tile-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.metric-tile-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
}

.metric-tile-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: 2px;
}

/* deviation-colored text */
.dev-neutral { color: var(--dev-neutral); }
.dev-warning { color: var(--dev-warning); }
.dev-critical { color: var(--dev-critical); }

/* ==========================================================================
   Badges / pills
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.badge-neutral { background: var(--dev-neutral-bg); color: var(--dev-neutral); }
.badge-warning { background: var(--dev-warning-bg); color: var(--dev-warning); }
.badge-critical { background: var(--dev-critical-bg); color: var(--dev-critical); }
.badge-info { background: var(--accent-soft); color: var(--accent-text); }

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

/* ==========================================================================
   Bar chart (horizontal, by direction)
   ========================================================================== */

.bar-chart { display: flex; flex-direction: column; gap: 10px; }

.bar-row {
  display: grid;
  grid-template-columns: 176px 1fr 64px;
  align-items: center;
  gap: 10px;
}

.bar-row-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  position: relative;
  height: 18px;
  background: var(--surface-raised);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  border-radius: 3px;
}

.bar-row-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

/* ==========================================================================
   Tables
   ========================================================================== */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: default;
  white-space: nowrap;
}

.data-table thead th.is-sortable { cursor: pointer; }
.data-table thead th.is-sortable:hover { color: var(--text-muted); }

.data-table tbody td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--surface-raised); }
.data-table tbody tr.is-clickable { cursor: pointer; }

.data-table td.num, .data-table th.num { text-align: right; font-family: var(--font-mono); }

.table-primary-cell { font-weight: 600; }
.table-secondary-cell { color: var(--text-muted); font-size: 12px; }

.table-note {
  font-weight: 400;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 3px;
  line-height: 1.4;
}

/* ==========================================================================
   Charts (SVG)
   ========================================================================== */

.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .axis-line { stroke: var(--border); stroke-width: 1; }
.chart-svg .grid-line { stroke: var(--border-soft); stroke-width: 1; }
.chart-svg .axis-label { fill: var(--text-faint); font-size: 10.5px; font-family: var(--font-mono); }
.chart-svg .plan-line { stroke: var(--text-faint); stroke-width: 1.5; stroke-dasharray: 4 3; fill: none; }
.chart-svg .actual-line { stroke: var(--accent); stroke-width: 2; fill: none; }
.chart-svg .trend-line { stroke: var(--accent); stroke-width: 2; fill: none; }
.chart-svg .zone-warning { fill: var(--dev-warning-bg); }
.chart-svg .zone-critical { fill: var(--dev-critical-bg); }
.chart-svg .point { fill: var(--bg); stroke-width: 2; }

/* ==========================================================================
   Risk cards
   ========================================================================== */

.risk-card {
  background: var(--surface);
  border: 1px solid var(--dev-critical);
  border-left-width: 3px;
  border-radius: var(--radius-m);
  padding: 14px 16px;
}

.risk-card + .risk-card { margin-top: 10px; }

.risk-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.risk-card-title { font-size: 13.5px; font-weight: 700; }
.risk-card-client { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.risk-card-explain {
  font-size: 12.5px;
  color: var(--text-muted);
}

.risk-card-explain .num { color: var(--text); font-weight: 600; }

/* ==========================================================================
   Tabs (direction switcher)
   ========================================================================== */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field select,
.form-field input[type="number"],
.form-field input[type="text"] {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  color: var(--text);
  padding: 9px 10px;
  font-size: 13.5px;
  font-family: var(--font-ui);
}

.form-field input[type="number"] { font-family: var(--font-mono); }

.form-field select:focus,
.form-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-pill:has(input:checked) {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}

.checkbox-pill input {
  accent-color: var(--accent);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-s);
  font-size: 13.5px;
  font-weight: 700;
  font-family: var(--font-ui);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
}

.btn-primary:hover { filter: brightness(1.08); }

/* ==========================================================================
   Explainability tooltip
   ========================================================================== */

[data-explain] {
  border-bottom: 1px dotted var(--text-faint);
  cursor: help;
}

.tooltip-popover {
  position: fixed;
  z-index: 60;
  max-width: 300px;
  background: #0e1015;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.1s ease, transform 0.1s ease;
}

.tooltip-popover.is-visible { opacity: 1; transform: translateY(0); }

.tooltip-popover-formula {
  font-family: var(--font-mono);
  color: var(--accent-text);
  margin-bottom: 4px;
}

.tooltip-popover-sample {
  color: var(--text-faint);
  margin-top: 4px;
}

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Utility
   ========================================================================== */

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.mt-16 { margin-top: 16px; }
