/* ============================================================
   MXControl - app.css
   Design tokens + base + component library
   Family backbone: slate skeleton. Brand: cobalt.
   ============================================================ */

:root {
  /* ---- Cobalt (primary / control + signal) ---- */
  --cobalt-50:  #eff6ff;
  --cobalt-100: #dbeafe;
  --cobalt-200: #bfdbfe;
  --cobalt-300: #93c5fd;
  --cobalt-400: #60a5fa;
  --cobalt-500: #3b82f6;
  --cobalt-600: #2563eb;
  --cobalt-700: #1d4ed8;
  --cobalt-800: #1e40af;
  --cobalt-900: #1e3a8a;
  --brand-grad: linear-gradient(150deg, #3b82f6, #1e40af);

  /* ---- Slate skeleton (family backbone) ---- */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* ---- Surfaces ---- */
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --ink:       #1e293b;
  --ink-soft:  #475569;
  --ink-mute:  #64748b;
  --border:    #e2e8f0;
  --border-2:  #cbd5e1;

  /* ---- Semantic (1:1 with family) ---- */
  --red:    #dc2626;  --red-bg:    #fef2f2;  --red-bd:    #fecaca;
  --amber:  #b45309;  --amber-bg:  #fffbeb;  --amber-bd:  #fde68a;
  --green:  #15803d;  --green-bg:  #f0fdf4;  --green-bd:  #bbf7d0;
  --cyan:   #0891b2;  --cyan-bg:   #ecfeff;  --cyan-bd:   #a5f3fc;
  --violet: #7c3aed;  --violet-bg: #f5f3ff;  --violet-bd: #ddd6fe;
  --gray:   #64748b;  --gray-bg:   #f1f5f9;  --gray-bd:   #e2e8f0;

  /* ---- Shadows ---- */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.05);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 28px rgba(15,23,42,.12), 0 4px 10px rgba(15,23,42,.06);
  --shadow-xl: 0 24px 60px rgba(2,6,23,.45), 0 8px 24px rgba(2,6,23,.30);

  /* ---- Geometry ---- */
  --sidebar: 248px;
  --sidebar-compact: 72px;
  --topbar-h: 60px;
  --radius-sm: 7px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* ---- Type ---- */
  --font: 'Golos Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
::selection { background: var(--cobalt-200); }

:focus-visible {
  outline: 2px solid var(--cobalt-500);
  outline-offset: 2px;
  border-radius: 4px;
}

.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }
.tnum { font-variant-numeric: tabular-nums; }

/* skip link */
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 999;
  background: var(--cobalt-700); color: #fff; padding: 8px 14px;
  border-radius: var(--radius-sm); font-weight: 600; transition: top .15s var(--ease);
}
.skip-link:focus { top: 12px; }

/* ============================================================
   Section label
   ============================================================ */
.eyebrow, .section-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-mute);
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card-link {
  transition: box-shadow .16s var(--ease), transform .16s var(--ease), border-color .16s var(--ease);
  cursor: pointer;
}
.card-link:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--cobalt-200); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.card-head .sub { font-size: 12px; color: var(--ink-mute); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--ink);
  transition: background .14s var(--ease), border-color .14s var(--ease), box-shadow .14s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--slate-400); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; gap: 6px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; }

.btn-primary {
  background: var(--brand-grad); color: #fff; border: none;
  box-shadow: 0 2px 6px rgba(29,78,216,.30);
}
.btn-primary:hover { background: var(--brand-grad); border-color: transparent; box-shadow: 0 4px 14px rgba(29,78,216,.40); filter: brightness(1.06); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--slate-100); border-color: transparent; }

