/* ==========================================================================
   Крос-ГЕО Сканер — дизайн-система
   Напрямок: щільний, професійний "термінал" для оператора, що весь день
   сканує цифри. Не маркетинговий лендінг — робочий інструмент.
   Сигнатурний елемент: "балансир" (balance beam) на картці ситуації —
   горизонтальна шкала, де ширина кожного сегмента = частка неявної
   ймовірності цього плеча (1/price), тобто буквально показує, наскільки
   плечі вилки "балансують" одне одного.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  /* --- Колір --- */
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #182029;
  --surface-3: #1e2833;
  --border: #212b36;
  --border-soft: #1a2229;

  --text: #e8edf3;
  --text-muted: #8b9bac;
  --text-faint: #52616f;

  --accent-blue: #5b8def;
  --accent-blue-dim: #2c3e5c;
  --accent-green: #2fbf83;
  --accent-green-dim: #14301f;
  --accent-red: #ff5c5c;
  --accent-red-dim: #3a1f22;
  --accent-amber: #f5a623;
  --accent-amber-dim: #3a2c14;

  /* --- Типографіка --- */
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

  /* --- Простір --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --sidebar-w: 236px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.input-inline {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text);
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.input-inline:focus { border-color: var(--accent-blue); outline: none; }

select {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text);
  padding: 8px 11px; border-radius: var(--radius-sm); font-size: 13px;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3e%3cpath d='M1 1l5 5 5-5' stroke='%238b93a1' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
}
select:focus { outline: none; border-color: var(--accent-blue); }
select option { background: var(--surface-2); color: var(--text); }

::selection { background: var(--accent-blue-dim); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

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

/* ==========================================================================
   Layout shell
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* --- Sidebar --- */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  padding: var(--sp-5) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-2);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
  flex-shrink: 0;
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 2px;
  background: var(--bg);
  clip-path: polygon(0 60%, 40% 60%, 55% 20%, 70% 80%, 100% 40%, 100% 100%, 0 100%);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
}

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0 var(--sp-3);
  margin-bottom: var(--sp-2);
  font-weight: 600;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent-blue);
}
.nav-item svg { flex-shrink: 0; opacity: 0.85; }
.nav-item .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 20px;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-3);
  border-top: 1px solid var(--border-soft);
  font-size: 11px;
  color: var(--text-faint);
}

/* --- Topbar --- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  position: sticky;
  top: 0;
  background: rgba(11, 15, 20, 0.9);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.topbar-sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: var(--sp-4); }

.live-dot-wrap { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 0 0 rgba(47,191,131,0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47,191,131,0.55); }
  70% { box-shadow: 0 0 0 6px rgba(47,191,131,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,191,131,0); }
}

.user-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 6px 10px 6px 6px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 999px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 11px; font-weight: 600; color: var(--text-muted);
}
.user-role-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-blue);
}

.content { padding: var(--sp-5); flex: 1; min-width: 0; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ==========================================================================
   Tabs (робоча стрічка оператора)
   ========================================================================== */

.tabs { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-5); border-bottom: 1px solid var(--border-soft); }
.tab {
  padding: var(--sp-3) var(--sp-4);
  font-size: 13.5px; font-weight: 500; color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent-blue); }
.tab .tab-count { margin-left: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }

.filter-bar {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-5); flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  background: var(--surface); border: 1px solid var(--border-soft); color: var(--text);
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: 12.5px;
}
.filter-bar .spacer { flex: 1; }

/* ==========================================================================
   Cards: ситуації (вилка / коридор / value)
   ========================================================================== */

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: var(--sp-4); }

.situation-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.situation-card:hover { border-color: var(--border); }
.situation-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--type-color, var(--accent-blue));
}

.situation-card.type-fork { --type-color: var(--accent-green); }
.situation-card.type-live { --type-color: var(--accent-red); }
.situation-card.type-corridor { --type-color: var(--accent-blue); }
.situation-card.type-value { --type-color: var(--accent-amber); }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.card-meta { font-size: 11.5px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.card-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-faint); }

