:root {
  --bg: #070b14;
  --bg-elevated: #0b1120;
  --surface: rgba(14, 22, 38, .88);
  --surface-2: rgba(22, 31, 50, .82);
  --surface-3: rgba(31, 42, 65, .72);
  --surface-hover: rgba(39, 53, 82, .82);
  --border: rgba(148, 163, 184, .14);
  --line: var(--border);
  --border-strong: rgba(148, 163, 184, .24);
  --text: #f4f7fb;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --primary: #5eead4;
  --primary-strong: #22d3ee;
  --accent: #8b5cf6;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #fb7185;
  --info: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .16);
  --shadow: 0 18px 44px rgba(0, 0, 0, .24);
  --shadow-xl: 0 30px 90px rgba(0, 0, 0, .48);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --sidebar-width: 248px;
  --sidebar-collapsed: 78px;
  --topbar-height: 76px;
  --transition: 160ms cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 95% -15%, rgba(124, 58, 237, .14), transparent 58%),
    radial-gradient(820px 480px at -10% 5%, rgba(34, 211, 238, .10), transparent 56%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden], .hidden { display: none !important; }

/* Shared surfaces */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px) saturate(130%);
}
.panel {
  min-width: 0;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.panel:hover { border-color: var(--border-strong); }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 14px;
}
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 760; letter-spacing: -.01em; }
.panel-head-tools, .toolbar-actions, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.section-subtitle { margin: 16px 0 8px; color: var(--muted); font-size: 12px; font-weight: 760; text-transform: uppercase; letter-spacing: .07em; }

/* Authentication */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(620px 360px at 50% 0%, rgba(34,211,238,.13), transparent 70%),
    linear-gradient(180deg, rgba(7,11,20,.4), var(--bg));
}
.login-card { width: min(430px, 100%); padding: 36px; border-radius: 26px; text-align: center; box-shadow: var(--shadow-xl); }
.login-card h1 { margin: 16px 0 4px; font-size: 28px; letter-spacing: -.04em; }
.login-card p { margin: 0 0 26px; color: var(--muted); }
.brand-mark, .logo-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 14px;
  color: #061019;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary-strong), #a78bfa);
  box-shadow: 0 10px 26px rgba(34,211,238,.18);
}
.brand-mark { width: 66px; height: 66px; margin: 0 auto; border-radius: 20px; font-size: 18px; }