.btn-call { background: var(--brand-grad); color:#fff; border:none; box-shadow: 0 2px 6px rgba(29,78,216,.28); }
.btn-call:hover { box-shadow: 0 4px 14px rgba(29,78,216,.40); }

.btn-green { background: var(--green); color: #fff; border: none; }
.btn-green:hover { filter: brightness(1.06); }
.btn-danger-ghost { color: var(--red); border-color: var(--red-bd); background: var(--red-bg); }
.btn-danger-ghost:hover { background: #fee2e2; }
.btn-green-ghost { color: var(--green); border-color: var(--green-bd); background: var(--green-bg); }
.btn-green-ghost:hover { background: #dcfce7; }

.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  border: 1px solid transparent; color: var(--ink-soft); position: relative;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.icon-btn:hover { background: var(--slate-100); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }

/* ============================================================
   Badges / chips
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: var(--radius-sm);
  font-size: 11.5px; font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid var(--gray-bd); background: var(--gray-bg); color: var(--ink-soft);
}
.badge svg { width: 13px; height: 13px; }
.badge.red    { color: var(--red);    background: var(--red-bg);    border-color: var(--red-bd); }
.badge.amber  { color: var(--amber);  background: var(--amber-bg);  border-color: var(--amber-bd); }
.badge.green  { color: var(--green);  background: var(--green-bg);  border-color: var(--green-bd); }
.badge.cyan   { color: var(--cyan);   background: var(--cyan-bg);   border-color: var(--cyan-bd); }
.badge.violet { color: var(--violet); background: var(--violet-bg); border-color: var(--violet-bd); }
.badge.cobalt { color: var(--cobalt-700); background: var(--cobalt-50); border-color: var(--cobalt-200); }
.badge.gray   { color: var(--gray);   background: var(--gray-bg);   border-color: var(--gray-bd); }
.badge.solid-cobalt { background: var(--brand-grad); color:#fff; border:none; }

/* dot before badge text */
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* outcome chip */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 10px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2);
}
.chip.up   { color: var(--green); background: var(--green-bg); border-color: var(--green-bd); }
.chip.down { color: var(--red);   background: var(--red-bg);   border-color: var(--red-bd); }
.chip.warn { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-bd); }
.chip.neutral { color: var(--ink-soft); }

/* timer chip - lives, reddens */
.timer {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  height: 26px; padding: 0 10px; border-radius: var(--radius-sm);
  background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bd);
}
.timer.hot { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.timer.cool { background: var(--surface-2); color: var(--ink-soft); border-color: var(--border); }

/* ============================================================
   Avatar (deterministic color from palette)
   ============================================================ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  font-size: 12px; font-weight: 700; color: #fff;
  font-family: var(--font); letter-spacing: .01em;
}
.avatar.lg { width: 46px; height: 46px; font-size: 16px; border-radius: 12px; }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; border-radius: 7px; }
.av-c0 { background: linear-gradient(135deg,#3b82f6,#1e40af); }
.av-c1 { background: linear-gradient(135deg,#0891b2,#0e7490); }
.av-c2 { background: linear-gradient(135deg,#7c3aed,#5b21b6); }
.av-c3 { background: linear-gradient(135deg,#15803d,#166534); }
.av-c4 { background: linear-gradient(135deg,#b45309,#92400e); }
.av-c5 { background: linear-gradient(135deg,#db2777,#9d174d); }
.av-c6 { background: linear-gradient(135deg,#475569,#1e293b); }

/* ============================================================
   Direction icon (in / out)
   ============================================================ */
.dir {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; flex: none;
}
.dir svg { width: 16px; height: 16px; }
.dir.in  { background: var(--cyan-bg);   color: var(--cyan);   border: 1px solid var(--cyan-bd); }
.dir.out { background: var(--violet-bg); color: var(--violet); border: 1px solid var(--violet-bd); }

/* ============================================================
   KPI tile
   ============================================================ */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.kpi .kpi-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-mute);
  display: flex; align-items: center; gap: 7px;
}
.kpi .kpi-label svg { width: 14px; height: 14px; color: var(--slate-400); }
.kpi .kpi-value {
  font-family: var(--mono); font-size: 30px; font-weight: 700;
  letter-spacing: -.02em; line-height: 1.05; color: var(--slate-900);
}
.kpi .kpi-value .unit { font-size: 15px; color: var(--ink-mute); font-weight: 500; }
.kpi .kpi-sub { font-size: 12px; color: var(--ink-mute); display: flex; align-items: center; gap: 6px; }
.kpi .trend { display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.kpi .trend svg { width: 13px; height: 13px; }
.kpi .trend.up { color: var(--green); }
.kpi .trend.down { color: var(--red); }
.kpi .trend.flat { color: var(--ink-mute); }
/* Цвят по СМИСЪЛ (не по посока): спад на "Средно чакане/Изпуснати" е добър -> зелено. */
.kpi .trend.good { color: var(--green); }
.kpi .trend.bad { color: var(--red); }
.kpi.accent-top::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--brand-grad);
}

/* ============================================================
   Confidence bar
   ============================================================ */
.conf { display: flex; align-items: center; gap: 8px; }
.conf .track { flex: 1; height: 5px; border-radius: 999px; background: var(--slate-200); overflow: hidden; min-width: 60px; }
.conf .fill { height: 100%; border-radius: 999px; background: var(--brand-grad); }
.conf .val { font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--ink-soft); }

/* ============================================================
   Quote block (italic + left bar)
   ============================================================ */
.quote {
  font-style: italic; color: var(--ink-soft); font-size: 13px; line-height: 1.55;
  padding: 2px 0 2px 12px; border-left: 3px solid var(--slate-300);
}
.quote.red    { border-color: var(--red); }
.quote.amber  { border-color: var(--amber); }
.quote.violet { border-color: var(--violet); }
.quote.cyan   { border-color: var(--cyan); }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  text-align: left; padding: 10px 14px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-mute);
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
table.data thead th.num { text-align: right; }
table.data tbody td { padding: 11px 14px; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.data tbody td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data tbody tr { transition: background .12s var(--ease); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--cobalt-50); }
table.data tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   Pagebar / filter bar
   ============================================================ */
