/* Xilancer Admin — Linear/Stripe-density, dark default */

:root {
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: color-mix(in oklch, var(--accent) 18%, transparent);
  --accent-fg: #ffffff;

  /* Dark (default) */
  --bg: #0a0b10;
  --bg-elev: #0f1117;
  --surface: #14161d;
  --surface-2: #181b23;
  --hover: #1d212b;
  --border: #22262f;
  --border-strong: #2c313c;
  --text: #e6e8ed;
  --text-2: #a3a8b4;
  --text-3: #6b7280;
  --text-dim: #4b5260;

  --success: #10b981;
  --success-soft: color-mix(in oklch, #10b981 15%, transparent);
  --warn: #f59e0b;
  --warn-soft: color-mix(in oklch, #f59e0b 15%, transparent);
  --danger: #ef4444;
  --danger-soft: color-mix(in oklch, #ef4444 15%, transparent);
  --info: #3b82f6;
  --info-soft: color-mix(in oklch, #3b82f6 15%, transparent);

  --radius: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  --sidebar-w: 232px;
  --topbar-h: 48px;

  --shadow-md: 0 4px 16px -4px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.03) inset;

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --hover: #f0f0f3;
  --border: #e6e6ea;
  --border-strong: #d4d4da;
  --text: #18181b;
  --text-2: #57575e;
  --text-3: #80808a;
  --text-dim: #a8a8b0;
  --shadow-md: 0 4px 16px -4px rgba(15,15,20,0.08), 0 1px 0 rgba(0,0,0,0.02) inset;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.icon { width: 14px; height: 14px; flex: none; display: inline-block; vertical-align: -2px; }
.crumbs .sep .icon { width: 12px; height: 12px; }
.workspace .chev .icon { width: 14px; height: 14px; }

/* ============ Layout ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  background: var(--bg);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  min-width: 0;
  min-height: 0;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--bg-elev);
  position: relative;
  z-index: 5;
}

.content {
  overflow: auto;
  min-height: 0;
  background: var(--bg);
}

.content::-webkit-scrollbar { width: 10px; height: 10px; }
.content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }
.content::-webkit-scrollbar-track { background: transparent; }

/* ============ Sidebar ============ */
.brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex: none;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), color-mix(in oklch, var(--accent) 60%, #000));
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.02em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15);
  flex: none;
}
.brand-name {
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -0.01em;
}
.brand-tag {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
}

.workspace {
  margin: 10px 10px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  flex: none;
}
.workspace:hover { background: var(--hover); }
.workspace-avatar {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  flex: none;
}
.workspace-name { font-size: 12.5px; font-weight: 500; }
.workspace-role { font-size: 11px; color: var(--text-3); }
.workspace .chev { margin-left: auto; color: var(--text-3); }

/* Sidebar search */
.sb-search {
  display: flex; align-items: center; gap: 7px;
  margin: 6px 10px 2px;
  padding: 5px 9px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.sb-search:focus-within { border-color: var(--border-strong); }
.sb-search .icon { width: 12px; height: 12px; color: var(--text-dim); flex: none; }
.sb-search input {
  background: none; border: none; outline: none;
  font-size: 12px; color: var(--text); width: 100%;
  font-family: var(--font);
}
.sb-search input::placeholder { color: var(--text-dim); }

.nav {
  padding: 4px 8px 8px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.nav-section {
  margin-top: 14px;
}
.nav-label {
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 10px;
  color: var(--text-3);
  padding: 0 8px 6px;
  font-weight: 500;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 450;
  position: relative;
  user-select: none;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active {
  background: var(--hover);
  color: var(--text);
  font-weight: 500;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.nav-item .icon { width: 15px; height: 15px; opacity: 0.85; flex: none; }
.nav-item .count {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.nav-item .badge {
  margin-left: auto;
  font-size: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 10px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: var(--radius);
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.user-chip:hover { background: var(--hover); }
.user-name { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mail { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ Topbar ============ */
.crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}
.crumbs .sep { color: var(--text-dim); }
.crumbs .cur { color: var(--text); font-weight: 500; }

.search {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  width: 280px;
  color: var(--text-3);
  font-size: 12.5px;
  cursor: pointer;
}
.search:hover { border-color: var(--border-strong); }
.search .kbd {
  margin-left: auto;
  display: flex; gap: 2px;
}
.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
}
.kbd kbd {
  border: 1px solid var(--border);
  border-bottom-width: 1.5px;
  border-radius: 3px;
  padding: 0 4px;
  font-family: inherit;
}

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-2);
  background: transparent;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn .icon { width: 15px; height: 15px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn .icon { width: 14px; height: 14px; }
.btn.primary {
  background: var(--accent);
  border-color: color-mix(in oklch, var(--accent) 80%, #000);
  color: var(--accent-fg);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 1px 2px rgba(0,0,0,0.2);
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.sm { height: 24px; padding: 0 8px; font-size: 12px; }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: white; }

/* ============ Page header ============ */
.page {
  padding: 18px 24px 40px;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}
.page-sub {
  margin: 2px 0 0;
  color: var(--text-3);
  font-size: 12.5px;
}
.page-actions { display: flex; gap: 6px; align-items: center; }

/* Segmented range */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 2px;
  gap: 0;
}
.seg button {
  height: 22px; padding: 0 8px;
  font-size: 11.5px;
  background: transparent; border: 0;
  border-radius: 4px;
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font-mono);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--hover); color: var(--text); }

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.card-sub { font-size: 11.5px; color: var(--text-3); }
.card-body { padding: 14px; }

/* ============ Dialog (native <dialog> element) ============ */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 40px rgba(0,0,0,.28);
  max-width: 94vw;
}
dialog::backdrop {
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}
.dialog-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 65vh;
  overflow-y: auto;
}
.dialog-foot {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
@media (max-width: 640px) {
  dialog { width: calc(100vw - 24px) !important; max-width: calc(100vw - 24px); max-height: 90vh; margin: auto; }
  .dialog-body { max-height: 50vh; }
}

/* KPI tile */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.kpi { padding: 16px; border-right: 1px solid var(--border); display: flex; flex-direction: row; align-items: center; gap: 14px; min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi-spark { flex: none; width: 130px; height: 52px; line-height: 0; order: 1; }
.kpi-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 11.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}
.kpi-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-3); }
.delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
}
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

/* ============ Grid helpers ============ */
.grid { display: grid; gap: 12px; }
.grid-12 { grid-template-columns: repeat(12, 1fr); }
.row { display: flex; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.span-8 { grid-column: span 8; min-width: 0; }
.span-4 { grid-column: span 4; min-width: 0; }
.span-6 { grid-column: span 6; min-width: 0; }
.span-5 { grid-column: span 5; min-width: 0; }
.span-7 { grid-column: span 7; min-width: 0; }
.span-12 { grid-column: span 12; min-width: 0; }

/* ============ Tables ============ */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  color: var(--text-3);
  font-size: 11.5px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0;
  user-select: none;
  white-space: nowrap;
}
.tbl td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.tbl tbody tr:hover td { background: var(--hover); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--font-mono); }
.tbl td.dim { color: var(--text-3); }
.tbl .row-link { cursor: pointer; }

/* Tag / pill */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--surface-2);
  font-family: var(--font-mono);
  letter-spacing: 0;
  line-height: 17px;
}
.tag.success { color: var(--success); background: var(--success-soft); border-color: transparent; }
.tag.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.tag.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.tag.info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.tag.accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.tag .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* Avatar bubble */
.av {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 10.5px; font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  flex: none;
}
.av-stack { display: inline-flex; }
.av-stack .av { margin-left: -6px; }
.av-stack .av:first-child { margin-left: 0; }

