/* ==========================================================================
   Energo CRM — design system
   Tokens on :root, dark theme via [data-theme="dark"] (or system preference).
   ========================================================================== */

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;

  --primary: #0f766e;
  --primary-hover: #0d5f59;
  --primary-soft: #e6f4f2;
  --primary-text: #0f766e;
  --accent: #f59e0b;
  --accent-soft: #fef3c7;
  --focus: rgba(15, 118, 110, .28);

  --green: #15803d;  --green-soft: #dcfce7;
  --blue: #1d4ed8;   --blue-soft: #dbeafe;
  --amber: #b45309;  --amber-soft: #fef3c7;
  --red: #b91c1c;    --red-soft: #fee2e2;
  --purple: #7e22ce; --purple-soft: #f3e8ff;
  --teal: #0f766e;   --teal-soft: #ccfbf1;
  --gray: #475569;   --gray-soft: #f1f5f9;

  --sidebar-bg: #0b1324;
  --sidebar-text: #aab4c5;
  --sidebar-text-strong: #ffffff;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: rgba(45, 212, 191, .14);
  --sidebar-active-text: #5eead4;
  --sidebar-border: rgba(255,255,255,.07);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px -8px rgba(15, 23, 42, .18), 0 4px 8px -4px rgba(15, 23, 42, .08);

  --sidebar-w: 256px;
  --topbar-h: 60px;
  color-scheme: light;
}

/* The theme is resolved before first paint (stored choice, else system preference) and set as data-theme. */
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --surface-3: #1e293b;
  --border: #1f2a3c;
  --border-strong: #334155;
  --text: #e5e9f0;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --faint: #64748b;
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: rgba(20, 184, 166, .14);
  --primary-text: #5eead4;
  --focus: rgba(45, 212, 191, .35);
  --green: #4ade80;  --green-soft: rgba(74, 222, 128, .12);
  --blue: #60a5fa;   --blue-soft: rgba(96, 165, 250, .14);
  --amber: #fbbf24;  --amber-soft: rgba(251, 191, 36, .14);
  --red: #f87171;    --red-soft: rgba(248, 113, 113, .14);
  --purple: #c084fc; --purple-soft: rgba(192, 132, 252, .14);
  --teal: #2dd4bf;   --teal-soft: rgba(45, 212, 191, .14);
  --gray: #cbd5e1;   --gray-soft: rgba(148, 163, 184, .14);
  --accent-soft: rgba(245, 158, 11, .15);
  --sidebar-bg: #070d1a;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 16px 40px -8px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
}
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; } h4 { font-size: 13px; }
p { margin: 0 0 .75em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; border-right: 1px solid var(--sidebar-border); scrollbar-width: thin; scrollbar-color: #233049 transparent;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; color: var(--sidebar-text-strong); font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, #14b8a6, #0f766e); box-shadow: 0 4px 14px -4px rgba(20,184,166,.6); }
.brand-mark svg { width: 18px; height: 18px; fill: #fde68a; stroke: none; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--sidebar-text); letter-spacing: .02em; }
.nav { padding: 6px 10px 20px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group-label { padding: 0 10px 6px; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #6b7a93; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--sidebar-text);
  font-weight: 500; font-size: 13.5px; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: var(--sidebar-active-text); }
.nav a .icon { width: 17px; height: 17px; opacity: .9; }
.nav .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.08); padding: 1px 7px; border-radius: 99px; }
.sidebar-footer { padding: 12px 18px; border-top: 1px solid var(--sidebar-border); font-size: 11.5px; color: #6b7a93; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.search-trigger {
  display: flex; align-items: center; gap: 8px; width: min(440px, 100%); height: 36px; padding: 0 10px 0 12px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--muted); cursor: pointer; font: inherit; text-align: left;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger span { flex: 1; }
kbd { font-family: var(--font); font-size: 11px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; color: var(--muted); background: var(--surface); }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); border: 2px solid var(--surface); }
.menu-toggle { display: none; }
.content { padding: 24px; width: 100%; max-width: 1480px; margin: 0 auto; }