.profit-badge {
  font-family: var(--font-mono); font-weight: 600; font-size: 15px;
  color: var(--accent-green);
  background: var(--accent-green-dim);
  padding: 3px 10px; border-radius: 999px;
  white-space: nowrap;
}
.profit-badge.small { font-size: 12px; padding: 2px 8px; }
.profit-badge.negative { color: var(--accent-red); background: var(--accent-red-dim); }

.card-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; margin-bottom: 2px; letter-spacing: -0.01em; }
.card-market-tag {
  display: inline-block; font-size: 10.5px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-soft);
  padding: 1px 7px; border-radius: 4px; margin-bottom: var(--sp-3);
}

.live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; color: var(--accent-red);
  background: var(--accent-red-dim); padding: 2px 8px; border-radius: 4px;
}
.live-badge .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-red); animation: pulse 1.6s infinite; }

/* --- Балансир (сигнатурний елемент) --- */
.beam {
  display: flex; height: 6px; border-radius: 4px; overflow: hidden;
  margin-bottom: var(--sp-3); background: var(--surface-3);
}
.beam-seg { height: 100%; }
.beam-seg:nth-child(1) { background: var(--accent-blue); }
.beam-seg:nth-child(2) { background: var(--accent-green); }
.beam-seg:nth-child(3) { background: var(--accent-amber); }

.legs { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); }
.leg-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 7px 9px; background: var(--surface-2); border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.leg-bk {
  width: 30px; height: 22px; border-radius: 4px; flex-shrink: 0;
  background: var(--surface-3); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600;
}
.leg-info { flex: 1; min-width: 0; }
.leg-brand { font-weight: 600; color: var(--text); }
.leg-geo { color: var(--text-faint); font-size: 11px; margin-left: 5px; }
.leg-selection { color: var(--text-muted); font-size: 11.5px; }
.leg-price { font-family: var(--font-mono); font-weight: 600; font-size: 14px; min-width: 48px; text-align: right; }
.leg-link {
  color: var(--accent-blue); font-size: 11px; font-weight: 500;
  padding: 4px 8px; border: 1px solid var(--accent-blue-dim); border-radius: 5px;
  flex-shrink: 0;
}
.leg-link:hover { background: var(--accent-blue-dim); }

.cross-geo-strip {
  border-top: 1px dashed var(--border-soft);
  padding-top: var(--sp-3); margin-top: 2px;
}
.cross-geo-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px; color: var(--accent-blue); font-weight: 600;
  margin-bottom: var(--sp-2);
}
.access-badge {
  font-size: 10px; color: var(--accent-amber); background: var(--accent-amber-dim);
  padding: 2px 7px; border-radius: 4px; font-weight: 500;
}

.corridor-meta { display: flex; gap: var(--sp-4); margin-bottom: var(--sp-3); font-size: 12px; }
.corridor-meta .label { color: var(--text-faint); display: block; font-size: 10.5px; }
.corridor-meta .val { font-family: var(--font-mono); font-weight: 600; font-size: 14px; }