/* User cell */
.usercell { display: flex; align-items: center; gap: 8px; }
.usercell .nm { font-weight: 500; font-size: 12.5px; }
.usercell .sub { font-size: 11px; color: var(--text-3); }

/* Mini progress bar */
.bar {
  width: 100%; height: 4px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* Toolbar above table */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-2);
  background: transparent;
  cursor: pointer;
}
.filter-chip:hover { background: var(--hover); color: var(--text); }
.filter-chip.applied {
  border-style: solid;
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}
.filter-chip .v { color: var(--text); font-weight: 500; }

/* Empty */
.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-3);
  font-size: 12.5px;
}

/* Tabs */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  padding: 0 14px;
  margin-bottom: 0;
}
.tabs-flush {
  background: var(--bg-elev);
  padding: 0 24px;
}
.tab {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.on {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 500;
}
.tab .ct { margin-left: 4px; color: var(--text-3); font-family: var(--font-mono); font-size: 11px; }

/* List rows */
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--hover); }
.list-row .meta { margin-left: auto; color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); }

/* Star */
.stars { display: inline-flex; gap: 1px; color: var(--warn); }

/* Switch */
.switch {
  width: 28px; height: 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  flex: none;
}
.switch::after {
  content: ""; position: absolute;
  top: 1px; left: 1px;
  width: 12px; height: 12px;
  background: var(--text-2);
  border-radius: 50%;
  transition: transform .15s ease, background .15s ease;
}
.switch.on { background: var(--accent-soft); border-color: var(--accent); }
.switch.on::after { transform: translateX(12px); background: var(--accent); }