.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--primary-soft); color: var(--primary-text); font-size: 12px; font-weight: 650;
}
.avatar-lg { width: 52px; height: 52px; font-size: 18px; border-radius: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.user-chip:hover { border-color: var(--border-strong); }
.user-chip .name { font-weight: 550; font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .titles { min-width: 0; }
.page-header p.sub { margin: 4px 0 0; color: var(--muted); }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs .sep { color: var(--faint); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; font-size: 13.5px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, box-shadow .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
:root[data-theme="dark"] .btn-primary { color: #04201d; }
.btn-danger { background: var(--surface); color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--border)); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; gap: 4px; }
.btn-icon { width: 36px; padding: 0; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 9px 0 0 9px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 9px 9px 0; }
.btn-group .btn.active { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary); z-index: 1; }
form.inline { display: inline; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header h2, .card-header h3 { font-size: 14.5px; }
.card-header .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card + .card { margin-top: 16px; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.grid-side-main { grid-template-columns: 320px minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0 } .mt-1 { margin-top: 8px } .mt-2 { margin-top: 16px } .mt-3 { margin-top: 24px }
.mb-0 { margin-bottom: 0 } .mb-1 { margin-bottom: 8px } .mb-2 { margin-bottom: 16px } .mb-3 { margin-bottom: 24px }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; } .xs { font-size: 11.5px; }
.strong { font-weight: 600; } .nowrap { white-space: nowrap; } .right { text-align: right; } .center { text-align: center; }
.text-green { color: var(--green); } .text-red { color: var(--red); } .text-amber { color: var(--amber); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); }
.kpi-icon .icon { width: 16px; height: 16px; }
.kpi-icon.amber { background: var(--amber-soft); color: var(--amber); }
.kpi-icon.blue { background: var(--blue-soft); color: var(--blue); }
.kpi-icon.red { background: var(--red-soft); color: var(--red); }
.kpi-icon.purple { background: var(--purple-soft); color: var(--purple); }
.kpi-icon.green { background: var(--green-soft); color: var(--green); }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi a.stretched::after { content: ""; position: absolute; inset: 0; }
.delta-up { color: var(--green); } .delta-down { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
.table th:first-child { border-top-left-radius: var(--radius-lg); } .table th:last-child { border-top-right-radius: var(--radius-lg); }
.card-body.tight .table th { border-radius: 0; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table .sort-link { color: inherit; }
.table td.actions-cell { text-align: right; white-space: nowrap; width: 1%; }
.table-sm td { padding: 7px 12px; } .table-sm th { padding: 8px 12px; }
.table tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
.cell-title { font-weight: 560; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); }
a.cell-title:hover { color: var(--primary-text); }
.table-empty { padding: 48px 20px !important; text-align: center; color: var(--muted); }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.filters .input, .filters select.input { height: 34px; width: auto; min-width: 150px; }
.filters .search-input { flex: 1; min-width: 220px; position: relative; }
.filters .search-input .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; }
.filters .search-input .input { width: 100%; padding-left: 34px; }
.tabs-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs-pills a { padding: 5px 11px; border-radius: 99px; color: var(--muted); font-weight: 550; font-size: 13px; }
.tabs-pills a:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.tabs-pills a.active { background: var(--primary-soft); color: var(--primary-text); }
.tabs-pills .n { font-size: 11px; opacity: .8; margin-left: 3px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 4px; }
.pagination a, .pagination span.page { min-width: 32px; height: 32px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); }
.pagination a:hover { text-decoration: none; border-color: var(--border-strong); }
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .disabled { opacity: .45; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 580; white-space: nowrap; background: var(--gray-soft); color: var(--gray); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-teal { background: var(--teal-soft); color: var(--teal); }
.badge-gray { background: var(--gray-soft); color: var(--gray); }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11.5px; font-weight: 550; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.priority-critical { color: var(--red); font-weight: 650; } .priority-high { color: var(--amber); font-weight: 600; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-1 { grid-column: span 1; } .form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; } .form-grid .span-4 { grid-column: 1 / -1; }
.form-section { padding: 20px; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section-title { font-size: 13.5px; font-weight: 650; margin-bottom: 4px; }
.form-section-desc { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12.5px; font-weight: 580; color: var(--text-2); }
.req { color: var(--red); }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; transition: border-color .12s, box-shadow .12s; min-width: 0;
}
:root[data-theme="dark"] .input { border-color: var(--border-strong); background: var(--surface-2); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select.input { padding-right: 32px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
select.input[multiple] { height: auto; min-height: 100px; padding: 6px; background-image: none; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.input:disabled, .input[readonly] { background: var(--surface-3); color: var(--muted); }
.input.is-invalid { border-color: var(--red); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px var(--red-soft); }
.field-help { margin: 0; font-size: 12px; color: var(--muted); }
.field-error { margin: 0; font-size: 12px; color: var(--red); font-weight: 550; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0; flex: 1; }
.input-group .input:first-child { border-radius: 9px 0 0 9px; }
.input-group .input:last-child { border-radius: 0 9px 9px 0; }
.input-affix { display: grid; place-items: center; padding: 0 11px; border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--muted); font-size: 13px; }
.input-group .input-affix:first-child { border-radius: 9px 0 0 9px; border-right: 0; }
.input-group .input-affix:last-child { border-radius: 0 9px 9px 0; border-left: 0; }
.field-check { justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 500; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); margin: 0; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.radio-card { position: relative; border: 1px solid var(--border-strong); border-radius: 11px; padding: 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); background: var(--primary-soft); }
.radio-card .rc-title { font-weight: 600; }
.radio-card .rc-desc { font-size: 12px; color: var(--muted); }

/* ---------- Alerts / flash ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 11px; border: 1px solid; margin-bottom: 16px; font-size: 13.5px; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 30%, transparent); color: var(--green); }
.alert-error { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 30%, transparent); color: var(--red); }
.alert-warning { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); color: var(--amber); }
.alert-info { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 30%, transparent); color: var(--blue); }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .7; padding: 0; }
.alert-body { color: var(--text-2); }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toasts .alert { box-shadow: var(--shadow-lg); margin: 0; background: var(--surface); animation: toast-in .25s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 560; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs a.active, .tabs button.active { color: var(--primary-text); border-bottom-color: var(--primary); }
.tabs .n { font-size: 11px; background: var(--surface-3); color: var(--muted); border-radius: 99px; padding: 0 7px; }
.tab-panel { display: none; } .tab-panel.active { display: block; }

/* ---------- Description list ---------- */
.dl { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 9px 14px; margin: 0; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 520; min-width: 0; overflow-wrap: anywhere; }
.dl-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 24px; }
.dl-cols .item .k { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.dl-cols .item .v { font-weight: 560; overflow-wrap: anywhere; }

/* ---------- Entity hero (360 header) ---------- */
.hero { display: flex; gap: 16px; align-items: center; padding: 20px; flex-wrap: wrap; }
.hero .meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 4px; }
.hero .meta span { display: inline-flex; align-items: center; gap: 5px; }
.hero-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-top: 1px solid var(--border); }
.hero-stat { padding: 14px 20px; border-right: 1px solid var(--border); }
.hero-stat:last-child { border-right: 0; }
.hero-stat .k { font-size: 12px; color: var(--muted); }
.hero-stat .v { font-size: 18px; font-weight: 680; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 16px 28px; }
.timeline li::before { content: ""; position: absolute; left: 8px; top: 20px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .t-dot { position: absolute; left: 0; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); display: grid; place-items: center; }
.timeline .t-dot.primary { border-color: var(--primary); background: var(--primary-soft); }
.timeline .t-title { font-weight: 560; }
.timeline .t-meta { font-size: 12px; color: var(--muted); }
.timeline .t-body { margin-top: 4px; color: var(--text-2); white-space: pre-line; }