.value-compare { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--sp-3); }
.value-compare-row { display: flex; align-items: center; gap: var(--sp-3); font-size: 12px; padding: 5px 0; }
.value-compare-row .bar-track { flex: 1; height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.value-compare-row .bar-fill { height: 100%; background: var(--text-faint); }
.value-compare-row.is-outlier .bar-fill { background: var(--accent-amber); }
.value-compare-row.is-outlier { color: var(--accent-amber); font-weight: 600; }

/* ==========================================================================
   Buttons, badges, forms
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; border: 1px solid var(--border-soft);
  background: var(--surface-2); color: var(--text);
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); color: #0b0f14; font-weight: 600; }
.btn-primary:hover { background: #6f9bf2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-5);
}
.page-header h1 { font-family: var(--font-display); font-size: 20px; margin: 0; font-weight: 600; }
.page-header p { color: var(--text-faint); font-size: 12.5px; margin: 4px 0 0; }

.panel {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: var(--sp-5);
}
.panel + .panel { margin-top: var(--sp-4); }
.panel-title { font-family: var(--font-display); font-size: 14px; font-weight: 600; margin: 0 0 var(--sp-4); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); font-weight: 600; padding: 0 var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--border-soft);
}
tbody td { padding: var(--sp-3); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num { font-family: var(--font-mono); }

.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
}
.status-pill.ok { color: var(--accent-green); background: var(--accent-green-dim); }
.status-pill.warn { color: var(--accent-amber); background: var(--accent-amber-dim); }
.status-pill.err { color: var(--accent-red); background: var(--accent-red-dim); }
.status-pill.off { color: var(--text-faint); background: var(--surface-3); }

.badge-role {
  font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-role.superadmin { color: var(--accent-red); background: var(--accent-red-dim); }
.badge-role.admin { color: var(--accent-blue); background: var(--accent-blue-dim); }
.badge-role.operator { color: var(--accent-green); background: var(--accent-green-dim); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-field .hint { font-size: 11px; color: var(--text-faint); }
.form-field input, .form-field select, .form-field textarea {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text);
  padding: 9px 11px; border-radius: var(--radius-sm); font-size: 13px;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--accent-blue);
}
.form-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-2); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--border-soft);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .toggle-label { font-size: 13px; font-weight: 500; }
.toggle-row .toggle-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px;
  transition: background 0.15s ease; cursor: pointer;
}
.switch .track::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: var(--text-muted); border-radius: 50%; transition: transform 0.15s ease, background 0.15s ease;
}
.switch input:checked + .track { background: var(--accent-green-dim); }
.switch input:checked + .track::before { transform: translateX(18px); background: var(--accent-green); }

/* ==========================================================================
   Dashboard
   ========================================================================== */

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); margin-bottom: var(--sp-4); }
.stat-card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
  padding: var(--sp-4);
}
.stat-card .stat-label { font-size: 11.5px; color: var(--text-faint); margin-bottom: 6px; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; }
.stat-card .stat-value.green { color: var(--accent-green); }
.stat-card .stat-value.red { color: var(--accent-red); }
.stat-card .stat-value.blue { color: var(--accent-blue); }
.stat-card .stat-value.amber { color: var(--accent-amber); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--sp-4); }

.hbar-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.hbar-row { display: grid; grid-template-columns: 90px 1fr 40px; align-items: center; gap: var(--sp-3); font-size: 12px; }
.hbar-row .track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.hbar-row .fill { height: 100%; background: var(--accent-blue); border-radius: 4px; }
.hbar-row .val { font-family: var(--font-mono); text-align: right; color: var(--text-muted); }

.vbars { display: flex; align-items: flex-end; gap: var(--sp-3); height: 160px; padding-top: var(--sp-3); }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 8px; }
.vbar-col .bar { width: 100%; background: linear-gradient(180deg, var(--accent-blue), var(--accent-blue-dim)); border-radius: 4px 4px 0 0; }
.vbar-col .lbl { font-size: 10px; color: var(--text-faint); }

/* ==========================================================================
   Login
   ========================================================================== */

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, #101823 0%, var(--bg) 60%);
}
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: var(--sp-6);
}
.login-card .brand { margin-bottom: var(--sp-6); justify-content: center; }
.login-card h1 { font-family: var(--font-display); font-size: 18px; text-align: center; margin: 0 0 var(--sp-1); }
.login-card p.sub { text-align: center; color: var(--text-faint); font-size: 12px; margin: 0 0 var(--sp-5); }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: var(--sp-2); }

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

.empty-state {
  text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-faint);
}
.empty-state .icon { font-size: 28px; margin-bottom: var(--sp-3); opacity: 0.5; }
.empty-state h3 { color: var(--text-muted); font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.empty-state p { font-size: 12.5px; margin: 0; }

@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