.pagebar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.field { display: inline-flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-mute); }
.control {
  height: 36px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border-2);
  background: var(--surface); font-size: 13px; color: var(--ink); min-width: 120px;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.control:hover { border-color: var(--slate-400); }
.control:focus { outline: none; border-color: var(--cobalt-500); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
textarea.control { height: auto; min-height: 80px; padding: 9px 12px; line-height: 1.5; width: 100%; resize: vertical; }
select.control { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' 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 10px center; padding-right: 30px; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--slate-400); pointer-events: none; }
.search-field .control { padding-left: 34px; min-width: 180px; }

/* segmented (period selector / tabs) */
.segment {
  display: inline-flex; padding: 3px; gap: 2px; background: var(--slate-100);
  border: 1px solid var(--border); border-radius: var(--radius); 
}
.segment button {
  height: 30px; padding: 0 14px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-soft); transition: background .14s var(--ease), color .14s var(--ease), box-shadow .14s var(--ease);
}
.segment button:hover { color: var(--ink); }
.segment button.active { background: var(--surface); color: var(--cobalt-700); box-shadow: var(--shadow-xs); }

/* tabs (pagebar tabs with counters) */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius); font-size: 13px; font-weight: 600; color: var(--ink-soft);
  border: 1px solid transparent; transition: background .14s var(--ease), color .14s var(--ease);
}
.tab:hover { background: var(--slate-100); color: var(--ink); }
.tab.active { background: var(--cobalt-50); color: var(--cobalt-700); border-color: var(--cobalt-200); }
.tab .count {
  font-family: var(--mono); font-size: 11px; font-weight: 700; min-width: 20px; height: 18px;
  padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--slate-200); color: var(--ink-soft);
}
.tab.active .count { background: var(--cobalt-600); color: #fff; }
.tab .count.amber { background: var(--amber-bg); color: var(--amber); }
.tab .count.red { background: var(--red); color: #fff; }

/* ============================================================
   Empty / loading states
   ============================================================ */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 48px 24px; gap: 12px; color: var(--ink-mute);
}
.empty-state .ico {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bd);
}
.empty-state .ico svg { width: 26px; height: 26px; }
.empty-state h4 { font-size: 15px; color: var(--ink); font-weight: 700; }
.empty-state p { font-size: 13px; max-width: 320px; }

.skeleton { background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-200) 37%, var(--slate-100) 63%);
  background-size: 400% 100%; border-radius: 6px; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ============================================================
   Toast (quiet, bottom-right)
   ============================================================ */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; min-width: 240px;
  background: var(--slate-900); color: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 500; animation: toast-in .2s var(--ease);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.ok svg { color: #4ade80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Utility
   ============================================================ */
.row { display: flex; align-items: center; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .gap-12 { gap: 12px; } .gap-14 { gap: 14px; } .gap-16 { gap: 16px; } .gap-18 { gap: 18px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.mt-4{margin-top:4px;} .mt-8{margin-top:8px;} .mt-12{margin-top:12px;} .mt-16{margin-top:16px;} .mt-20{margin-top:20px;} .mt-24{margin-top:24px;}
.muted { color: var(--ink-mute); }
.soft { color: var(--ink-soft); }
.strong { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.t-xs { font-size: 11.5px; } .t-sm { font-size: 12.5px; } .t-lg { font-size: 16px; }
.hide { display: none !important; }

/* pulse: only for critical unreturned signal */
.pulse-dot { position: relative; }
.pulse-dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--red); animation: pulse 1.8s var(--ease) infinite;
}
@keyframes pulse { 0% { opacity: .7; transform: scale(.8); } 70%,100% { opacity: 0; transform: scale(1.5); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Reason modal (Черен списък / Отписване) */
.mx-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.mx-modal[hidden] { display: none; }
.mx-modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(2px); }
.mx-modal-card { position: relative; width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 20px 22px 18px; animation: mxModalIn .16s var(--ease); }
.mx-modal-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.mx-modal-msg { margin: 0 0 14px; font-size: 13px; line-height: 1.5; }
.mx-modal .field { display: flex; width: 100%; margin-bottom: 12px; }
.mx-modal .control { width: 100%; }
.btn-danger { color: #fff; background: var(--red); border-color: var(--red); }
.btn-danger:hover { filter: brightness(.94); }
@keyframes mxModalIn { from { opacity: 0; transform: translateY(6px) scale(.99); } to { opacity: 1; transform: none; } }