/* Settings */
.setting-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .info { flex: 1; min-width: 0; }
.setting-row .ttl { font-size: 13px; font-weight: 500; }
.setting-row .desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Form labels */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* Inputs */
.input {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.input.wide { width: 100%; }

/* Section header inline */
.section-h {
  display: flex; align-items: baseline; gap: 10px;
  margin: 22px 0 10px;
}
.section-h h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.section-h .sub { color: var(--text-3); font-size: 12px; }

.divider { height: 1px; background: var(--border); margin: 8px 0; }

/* Mini scrollbar everywhere */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============ Bell button ============ */
.bell-btn {
  position: relative;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
}
.bell-btn:hover { background: var(--hover); color: var(--text); }
.bell-btn.on { background: var(--hover); color: var(--text); border-color: var(--border); }
.bell-btn .icon { width: 16px; height: 16px; }
.bell-dot {
  position: absolute;
  top: -5px; right: -5px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--bg);
  line-height: 1;
  z-index: 1;
}
.bell-pulse {
  position: absolute;
  top: -8px; right: -8px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--danger);
  opacity: 0.5;
  animation: bellPulse 1.6s ease-out infinite;
  pointer-events: none;
}
@keyframes bellPulse {
  0%   { transform: scale(0.5); opacity: 0.4; }
  60%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* ============ User pill ============ */
.user-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px;
  padding: 0 8px 0 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  margin-left: 2px;
}
.user-pill:hover { background: var(--hover); border-color: var(--border-strong); }
.user-pill.on { background: var(--hover); border-color: var(--border-strong); }
.user-pill .av { width: 22px; height: 22px; font-size: 10px; }
.user-pill-info { display: flex; flex-direction: column; line-height: 1.2; text-align: left; }
.user-pill-name { font-size: 12px; font-weight: 500; }
.user-pill-role { font-size: 10.5px; color: var(--text-3); font-family: var(--font-mono); }
.user-pill .icon { width: 12px; height: 12px; color: var(--text-3); margin-left: 2px; }

/* ============ Popover ============ */
.pop-wrap { position: relative; display: inline-block; }
.pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md), 0 8px 24px -4px rgba(0,0,0,0.4);
  min-width: 280px;
  overflow: hidden;
  display: none;
}
.pop.open { display: block; }

.notif-pop { width: 380px; }
.pop-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.pop-tabs {
  display: flex; gap: 0;
  padding: 0 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.pop-tab {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 5px;
}
.pop-tab em { color: var(--text-dim); font-style: normal; font-family: var(--font-mono); font-size: 11px; }
.pop-tab:hover { color: var(--text-2); }
.pop-tab.on { color: var(--text); border-bottom-color: var(--accent); }
.pop-body {
  max-height: 380px;
  overflow-y: auto;
}
.pop-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.notif {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}
.notif:hover { background: var(--hover); }
.notif:last-child { border-bottom: 0; }
.notif.unread::before {
  content: "";
  position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 2px; background: var(--accent); border-radius: 2px;
}
.notif-t { font-size: 12.5px; font-weight: 500; color: var(--text); line-height: 1.35; }
.notif-s { font-size: 11.5px; color: var(--text-3); margin-top: 2px; line-height: 1.35; }
.notif-r { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.notif-time { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); }
.unread-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* User popover */
.user-pop { width: 280px; }
.user-pop-head {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.pop-section {
  padding: 4px;
  border-bottom: 1px solid var(--border);
}
.pop-section:last-child { border-bottom: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  cursor: pointer;
}
.menu-item:hover { background: var(--hover); }
.menu-item .icon { width: 14px; height: 14px; color: var(--text-3); }

/* Live dot on nav */
.live-dot {
  margin-left: auto;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--success) 18%, transparent);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--success) 18%, transparent);
  flex: none;
}
.status-dot.ok { background: var(--success); }