/* Application shell */
.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); transition: grid-template-columns var(--transition); }
.app.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  z-index: 35;
  height: 100vh;
  min-width: 0;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(7, 12, 23, .91);
  backdrop-filter: blur(22px);
  overflow: hidden;
}
.logo {
  display: flex;
  align-items: center;
  gap: 11px;
  height: 58px;
  padding: 4px 5px 12px;
  white-space: nowrap;
}
.logo span { all: unset; }
.logo strong { font-size: 16px; letter-spacing: -.02em; transition: opacity var(--transition), width var(--transition); }
.sidebar-collapse {
  margin-left: auto;
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 9px;
}
.nav-groups { min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.nav-group-label {
  padding: 16px 10px 7px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .12em;
  white-space: nowrap;
}
nav { display: grid; gap: 4px; }
.nav {
  position: relative;
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 680;
  text-align: left;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition), border-color var(--transition), transform var(--transition);
}
.nav svg { width: 18px; height: 18px; flex: 0 0 auto; stroke-width: 1.8; }
.nav:hover { color: var(--text); background: rgba(148,163,184,.08); }
.nav.active {
  color: #dffcff;
  border-color: rgba(94,234,212,.18);
  background: linear-gradient(90deg, rgba(34,211,238,.14), rgba(139,92,246,.08));
}
.nav.active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
}
.nav-label { overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot { margin-top: auto; padding-top: 10px; display: grid; gap: 7px; }
.app.sidebar-collapsed .logo strong,
.app.sidebar-collapsed .nav-label,
.app.sidebar-collapsed .nav-group-label,
.app.sidebar-collapsed .sidebar-foot .btn span { display: none; }
.app.sidebar-collapsed .nav { justify-content: center; padding-inline: 0; }
.app.sidebar-collapsed .sidebar-collapse { margin-left: 0; }
.app.sidebar-collapsed .logo { justify-content: center; }

.main { min-width: 0; padding: 16px 20px 28px; }
.topbar {
  position: sticky;
  top: 12px;
  z-index: 24;
  min-height: var(--topbar-height);
  margin-bottom: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-radius: 18px;
  background: rgba(12, 18, 31, .84);
  border: 1px solid var(--border);
  box-shadow: 0 12px 34px rgba(0,0,0,.20);
  backdrop-filter: blur(20px) saturate(140%);
}
.topbar-main { min-width: 0; display: flex; align-items: center; gap: 12px; }
.mobile-menu { display: none; }
.page-symbol {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: var(--primary);
  background: rgba(34,211,238,.09);
  border: 1px solid rgba(34,211,238,.13);
}
.page-symbol svg { width: 20px; height: 20px; }
.topbar-title { min-width: 0; }
.topbar h2 { margin: 0; font-size: clamp(20px, 2vw, 25px); letter-spacing: -.035em; line-height: 1.15; }
.topbar p { margin: 3px 0 0; max-width: 720px; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.top-icon-btn { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }
.top-icon-btn svg { width: 17px; height: 17px; }
.user-chip { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; color: #07111d; background: linear-gradient(135deg, var(--primary), #c4b5fd); font-size: 11px; font-weight: 900; }
#userBadge { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-action-bar {
  min-height: 40px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.page-context { color: var(--muted); font-size: 12px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Buttons and badges */
.btn {
  min-height: 36px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 720;
  font-size: 12.5px;
  line-height: 1;
  transition: transform var(--transition), border-color var(--transition), background var(--transition), opacity var(--transition);
}
.btn svg { width: 15px; height: 15px; stroke-width: 2; }
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--border-strong); background: var(--surface-hover); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .46; cursor: not-allowed; }
.btn.primary { color: #041016; border-color: transparent; background: linear-gradient(135deg, #67e8f9, #6ee7b7); box-shadow: 0 8px 20px rgba(34,211,238,.12); }
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #a5f3fc, #a7f3d0); }
.btn.ghost { background: transparent; }
.btn.danger-soft { color: #fecdd3; border-color: rgba(251,113,133,.12); background: rgba(251,113,133,.08); }
.btn.small { min-height: 30px; padding: 6px 9px; font-size: 11.5px; border-radius: 8px; }
.btn.icon-only { width: 32px; padding: 0; }
.badge, .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(148,163,184,.07);
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}
.badge.warn { color: #fde68a; border-color: rgba(251,191,36,.22); background: rgba(251,191,36,.08); }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }
.status-pill.success, .status-pill.online, .status-pill.active { color: var(--success); }
.status-pill.failed, .status-pill.offline, .status-pill.disabled, .status-pill.critical { color: var(--danger); }
.status-pill.running, .status-pill.pending, .status-pill.warn, .status-pill.claimed { color: var(--warning); }
.status-pill.queued, .status-pill.info, .status-pill.planned { color: var(--info); }

/* Pages, grids and dashboard */
.page { display: none; }
.page.active { display: grid; gap: 14px; animation: pageIn .18s ease both; }
@keyframes pageIn { from { opacity: .55; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: minmax(0, 1.35fr) minmax(320px, .85fr); }
.cards, .cards-advanced { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 10px; }
.card, .kpi-card {
  position: relative;
  min-width: 0;
  min-height: 104px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(25,35,56,.78), rgba(13,20,35,.72));
}
.kpi-card::after {
  content: "";
  position: absolute;
  width: 76px;
  height: 76px;
  right: -28px;
  bottom: -32px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(94,234,212,.12), transparent 68%);
}
.kpi-card.primary-kpi { min-height: 126px; border-color: rgba(94,234,212,.16); }
.kpi-card.mini-kpi { min-height: 88px; padding: 12px; background: rgba(18,27,44,.66); }
.metric-label { color: var(--muted); font-size: 11px; font-weight: 760; line-height: 1.35; overflow-wrap: anywhere; }
.metric { margin: 8px 0 2px; font-size: clamp(22px, 2.2vw, 30px); font-weight: 850; letter-spacing: -.04em; line-height: 1; overflow-wrap: anywhere; }
.kpi-icon { position: absolute; top: 12px; right: 12px; color: var(--muted-2); }
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-trend { margin-top: 10px; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10.5px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(210px, 1fr)); gap: 13px; align-items: end; }
.stack { display: grid; gap: 13px; }
label { min-width: 0; display: grid; gap: 6px; color: var(--muted); font-size: 11.5px; font-weight: 760; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: #0a1020;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
input::placeholder, textarea::placeholder { color: #56657a; opacity: 1; }
select option { color: var(--text); background: #0b1220; }
textarea { min-height: 104px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: rgba(94,234,212,.52); box-shadow: 0 0 0 3px rgba(94,234,212,.08); background: #0c1425; }
.wide { grid-column: 1 / -1; }
.switch { display: flex; flex-direction: row; align-items: center; gap: 9px; min-height: 40px; }
.switch input { width: 17px; height: 17px; min-height: 0; accent-color: var(--primary-strong); }
.builder-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(190px, 1fr)); gap: 12px; padding: 13px; border: 1px solid var(--border); border-radius: 13px; background: rgba(148,163,184,.035); }
.builder-grid .builder-hint { grid-column: 1 / -1; color: var(--muted-2); font-size: 10.5px; }
.subtle-box { padding: 12px; border: 1px dashed var(--border-strong); border-radius: 13px; background: rgba(148,163,184,.025); }
.form-footer { position: sticky; bottom: -18px; z-index: 2; grid-column: 1 / -1; margin: 8px -18px -18px; padding: 12px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); background: rgba(12,18,31,.95); backdrop-filter: blur(16px); }

/* Modal-first workflows */
.next-modal, .modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(1, 5, 13, .72);
  backdrop-filter: blur(7px);
  animation: modalFade .15s ease both;
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal-card, .next-modal-card {
  width: min(900px, calc(100vw - 32px));
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: #0d1423;
  box-shadow: var(--shadow-xl);
}
.next-modal-card.modal-wide { width: min(1080px, calc(100vw - 32px)); }
.next-modal-card.modal-narrow { width: min(560px, calc(100vw - 32px)); }
.modal-header { min-height: 68px; padding: 14px 17px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.modal-heading { min-width: 0; display: flex; align-items: center; gap: 11px; }
.modal-heading-icon { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 11px; color: var(--primary); background: rgba(94,234,212,.08); }
.modal-heading h3 { margin: 0; font-size: 16px; }
.modal-heading p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.modal-body { min-height: 0; padding: 18px; overflow: auto; }
.modal-body > form { width: 100%; }
.modal-close { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
body.modal-open { overflow: hidden; }

/* List-first entity pages */
.entity-panel { padding: 0; overflow: visible; }
.entity-toolbar { padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); }
.entity-toolbar-left { min-width: 0; display: flex; align-items: center; gap: 10px; }
.entity-toolbar h3 { margin: 0; font-size: 15px; }
.entity-toolbar-meta { color: var(--muted); font-size: 11px; }
.entity-search { position: relative; width: min(290px, 34vw); }
.entity-search svg { position: absolute; left: 10px; top: 50%; width: 15px; height: 15px; color: var(--muted-2); transform: translateY(-50%); pointer-events: none; }
.entity-search input { min-height: 34px; padding: 7px 10px 7px 33px; border-radius: 9px; }
.entity-list { min-width: 0; }
.entity-row {
  display: grid;
  grid-template-columns: minmax(210px, 1.35fr) minmax(150px, .8fr) minmax(150px, .8fr) minmax(130px, .7fr) 46px;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.entity-row:last-child { border-bottom: 0; }
.entity-row:hover { background: rgba(148,163,184,.035); }
.entity-main { min-width: 0; display: flex; align-items: center; gap: 11px; }
.entity-icon { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 11px; color: var(--primary); border: 1px solid rgba(94,234,212,.12); background: rgba(94,234,212,.06); }
.entity-icon svg { width: 18px; height: 18px; }
.entity-copy { min-width: 0; }
.entity-name { color: var(--text); font-weight: 770; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity-sub { margin-top: 2px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity-cell { min-width: 0; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.entity-cell strong { display: block; color: var(--text); font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-menu { position: relative; justify-self: end; }
.row-menu > summary { list-style: none; width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 9px; color: var(--muted); cursor: pointer; user-select: none; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu > summary:hover, .row-menu[open] > summary { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.row-menu-pop {
  position: absolute;
  top: 37px;
  right: 0;
  z-index: 18;
  width: 180px;
  padding: 6px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #111a2b;
  box-shadow: var(--shadow);
}
.row-menu-pop .btn { width: 100%; justify-content: flex-start; border-color: transparent; background: transparent; }
.row-menu-pop .btn:hover { background: var(--surface-hover); }

/* Tables */
.table-wrap { min-width: 0; overflow: auto; border: 1px solid var(--border); border-radius: 13px; scrollbar-width: thin; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 760px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; font-size: 11.5px; }
th { position: sticky; top: 0; z-index: 2; color: var(--muted); background: #11192a; font-size: 10px; font-weight: 830; text-transform: uppercase; letter-spacing: .045em; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: rgba(148,163,184,.035); }
tbody tr:last-child td { border-bottom: 0; }
code { color: #86efac; font-size: 11px; word-break: break-all; }
.status-success, .status-sent, .status-online, .status-available, .status-healthy { color: var(--success); font-weight: 800; }
.status-failed, .status-offline, .status-critical, .status-retention_failed { color: var(--danger); font-weight: 800; }
.status-running, .status-pending, .status-claimed, .status-submitted, .status-provider_pending { color: var(--warning); font-weight: 800; }
.status-queued, .status-planned, .status-new { color: var(--info); font-weight: 800; }
.status-cancelled, .status-disabled, .status-skipped { color: var(--muted); font-weight: 800; }
.health-meter { width: 84px; height: 7px; overflow: hidden; border: 0; border-radius: 999px; background: rgba(148,163,184,.12); }
.health-meter::-webkit-progress-bar { background: rgba(148,163,184,.12); border-radius: 999px; }
.health-meter::-webkit-progress-value { background: linear-gradient(90deg, var(--danger), var(--warning), var(--success)); border-radius: 999px; }
.health-meter::-moz-progress-bar { background: linear-gradient(90deg, var(--danger), var(--warning), var(--success)); border-radius: 999px; }

/* Empty states and logs */
.empty-state { min-height: 190px; padding: 28px; display: grid; place-items: center; text-align: center; }
.empty-state-icon { width: 52px; height: 52px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 16px; color: var(--muted); background: rgba(148,163,184,.07); border: 1px solid var(--border); }
.empty-state h4 { margin: 0 0 4px; font-size: 15px; }
.empty-state p { max-width: 420px; margin: 0; color: var(--muted); font-size: 11.5px; }
.log-list { display: grid; gap: 8px; }
.log-line { padding: 11px 12px; overflow-wrap: anywhere; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); background: rgba(148,163,184,.035); font-size: 11.5px; }
.log-line strong { color: var(--text); }
.insight-ok { border-color: rgba(52,211,153,.22); }
.insight-warn { border-color: rgba(251,191,36,.26); }
.insight-critical { border-color: rgba(251,113,133,.30); }
.terminal { margin-top: 12px; max-height: 420px; overflow: auto; padding: 13px; border: 1px solid rgba(52,211,153,.15); border-radius: 13px; color: #bbf7d0; background: #030811; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; line-height: 1.65; }

/* Workspace tabs */
.workspace-tabs, .settings-tabs {
  position: sticky;
  top: 104px;
  z-index: 18;
  display: flex;
  gap: 5px;
  padding: 5px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(10,16,29,.88);
  backdrop-filter: blur(16px);
  scrollbar-width: none;
}
.workspace-tabs::-webkit-scrollbar, .settings-tabs::-webkit-scrollbar { display: none; }
.workspace-tab, .settings-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 11px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 760;
}
.workspace-tab svg, .settings-tab svg { width: 15px; height: 15px; flex: 0 0 auto; stroke-width: 1.9; }
.workspace-tab.active, .settings-tab.active { color: var(--text); background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--border); }
.workspace-pane { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.workspace-pane.active { display: grid; }
.workspace-pane > .panel.wide-panel { grid-column: 1 / -1; }
.feature-summary { min-height: 110px; display: grid; align-content: center; gap: 5px; color: var(--muted); font-size: 11.5px; }
.feature-summary strong { color: var(--text); font-size: 13px; }

/* Settings */
.settings-shell { padding: 0; overflow: hidden; }
.settings-header { padding: 16px 18px 0; }
.settings-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 560px; }
.settings-tabs { position: static; flex-direction: column; align-items: stretch; margin: 0; padding: 12px; border: 0; border-right: 1px solid var(--border); border-radius: 0; background: rgba(148,163,184,.025); }
.settings-tab { width: 100%; justify-content: flex-start; text-align: left; }
.settings-panes { min-width: 0; padding: 18px; }
.settings-pane { display: none; grid-template-columns: repeat(2, minmax(210px, 1fr)); gap: 13px; }
.settings-pane.active { display: grid; }
.settings-pane-title { grid-column: 1 / -1; margin-bottom: 3px; }
.settings-pane-title h4 { margin: 0; font-size: 15px; }
.settings-pane-title p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.settings-savebar { position: sticky; bottom: 0; z-index: 4; grid-column: 1 / -1; margin: 14px -18px -18px; padding: 11px 18px; display: flex; justify-content: flex-end; border-top: 1px solid var(--border); background: rgba(13,20,35,.96); backdrop-filter: blur(16px); }

/* Trend and health */
.trend-list { display: grid; gap: 9px; }
.trend-row { display: grid; grid-template-columns: 92px minmax(120px, 1fr) 120px; align-items: center; gap: 10px; color: var(--muted); font-size: 10.5px; font-weight: 700; }
.trend-row > div { height: 7px; overflow: hidden; border-radius: 999px; background: rgba(148,163,184,.10); }
.trend-row i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary-strong), var(--accent)); transition: width .28s ease; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 9px; }
.mini-card { min-width: 0; padding: 11px; display: grid; gap: 4px; border: 1px solid var(--border); border-radius: 12px; background: rgba(148,163,184,.035); }
.mini-card span { color: var(--muted); font-size: 9.5px; font-weight: 850; text-transform: uppercase; letter-spacing: .065em; }
.mini-card strong { color: var(--text); font-size: 17px; letter-spacing: -.025em; overflow-wrap: anywhere; }

/* Filters and pager */
.inline-filter { display: grid; grid-template-columns: minmax(190px, 1fr) 150px 110px auto auto; gap: 8px; align-items: center; margin-bottom: 10px; }
.inline-filter input, .inline-filter select { min-height: 34px; padding-block: 7px; }
.pager { margin: 0 0 10px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

/* Detail inspector and command palette */
.inspector-grid { display: grid; gap: 12px; }
.inspector-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.inspector-code { max-height: 52vh; overflow: auto; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px; color: #d7e3f4; background: #070c16; white-space: pre-wrap; word-break: break-word; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.command-list { display: grid; gap: 5px; }
.command-item { width: 100%; padding: 10px; display: flex; align-items: center; gap: 10px; border: 1px solid transparent; border-radius: 10px; color: var(--text); background: transparent; cursor: pointer; text-align: left; }
.command-item:hover { border-color: var(--border); background: var(--surface-2); }
.command-item svg { width: 18px; height: 18px; color: var(--muted); }
.command-copy strong { display: block; font-size: 12px; }
.command-copy span { color: var(--muted); font-size: 10.5px; }

/* Toast */
.toast { position: fixed; top: 16px; right: 16px; z-index: 120; max-width: min(420px, calc(100vw - 32px)); padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 11px; color: var(--text); background: #111a2b; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(-8px); transition: opacity var(--transition), transform var(--transition); }
.toast.show { opacity: 1; transform: none; }
.toast.success { border-color: rgba(52,211,153,.36); }
.toast.error { border-color: rgba(251,113,133,.44); color: #fecdd3; }
.error-text { min-height: 18px; color: #fecdd3; font-size: 12px; font-weight: 700; }

/* Role visibility */
body[data-role="viewer"] .operator-only,
body[data-role="viewer"] .admin-only,
body[data-role="operator"] .admin-only { display: none !important; }

/* Themes */
body[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-elevated: #ffffff;
  --surface: rgba(255,255,255,.92);
  --surface-2: rgba(241,245,249,.96);
  --surface-3: rgba(226,232,240,.92);
  --surface-hover: #eaf0f7;
  --border: rgba(30,41,59,.11);
  --border-strong: rgba(30,41,59,.18);
  --text: #111827;
  --muted: #64748b;
  --muted-2: #94a3b8;
  background: radial-gradient(900px 520px at 95% -15%, rgba(124,58,237,.07), transparent 58%), #f4f7fb;
}
body[data-theme="light"] .sidebar { background: rgba(250,252,255,.95); }
body[data-theme="light"] .topbar, body[data-theme="light"] .workspace-tabs { background: rgba(255,255,255,.88); }
body[data-theme="light"] input, body[data-theme="light"] select, body[data-theme="light"] textarea { color: #111827; background: #fff; }
body[data-theme="light"] select option { color: #111827; background: #fff; }
body[data-theme="light"] th { background: #f3f6fa; }
body[data-theme="light"] .row-menu-pop, body[data-theme="light"] .modal-card, body[data-theme="light"] .next-modal-card { background: #fff; }
body[data-theme="light"] .inspector-code, body[data-theme="light"] .terminal { color: #123; background: #eef3f8; }
body[data-theme="amoled"] { --bg: #000; --surface: rgba(8,8,8,.96); --surface-2: #111; --surface-3: #171717; --surface-hover: #1e1e1e; background: #000; }
body[data-theme="amoled"] .sidebar, body[data-theme="amoled"] .topbar { background: rgba(0,0,0,.96); }
body[data-theme="blue"] { --primary: #60a5fa; --primary-strong: #38bdf8; --accent: #2563eb; background: radial-gradient(900px 520px at 95% -15%, rgba(37,99,235,.16), transparent 58%), #06101f; }
body[data-theme="green"] { --primary: #4ade80; --primary-strong: #34d399; --accent: #16a34a; background: radial-gradient(900px 520px at 95% -15%, rgba(22,163,74,.15), transparent 58%), #05110b; }
body[data-density="comfortable"] { font-size: 14.5px; }
body[data-density="comfortable"] .panel { padding: 22px; }
body[data-density="comfortable"] .entity-row { min-height: 78px; padding-block: 13px; }
body[data-density="comfortable"] th, body[data-density="comfortable"] td { padding: 13px; }

/* Responsive */
@media (max-width: 1440px) {
  .cards, .cards-advanced { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
}
@media (max-width: 1180px) {
  .app { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }
  .logo strong, .nav-label, .nav-group-label, .sidebar-foot .btn span { display: none; }
  .nav { justify-content: center; padding-inline: 0; }
  .logo { justify-content: center; }
  .sidebar-collapse { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .workspace-pane { grid-template-columns: 1fr; }
  .workspace-pane > .panel { grid-column: 1; }
  .entity-row { grid-template-columns: minmax(200px, 1.4fr) minmax(130px, .8fr) minmax(120px, .7fr) 42px; }
  .entity-row .entity-created { display: none; }
}
@media (max-width: 920px) {
  .cards, .cards-advanced { grid-template-columns: repeat(3, minmax(110px, 1fr)); }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-tabs { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .settings-tab { width: auto; white-space: nowrap; }
  .inspector-meta { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  :root { --topbar-height: 66px; }
  .app, .app.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(286px, 84vw);
    height: 100dvh;
    padding: 14px;
    transform: translateX(-104%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-xl);
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.52); backdrop-filter: blur(3px); }
  .logo strong, .nav-label, .nav-group-label, .sidebar-foot .btn span { display: initial; }
  .logo { justify-content: flex-start; }
  .nav { justify-content: flex-start; padding-inline: 10px; }
  .nav-group-label { display: block; }
  .sidebar-collapse { display: none; }
  .main { padding: 10px 10px 22px; }
  .topbar { top: 7px; min-height: 62px; padding: 10px; border-radius: 15px; }
  .mobile-menu { display: grid; }
  .page-symbol { display: none; }
  .topbar p { max-width: 54vw; }
  #userBadge { display: none; }
  .top-actions { gap: 5px; }
  .top-icon-btn { width: 34px; height: 34px; }
  #quickRunOpen { min-width: 34px; width: 34px; padding: 0; font-size: 0; }
  #quickRunOpen svg { width: 16px; height: 16px; }
  .page-action-bar { min-height: 34px; margin-bottom: 10px; }
  .page-action-bar:has(.page-actions:empty) { display: none; }
  .page-context { display: none; }
  .cards, .cards-advanced { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-card.primary-kpi { min-height: 108px; }
  .kpi-card.mini-kpi { min-height: 82px; }
  .panel { padding: 13px; border-radius: 15px; }
  .form-grid, .settings-pane, .builder-grid { grid-template-columns: 1fr; }
  .wide, .builder-grid, .settings-pane-title { grid-column: 1; }
  .workspace-tabs { top: 82px; }
  .workspace-pane { gap: 10px; }
  .entity-toolbar { align-items: stretch; flex-direction: column; }
  .entity-toolbar-left, .toolbar-actions { width: 100%; }
  .entity-search { width: 100%; }
  .entity-row { grid-template-columns: minmax(0, 1fr) 38px; gap: 8px; min-height: 64px; padding: 10px 12px; }
  .entity-row .entity-cell { display: none; }
  .entity-main { min-width: 0; }
  .modal-card, .next-modal-card, .next-modal-card.modal-wide, .next-modal-card.modal-narrow { width: calc(100vw - 14px); max-height: calc(100dvh - 14px); border-radius: 16px; }
  .next-modal, .modal { padding: 7px; }
  .modal-header { min-height: 60px; padding: 11px 13px; }
  .modal-body { padding: 13px; }
  .form-footer { bottom: -13px; margin: 8px -13px -13px; padding: 10px 13px; }
  .inline-filter { grid-template-columns: 1fr 1fr; }
  .inline-filter > :first-child { grid-column: 1 / -1; }
  .table-wrap { overflow: visible; border: 0; }
  .table-wrap table { min-width: 0; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: grid; gap: 8px; }
  .table-wrap tr { display: grid; gap: 5px; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: rgba(148,163,184,.025); }
  .table-wrap td { padding: 4px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; border: 0; text-align: right; overflow-wrap: anywhere; }
  .table-wrap td::before { content: attr(data-label); flex: 0 0 92px; color: var(--muted); font-weight: 760; text-align: left; }
  .table-wrap td.actions { justify-content: flex-end; }
  .trend-row { grid-template-columns: 1fr; gap: 4px; }
  .settings-panes { padding: 13px; }
  .settings-savebar { margin: 12px -13px -13px; padding: 10px 13px; }
}
@media (max-width: 480px) {
  .cards, .cards-advanced { grid-template-columns: 1fr 1fr; }
  .kpi-card { min-height: 88px; padding: 11px; }
  .metric { font-size: 21px; }
  .topbar-title p { display: none; }
  .inline-filter { grid-template-columns: 1fr; }
  .inline-filter > * { grid-column: 1 !important; }
  .inspector-meta { grid-template-columns: 1fr; }
}