/* ---------- Stepper (lifecycle) ---------- */
.stepper { display: flex; gap: 0; overflow-x: auto; padding: 4px 0; }
.step { flex: 1; min-width: 110px; position: relative; text-align: center; font-size: 12px; color: var(--muted); padding-top: 28px; }
.step::before { content: ""; position: absolute; top: 10px; left: -50%; right: 50%; height: 2px; background: var(--border); }
.step:first-child::before { display: none; }
.step .s-dot { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); z-index: 1; }
.step.done { color: var(--text-2); } .step.done .s-dot { background: var(--primary); border-color: var(--primary); }
.step.done::before, .step.current::before { background: var(--primary); }
.step.current { color: var(--primary-text); font-weight: 650; }
.step.current .s-dot { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.step.failed .s-dot { border-color: var(--red); background: var(--red); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.kanban-col { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column; max-height: calc(100vh - 210px); }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-weight: 650; font-size: 13px; }
.kanban-col-head .sum { font-weight: 500; color: var(--muted); font-size: 12px; }
.kanban-cards { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; }
.kanban-cards.drag-over { background: var(--primary-soft); border-radius: 10px; }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; box-shadow: var(--shadow-sm); cursor: grab; }
.kanban-card:hover { border-color: var(--border-strong); }
.kanban-card.dragging { opacity: .5; }
.kanban-card .kc-title { font-weight: 600; font-size: 13.5px; }
.kanban-card .kc-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Dropdown / popover ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 220px; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); display: none;
}
.dropdown.open .dropdown-menu { display: block; animation: pop .12s ease-out; }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 8px; color: var(--text); font: inherit; font-size: 13.5px; background: none; border: 0; text-align: left; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-3); text-decoration: none; }
.dropdown-menu .sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-menu .head { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.dropdown-menu .danger { color: var(--red); }
.notif-menu { width: 360px; max-height: 440px; overflow-y: auto; }
.notif-item { display: block; padding: 10px; border-radius: 8px; }
.notif-item.unread { background: var(--primary-soft); }
.notif-item .t { font-weight: 600; font-size: 13px; color: var(--text); }
.notif-item .b { font-size: 12.5px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(2, 6, 23, .5); backdrop-filter: blur(2px); display: none; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto; }
.modal-backdrop.open { display: flex; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 560px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-lg { max-width: 820px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }

/* ---------- Command palette ---------- */
.palette { max-width: 640px; overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.palette-input input { flex: 1; border: 0; outline: 0; background: none; font: inherit; font-size: 16px; color: var(--text); }
.palette-results { max-height: 420px; overflow-y: auto; padding: 6px; }
.palette-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; color: var(--text); }
.palette-item:hover, .palette-item.active { background: var(--primary-soft); text-decoration: none; }
.palette-item .pi-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-3); display: grid; place-items: center; color: var(--muted); }
.palette-item .pi-title { font-weight: 560; }
.palette-item .pi-sub { font-size: 12px; color: var(--muted); }
.palette-empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .empty-icon { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); color: var(--faint); }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* ---------- Charts (inline SVG) ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--primary); }
.chart .bar:hover { opacity: .8; }
.chart .bar-2 { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--primary); opacity: .1; }
.chart .dot { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.progress.amber > span { background: var(--accent); } .progress.red > span { background: var(--red); }
.bars-list { display: flex; flex-direction: column; gap: 12px; }
.bars-list .bl-row .bl-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }

/* ---------- Auth pages ---------- */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-aside {
  position: relative; overflow: hidden; color: #e2e8f0; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at 10% 10%, rgba(20,184,166,.28), transparent 60%), radial-gradient(800px 500px at 90% 90%, rgba(245,158,11,.18), transparent 60%), #0b1324;
}
.auth-aside h2 { font-size: 32px; line-height: 1.15; color: #fff; max-width: 460px; letter-spacing: -.02em; }
.auth-aside p { color: #94a3b8; max-width: 440px; font-size: 15px; }
.auth-aside .features { display: grid; gap: 14px; margin-top: 28px; }
.auth-aside .feature { display: flex; gap: 12px; align-items: flex-start; color: #cbd5e1; }
.auth-aside .feature .icon { color: #5eead4; margin-top: 2px; }
.auth-main { display: grid; place-items: center; padding: 32px; background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 26px; }
.auth-card .field { margin-bottom: 16px; }
.auth-lang { position: absolute; top: 20px; right: 24px; }
.otp-input { letter-spacing: .5em; text-align: center; font-size: 22px !important; height: 52px !important; font-family: var(--mono); }
.qr-box { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 12px; border: 1px solid var(--border); width: fit-content; }
.secret-box { font-family: var(--mono); font-size: 15px; letter-spacing: .12em; padding: 10px 14px; background: var(--surface-3); border-radius: 9px; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: var(--mono); font-size: 14px; }
.codes span { padding: 6px 10px; background: var(--surface-3); border-radius: 7px; text-align: center; }

/* ---------- Error page ---------- */
.error-page { min-height: 70vh; display: grid; place-items: center; text-align: center; padding: 40px; }
.error-code { font-size: 72px; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-trace { text-align: left; max-width: 1000px; overflow: auto; background: var(--surface-3); padding: 16px; border-radius: 10px; font-size: 12px; margin-top: 20px; }

/* ---------- Matrix (permissions) ---------- */
.matrix th.rot { height: 140px; white-space: nowrap; vertical-align: bottom; padding: 8px 4px; }
.matrix th.rot > div { transform: rotate(-55deg); width: 26px; transform-origin: 14px 0; font-size: 11px; text-transform: none; letter-spacing: 0; }
.matrix td.c { text-align: center; padding: 6px 4px; }
.matrix input { width: 16px; height: 16px; accent-color: var(--primary); }
.matrix .module-row td { background: var(--surface-3); font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---------- Invoice document ---------- */
.doc-paper { background: #fff; color: #0f172a; max-width: 860px; margin: 0 auto; padding: 48px; border-radius: 8px; box-shadow: var(--shadow-lg); }
.doc-paper .table th { background: #f8fafc; color: #475569; }
.doc-paper .table td { border-color: #e2e8f0; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .grid-main-side, .grid-side-main { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .span-3 { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 90; width: 280px; transform: translateX(-100%); transition: transform .2s ease-out; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; z-index: 85; background: rgba(2,6,23,.5); }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .auth-page { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .search-trigger kbd, .user-chip .name { display: none; }
}
@media (max-width: 600px) {
  .grid-4, .form-grid, .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid [class*="span-"] { grid-column: 1 / -1; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
  .page-header { flex-direction: column; }
  .kpi-value { font-size: 20px; }
  .doc-paper { padding: 20px; }
  .filters .input, .filters select.input { min-width: 0; width: 100%; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .page-header .actions, .no-print, .toasts { display: none !important; }
  .app { display: block; } .content { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .card, .doc-paper { box-shadow: none; border: 0; }
}