/* ============ Utility ============ */
.hidden { display: none !important; }

/* ============ Sidebar — Collapsible Submenus ============ */
.nav-group { position: relative; }

/* Chevron arrow */
.nav-chev {
  width: 12px; height: 12px;
  margin-left: auto;
  flex: none;
  color: var(--text-3);
  transition: transform 0.18s ease;
  display: inline-block;
  vertical-align: -1px;
}
.nav-group.open > .nav-item > .nav-chev,
.nav-group.open > .nav-child > .nav-chev {
  transform: rotate(90deg);
}

/* Children container — collapsed by default, expands when .nav-group.open */
.nav-children {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: 18px;
}
.nav-group.open > .nav-children {
  max-height: 3000px;
}

/* Child item (anchor or toggle div) */
.nav-child {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  position: relative;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  text-decoration: none;
  user-select: none;
  line-height: 1.4;
  min-height: 26px;
}
.nav-child:hover { background: var(--hover); color: var(--text); }
.nav-child.active,
.nav-child.selected {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-child.has-children { font-weight: 450; }

/* Badge inside child items */
.nav-child .badge {
  margin-left: auto;
  font-size: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 10px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-weight: 600;
  flex: none;
}

/* Level 2 nested children (deeper indent, smaller text) */
.nav-children .nav-children {
  padding-left: 12px;
}
.nav-children .nav-children .nav-child {
  font-size: 11.5px;
  color: var(--text-3);
  min-height: 24px;
}
.nav-children .nav-children .nav-child:hover { color: var(--text-2); background: var(--hover); }
.nav-children .nav-children .nav-child.active,
.nav-children .nav-children .nav-child.selected {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

/* Level 3 nested children */
.nav-children .nav-children .nav-children {
  padding-left: 10px;
}
.nav-children .nav-children .nav-children .nav-child {
  font-size: 11px;
  min-height: 22px;
}

/* Ensure .nav-item.has-children (toggle div) has same styling as nav-item links */
.nav-item.has-children {
  user-select: none;
}

/* ============ Mobile responsive ============ */
.mob-menu { display: none; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 199; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.sidebar-backdrop.show { display: block; }

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .content { overflow-x: hidden; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 200;
    transform: translateX(calc(-1 * var(--sidebar-w) - 4px));
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar.mob-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,0.4);
  }

  .mob-menu {
    display: grid;
    place-items: center;
    width: 32px; height: 32px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-2);
    cursor: pointer;
    flex: none;
  }
  .mob-menu:hover { background: var(--hover); color: var(--text); }
  .mob-menu .icon { width: 16px; height: 16px; }

  .crumbs { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }

  /* Popovers: scrollable on mobile; MutationObserver handles fixed positioning */
  .pop {
    position: fixed;
    max-height: calc(100vh - var(--topbar-h) - 16px);
    overflow-y: auto;
  }
  /* Topbar pops (notification, user menu) span full width */
  .notif-pop, .user-pop {
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 0 12px 12px;
  }
  .pop-body  { max-height: 55vh; }

  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(2) { border-right: 0; }
  .kpi:nth-child(3), .kpi:nth-child(4) { border-top: 1px solid var(--border); }
  .grid-12 { grid-template-columns: 1fr !important; }
  .span-4, .span-5, .span-6, .span-7, .span-8, .span-12 { grid-column: span 1; }

  /* Stack setting rows that end with an input/select wrapper div — exclude toggle switch rows */
  .setting-row:has(> div:not(.switch):last-child) { flex-direction: column; align-items: stretch; gap: 8px; }
  .setting-row > div:not(.switch):last-child { width: 100% !important; }
}

@media (max-width: 640px) {
  .pg-bar { justify-content: center; }
  .pg-bar > span[style*="flex:1"] { display: none; }
  .pg-bar > span:first-child { width: 100%; text-align: center; margin-right: 0; }

  /* Shrink KPI sparklines in 2-col layout to give the value text room */
  .kpi-spark { width: 80px; height: 40px; }
  .kpi-value { font-size: 18px; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi { border-right: 0; border-bottom: 1px solid var(--border); }
  .kpi:last-child { border-bottom: 0; }
  .kpi-spark { width: 72px; height: 44px; }
  .user-pill-info { display: none; }
}
