/* ============================================================================
   ODX Admin — Unified Design System ("ui.css") · KERNEL SKIN
   Visual language ported from Swift's kernel.css: void-dark surfaces,
   electric violet + acid yellow, mono micro-labels, display-type headlines.
   Loads AFTER theme.css (token source). Selectors are the stable contract
   from the June 2026 revamp — only their look changed.
   ========================================================================== */

/* ==================== Extended Tokens ==================== */

:root {
  /* status softs (kernel pills/alerts) */
  --success-soft: rgba(74, 222, 128, 0.09);
  --success-text: #a7f3c4;
  --error-soft: rgba(255, 92, 114, 0.10);
  --error-text: #ffb3be;
  --warning-soft: rgba(255, 180, 84, 0.10);
  --warning-text: #ffd9a3;
  --info: #5b8cff;
  --info-soft: rgba(91, 140, 255, 0.12);
  --info-text: #b9ccff;
  --neutral-soft: rgba(106, 99, 148, 0.14);
  --neutral-text: #9a92c2;
  --purple: #a06bff;
  --purple-soft: rgba(160, 107, 255, 0.13);
  --purple-text: #cfb2ff;

  /* radii (kernel: 14 card / 12 tile / 10 control / 8 small) */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 12px;
  --r-lg: 14px;
  --r-full: 9999px;

  /* type scale */
  --fs-xs: 0.75rem;    /* 12 */
  --fs-sm: 0.8125rem;  /* 13 */
  --fs-md: 0.875rem;   /* 14 — base UI size */
  --fs-lg: 1rem;       /* 16 */
  --fs-xl: 1.125rem;   /* 18 */
  --fs-2xl: 1.375rem;  /* 22 */
  --fs-3xl: 1.75rem;   /* 28 */

  /* z-index ladder */
  --z-sidebar: 200;
  --z-topbar: 150;
  --z-dropdown: 400;
  --z-modal: 1000;
  --z-toast: 1200;

  /* shell metrics */
  --sidebar-w: 252px;
  --sidebar-w-collapsed: 70px;
  --topbar-h: 64px;

  --focus-ring: 0 0 0 3px rgba(255, 245, 130, 0.16), 0 0 18px -4px rgba(255, 245, 130, 0.30);
}

[data-theme="light"] {
  --success-soft: rgba(24, 165, 90, 0.10);
  --success-text: #137a43;
  --error-soft: rgba(224, 53, 80, 0.09);
  --error-text: #b81f38;
  --warning-soft: rgba(217, 131, 22, 0.11);
  --warning-text: #a35e07;
  --info: #3f6ce0;
  --info-soft: rgba(63, 108, 224, 0.10);
  --info-text: #2a4dba;
  --neutral-soft: rgba(117, 110, 155, 0.12);
  --neutral-text: #4b4570;
  --purple: #8b5cf6;
  --purple-soft: rgba(139, 92, 246, 0.11);
  --purple-text: #6c2bd9;

  --focus-ring: 0 0 0 3px rgba(84, 53, 240, 0.22);
}

/* ==================== Base refinements ==================== */

html {
  font-size: 16px;
}

body {
  font-size: var(--fs-md);
  min-height: 100vh;
}

::selection {
  background: rgba(255, 245, 130, 0.25);
  color: var(--text-primary);
}

[data-theme="light"] ::selection {
  background: rgba(84, 53, 240, 0.18);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-xs);
}

/* slim themed scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-hi) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-hi);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-tertiary); }

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

/* mono micro-label — the kernel signature, reused across components */
.ui-microlabel,
.ui-kpi-label,
.ui-label,
.sidebar-section-label,
.ui-table th {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 500;
}

/* ==================== Ambient stage (kernel background) ==================== */

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 600px at 14% -12%, rgba(45, 0, 244, 0.22), transparent 62%),
    radial-gradient(720px 540px at 108% 112%, rgba(45, 0, 244, 0.13), transparent 60%),
    radial-gradient(520px 380px at 90% -8%, rgba(255, 245, 130, 0.04), transparent 60%);
}

[data-theme="light"] .bg {
  background:
    radial-gradient(900px 600px at 14% -12%, rgba(84, 53, 240, 0.08), transparent 62%),
    radial-gradient(720px 540px at 108% 112%, rgba(84, 53, 240, 0.05), transparent 60%);
}

/* ==================== App Shell ==================== */

.shell {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

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

/* ---- Topbar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg-primary) 78%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--bg-primary); }
}

/* hairline glow along the topbar — kernel card signature */
.topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 9%;
  right: 9%;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 130, 0.22), transparent);
}

[data-theme="light"] .topbar::after {
  background: linear-gradient(90deg, transparent, rgba(84, 53, 240, 0.18), transparent);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  flex-shrink: 0;
}

.topbar-brand-logo {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--acid);
  background: var(--acid-soft);
  border: 1px solid rgba(255, 245, 130, 0.22);
  box-shadow: 0 0 22px -6px rgba(255, 245, 130, 0.3);
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
[data-theme="light"] .topbar-brand-logo {
  color: var(--violet-soft);
  background: var(--accent-light);
  border-color: rgba(84, 53, 240, 0.25);
  box-shadow: 0 0 22px -6px rgba(84, 53, 240, 0.3);
}
.topbar-brand-logo svg { width: 20px; height: 20px; }
.topbar-brand:hover .topbar-brand-logo {
  border-color: rgba(255, 245, 130, 0.5);
  box-shadow: 0 0 26px -4px rgba(255, 245, 130, 0.45);
}
[data-theme="light"] .topbar-brand:hover .topbar-brand-logo {
  border-color: rgba(84, 53, 240, 0.5);
  box-shadow: 0 0 26px -4px rgba(84, 53, 240, 0.4);
}

.topbar-brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: var(--text-primary);
  text-shadow: 0 0 26px rgba(106, 75, 255, 0.3);
}
[data-theme="light"] .topbar-brand-name { text-shadow: none; }

/* kernel backlink pill back to the hub */
.topbar-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 7px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--panel) 60%, transparent);
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.topbar-back svg { width: 13px; height: 13px; }
.topbar-back:hover { color: var(--acid); border-color: var(--border-hover); }
[data-theme="light"] .topbar-back:hover { color: var(--violet-soft); }

.topbar-titles {
  flex: 1;
  min-width: 0;
  padding-left: 6px;
  border-left: 1px solid var(--border-color);
}

.topbar-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 26px rgba(106, 75, 255, 0.3);
}

[data-theme="light"] .topbar-title { text-shadow: none; }

.topbar-subtitle {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* compact theme toggle for the topbar (shares #theme-toggle contract) */
.topbar .theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
}
.topbar .theme-toggle svg { width: 19px; height: 19px; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px 5px 6px;
  border: 1px solid var(--border-color);
  border-radius: var(--r-full);
  background: var(--bg-secondary);
}

.topbar-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  color: #fff;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}

.topbar-email {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-logout {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  color: var(--text-tertiary);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.topbar-logout:hover { background: var(--error-soft); color: var(--error); }
.topbar-logout svg { width: 17px; height: 17px; }

/* ---- Page area ---- */

.page {
  flex: 1;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.page-wide { max-width: none; }

@media (max-width: 920px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-brand-name { display: none; }
  .topbar-back span { display: none; }
  .topbar-back { padding: 7px 9px; }
  .topbar-email { display: none; }
  .topbar-titles { padding-left: 2px; }
  .page { padding: 16px; }
}

/* ==================== Buttons ==================== */

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font-body);
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease),
              box-shadow 0.2s var(--ease), transform 0.15s var(--ease);
}
.ui-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.ui-btn:active { transform: translateY(1px); }
.ui-btn:disabled, .ui-btn.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* primary = kernel acid button with sheen sweep */
.ui-btn-primary {
  background: var(--acid);
  color: #0a0716;
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  box-shadow: 0 10px 32px -10px rgba(255, 245, 130, 0.4);
}
.ui-btn-primary::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 46%;
  left: -60%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: skewX(-18deg);
  transition: left 0.6s var(--ease);
}
.ui-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 36px -10px rgba(255, 245, 130, 0.55), 0 0 0 1px rgba(255, 245, 130, 0.4);
}
.ui-btn-primary:hover::after { left: 120%; }
.ui-btn-primary:active { transform: translateY(0); filter: brightness(0.96); }

[data-theme="light"] .ui-btn-primary {
  box-shadow: 0 10px 28px -10px rgba(196, 178, 9, 0.5);
}

.ui-btn-secondary {
  background: rgba(106, 75, 255, 0.08);
  border-color: rgba(106, 75, 255, 0.35);
  color: var(--text-primary);
}
.ui-btn-secondary:hover {
  background: rgba(106, 75, 255, 0.15);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}
[data-theme="light"] .ui-btn-secondary {
  background: rgba(84, 53, 240, 0.06);
  border-color: rgba(84, 53, 240, 0.30);
}
[data-theme="light"] .ui-btn-secondary:hover {
  background: rgba(84, 53, 240, 0.11);
}

.ui-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.ui-btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.ui-btn-danger {
  background: var(--error);
  color: #1c0509;
}
.ui-btn-danger:hover { filter: brightness(1.06); box-shadow: 0 10px 28px -10px rgba(255, 92, 114, 0.5); }

.ui-btn-danger-soft {
  background: rgba(255, 92, 114, 0.08);
  border-color: rgba(255, 92, 114, 0.4);
  color: var(--error-text);
}
.ui-btn-danger-soft:hover { background: rgba(255, 92, 114, 0.16); border-color: var(--error); }

.ui-btn-success {
  background: var(--success);
  color: #04130a;
}
.ui-btn-success:hover { filter: brightness(1.06); box-shadow: 0 10px 28px -10px rgba(74, 222, 128, 0.5); }

.ui-btn-success-soft {
  background: rgba(74, 222, 128, 0.08);
  border-color: rgba(74, 222, 128, 0.4);
  color: var(--success-text);
}
.ui-btn-success-soft:hover { background: rgba(74, 222, 128, 0.15); border-color: var(--success); }

.ui-btn-warning-soft {
  background: rgba(255, 180, 84, 0.08);
  border-color: rgba(255, 180, 84, 0.4);
  color: var(--warning-text);
}
.ui-btn-warning-soft:hover { background: rgba(255, 180, 84, 0.15); border-color: var(--warning); }

.ui-btn-sm { padding: 6px 12px; font-size: var(--fs-sm); border-radius: var(--r-xs); }
.ui-btn-sm.ui-btn-primary { font-size: 0.6875rem; }
.ui-btn-sm svg { width: 14px; height: 14px; }
.ui-btn-lg { padding: 13px 22px; font-size: var(--fs-lg); border-radius: var(--r-sm); }
.ui-btn-lg.ui-btn-primary { font-size: var(--fs-md); }

.ui-btn-icon {
  padding: 0;
  width: 36px;
  height: 36px;
}
.ui-btn-icon.ui-btn-sm { width: 30px; height: 30px; }

/* button loading state */
.ui-btn.loading { color: transparent !important; pointer-events: none; }
.ui-btn.loading::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  margin: -8px 0 0 -8px;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(10, 7, 22, 0.35);
  border-top-color: #0a0716;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}
.ui-btn-secondary.loading::before, .ui-btn-ghost.loading::before {
  border-color: var(--line-hi);
  border-top-color: var(--text-secondary);
}
.ui-btn.loading::after { display: none; }

/* ==================== Cards ==================== */

.ui-card {
  position: relative;
  background: linear-gradient(180deg, var(--panel-2), var(--panel) 60%);
  border: 1px solid var(--card-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
}

/* hairline glow along the top edge — kernel signature */
.ui-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 9%;
  right: 9%;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 130, 0.22), transparent);
}

[data-theme="light"] .ui-card {
  background: var(--panel);
}
[data-theme="light"] .ui-card::before {
  background: linear-gradient(90deg, transparent, rgba(84, 53, 240, 0.18), transparent);
}

.ui-card-pad { padding: 20px; }

.ui-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.ui-card-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 9px;
}
.ui-card-title svg { width: 18px; height: 18px; color: var(--accent-primary); }

.ui-card-body { padding: 20px; }
.ui-card-body.flush { padding: 0; }

/* ==================== KPI / stat cards (kernel .stat) ==================== */

.ui-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.ui-kpi {
  --a: var(--accent-primary);
  background: var(--tile);
  border: 1px solid var(--card-border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s var(--ease), box-shadow 0.2s var(--ease), transform 0.15s var(--ease), background 0.15s var(--ease);
}

/* 3px left accent bar */
.ui-kpi::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--a);
  opacity: 0.85;
}

.ui-kpi.clickable { cursor: pointer; }
.ui-kpi.clickable:hover {
  background: var(--tile-hi);
  border-color: color-mix(in srgb, var(--a) 45%, var(--line));
  box-shadow: 0 14px 34px -16px color-mix(in srgb, var(--a) 60%, transparent);
  transform: translateY(-2px);
}

.ui-kpi-label {
  font-size: 0.656rem;
  letter-spacing: 0.16em;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ui-kpi-label svg { width: 14px; height: 14px; }

.ui-kpi-value {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.ui-kpi-sub {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ui-kpi.accent-success { --a: var(--success); }
.ui-kpi.accent-error { --a: var(--error); }
.ui-kpi.accent-warning { --a: var(--warning); }
.ui-kpi.accent-info { --a: var(--info); }
.ui-kpi.accent-success .ui-kpi-value { color: var(--success-text); }
.ui-kpi.accent-error .ui-kpi-value { color: var(--error-text); }
.ui-kpi.accent-warning .ui-kpi-value { color: var(--warning-text); }
.ui-kpi.accent-info .ui-kpi-value { color: var(--info-text); }

/* ==================== Forms ==================== */

.ui-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }

.ui-label {
  font-size: 0.6875rem;
  letter-spacing: 0.16em;
  color: var(--text-tertiary);
}
.ui-label .req { color: var(--error); }

.ui-input, .ui-select, .ui-textarea {
  width: 100%;
  padding: 10px 13px;
  font-size: var(--fs-md);
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--r-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
  min-width: 0;
  caret-color: var(--acid);
}
[data-theme="light"] .ui-input, [data-theme="light"] .ui-select, [data-theme="light"] .ui-textarea {
  caret-color: var(--violet-soft);
}
.ui-input::placeholder, .ui-textarea::placeholder { color: #544d7d; }
[data-theme="light"] .ui-input::placeholder, [data-theme="light"] .ui-textarea::placeholder { color: #a39cc6; }
.ui-input:hover, .ui-select:hover, .ui-textarea:hover { border-color: var(--border-hover); }
.ui-input:focus, .ui-select:focus, .ui-textarea:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: var(--focus-ring);
}
.ui-input:disabled, .ui-select:disabled, .ui-textarea:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}
.ui-textarea { resize: vertical; min-height: 84px; line-height: 1.5; }

.ui-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239a92c2' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}
.ui-select option { background: var(--panel-2); color: var(--text-primary); }

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 1000px #0a0716 inset;
  transition: background-color 9999s ease-in-out 0s;
}
[data-theme="light"] input:-webkit-autofill,
[data-theme="light"] input:-webkit-autofill:hover,
[data-theme="light"] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #ffffff inset;
}

.ui-help { font-size: var(--fs-xs); color: var(--text-tertiary); font-family: var(--font-mono); letter-spacing: 0.02em; }
.ui-error-text { font-size: var(--fs-xs); color: var(--error-text); font-weight: 500; }

/* input with leading icon */
.ui-input-icon { position: relative; }
.ui-input-icon > svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: color 0.2s var(--ease);
}
.ui-input-icon:focus-within > svg { color: var(--input-focus); }
.ui-input-icon > .ui-input { padding-left: 36px; }

/* inline filter/tool rows */
.ui-toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}
.ui-toolbar .spacer { flex: 1; }

/* checkbox + switch */
.ui-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-md);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.ui-check:hover { color: var(--text-primary); }
.ui-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--acid);
  cursor: pointer;
}
[data-theme="light"] .ui-check input[type="checkbox"] { accent-color: var(--violet-soft); }

.ui-switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.ui-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.ui-switch .track {
  width: 40px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
  flex-shrink: 0;
}
.ui-switch .track::after {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  margin: 2px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
}
.ui-switch input:checked + .track { background: rgba(255, 245, 130, 0.18); border-color: rgba(255, 245, 130, 0.5); }
.ui-switch input:checked + .track::after { transform: translateX(18px); background: var(--acid); }
[data-theme="light"] .ui-switch input:checked + .track { background: var(--accent-light); border-color: var(--violet-soft); }
[data-theme="light"] .ui-switch input:checked + .track::after { background: var(--violet-soft); }
.ui-switch input:focus-visible + .track { box-shadow: var(--focus-ring); }

/* ==================== Tables (kernel .tbl) ==================== */

.ui-table-wrap {
  overflow-x: auto;
  border-radius: var(--r-lg);
  background: rgba(5, 3, 12, 0.35);
}
[data-theme="light"] .ui-table-wrap { background: transparent; }
.ui-card > .ui-table-wrap { border-radius: 0 0 var(--r-lg) var(--r-lg); }

.ui-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-md);
}

.ui-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 0.656rem;
  letter-spacing: 0.16em;
  color: var(--text-tertiary);
  background: var(--panel-2);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.ui-table td {
  padding: 12px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  color: var(--text-secondary);
  vertical-align: middle;
}

.ui-table td strong { color: var(--text-primary); font-weight: 600; }

.ui-table tbody tr { transition: background 0.12s var(--ease); }
.ui-table tbody tr:hover { background: rgba(106, 75, 255, 0.06); }
[data-theme="light"] .ui-table tbody tr:hover { background: rgba(84, 53, 240, 0.045); }
.ui-table tbody tr:last-child td { border-bottom: none; }

.ui-table .num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.ui-table .nowrap { white-space: nowrap; }
.ui-table .muted { color: var(--text-tertiary); }

.ui-table th.sortable { cursor: pointer; user-select: none; }
.ui-table th.sortable:hover { color: var(--text-primary); }

/* row actions cell */
.ui-row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ==================== Badges / chips (kernel .pill) ==================== */

.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--neutral-text);
}
.ui-badge svg { width: 12px; height: 12px; }
.ui-badge .dot { width: 6px; height: 6px; border-radius: 2px; background: currentColor; }

.ui-badge-success { background: var(--success-soft); border-color: rgba(74, 222, 128, 0.35); color: var(--success-text); }
.ui-badge-error   { background: var(--error-soft);   border-color: rgba(255, 92, 114, 0.35); color: var(--error-text); }
.ui-badge-warning { background: var(--warning-soft); border-color: rgba(255, 180, 84, 0.35); color: var(--warning-text); }
.ui-badge-info    { background: var(--info-soft);    border-color: rgba(91, 140, 255, 0.35); color: var(--info-text); }
.ui-badge-purple  { background: var(--purple-soft);  border-color: rgba(160, 107, 255, 0.35); color: var(--purple-text); }

[data-theme="light"] .ui-badge-success { border-color: rgba(24, 165, 90, 0.35); }
[data-theme="light"] .ui-badge-error   { border-color: rgba(224, 53, 80, 0.32); }
[data-theme="light"] .ui-badge-warning { border-color: rgba(217, 131, 22, 0.35); }
[data-theme="light"] .ui-badge-info    { border-color: rgba(63, 108, 224, 0.32); }
[data-theme="light"] .ui-badge-purple  { border-color: rgba(139, 92, 246, 0.32); }

.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}
.ui-chip button {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
}
.ui-chip button:hover { background: var(--error-soft); color: var(--error-text); }

/* ==================== Tabs ==================== */

.ui-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(5, 3, 12, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--r-md);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
[data-theme="light"] .ui-tabs { background: var(--panel-2); }
.ui-tabs.full { width: 100%; }
.ui-tabs.full .ui-tab { flex: 1; }

.ui-tab {
  appearance: none;
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  position: relative;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.ui-tab svg { width: 15px; height: 15px; }
.ui-tab:hover { color: var(--text-primary); }
.ui-tab.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: inset 0 -2px 0 var(--acid);
}
[data-theme="light"] .ui-tab.active {
  background: #ffffff;
  box-shadow: inset 0 -2px 0 var(--violet-soft), var(--shadow-sm);
}
.ui-tab .count {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--neutral-soft);
  color: var(--neutral-text);
}
.ui-tab.active .count { background: var(--acid-soft); color: var(--acid); }
[data-theme="light"] .ui-tab.active .count { background: var(--accent-light); color: var(--violet-soft); }

/* ==================== Modal ==================== */

.ui-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 3, 12, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: ui-fade-in 0.18s var(--ease);
}
.ui-modal-overlay.hidden { display: none; }

.ui-modal {
  position: relative;
  background: linear-gradient(180deg, var(--panel-2), var(--panel) 60%);
  border: 1px solid var(--card-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  animation: ui-pop-in 0.22s var(--ease);
  overflow: hidden;
}
[data-theme="light"] .ui-modal { background: var(--panel); }

/* top hairline */
.ui-modal::before {
  content: '';
  position: absolute;
  top: 0;
  left: 9%;
  right: 9%;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 130, 0.3), transparent);
}
[data-theme="light"] .ui-modal::before {
  background: linear-gradient(90deg, transparent, rgba(84, 53, 240, 0.2), transparent);
}

.ui-modal.lg { max-width: 860px; }
.ui-modal.xl { max-width: 1140px; }

.ui-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.ui-modal-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.ui-modal-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.ui-modal-close:hover { background: var(--bg-hover); color: var(--acid); }
[data-theme="light"] .ui-modal-close:hover { color: var(--violet-soft); }

.ui-modal-body { padding: 22px; overflow-y: auto; }

.ui-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* ==================== Toasts (canonical + legacy compat) ==================== */

#notification-wrapper, #notification-container,
.notification-wrapper, .notification-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 36px));
  pointer-events: none;
}

.notification {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--accent-primary);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-weight: 500;
  position: relative;
  overflow: hidden;
  animation: ui-toast-in 0.25s var(--ease);
}
[data-theme="light"] .notification { background: var(--panel); }

.notification.success, .notification-success { border-left-color: var(--success); }
.notification.error, .notification-error { border-left-color: var(--error); }
.notification.warning, .notification-warning { border-left-color: var(--warning); }
.notification.info, .notification-info { border-left-color: var(--info); }

.notification-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.notification.success .notification-icon, .notification-success .notification-icon { color: var(--success); }
.notification.error .notification-icon, .notification-error .notification-icon { color: var(--error); }
.notification.warning .notification-icon, .notification-warning .notification-icon { color: var(--warning); }
.notification.info .notification-icon, .notification-info .notification-icon { color: var(--info); }
.notification-icon svg { width: 100%; height: 100%; }

.notification-content, .notification-text, .notification-message {
  flex: 1;
  min-width: 0;
  word-wrap: break-word;
  line-height: 1.45;
}

.notification-close {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.notification-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.notification-close svg { width: 13px; height: 13px; }

.notification-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: currentColor;
  opacity: 0.3;
  animation: ui-timer 4s linear forwards;
}

.notification.fade-out { animation: ui-toast-out 0.25s var(--ease) forwards; }

/* ==================== Empty / loading states ==================== */

.ui-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-tertiary);
}
.ui-empty svg { width: 44px; height: 44px; opacity: 0.4; }
.ui-empty-title { font-size: var(--fs-lg); font-weight: 700; color: var(--text-secondary); }
.ui-empty-text { font-size: var(--fs-md); max-width: 380px; }

.ui-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--acid);
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}
[data-theme="light"] .ui-spinner { border-top-color: var(--violet-soft); }
.ui-spinner.lg { width: 34px; height: 34px; border-width: 3px; }

.ui-loading-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 24px;
  color: var(--text-tertiary);
  font-size: var(--fs-md);
  font-family: var(--font-mono);
}

.ui-skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-tertiary);
  border-radius: var(--r-xs);
  min-height: 14px;
}
.ui-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(106, 75, 255, 0.10), transparent);
  animation: ui-shimmer 1.4s infinite;
}

/* ==================== Progress ==================== */

.ui-progress {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--r-full);
  overflow: hidden;
}
.ui-progress-bar {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--violet-soft), var(--acid));
  box-shadow: 0 0 14px -2px rgba(255, 245, 130, 0.45);
  transition: width 0.3s var(--ease);
  min-width: 0;
}

/* ==================== Pagination ==================== */

.ui-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px 0;
  flex-wrap: wrap;
}
.ui-pagination .info {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.ui-pagination .pages { display: flex; gap: 5px; }

.ui-page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: var(--r-xs);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.ui-page-btn:hover:not(:disabled) { border-color: var(--accent-primary); color: var(--text-primary); }
.ui-page-btn.active {
  background: var(--acid);
  border-color: var(--acid);
  color: #0a0716;
  font-weight: 600;
}
[data-theme="light"] .ui-page-btn.active {
  background: var(--violet-soft);
  border-color: var(--violet-soft);
  color: #fff;
}
.ui-page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ==================== Dropdown menu ==================== */

.ui-menu {
  position: absolute;
  min-width: 180px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-hi);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: var(--z-dropdown);
  animation: ui-pop-in 0.14s var(--ease);
}
[data-theme="light"] .ui-menu { background: var(--panel); }
.ui-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-family: var(--font-body);
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s var(--ease);
}
.ui-menu-item:hover { background: var(--bg-hover); }
.ui-menu-item.danger { color: var(--error-text); }
.ui-menu-item.danger:hover { background: var(--error-soft); }
.ui-menu-item svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ==================== Upload dropzone ==================== */

.ui-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 34px 20px;
  border: 2px dashed var(--line-hi);
  border-radius: var(--r-md);
  background: rgba(5, 3, 12, 0.35);
  color: var(--text-tertiary);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
[data-theme="light"] .ui-dropzone { background: var(--panel-2); }
.ui-dropzone:hover, .ui-dropzone.dragover {
  border-color: var(--acid);
  background: rgba(255, 245, 130, 0.04);
  color: var(--acid);
  box-shadow: 0 0 30px -10px rgba(255, 245, 130, 0.25);
}
[data-theme="light"] .ui-dropzone:hover, [data-theme="light"] .ui-dropzone.dragover {
  border-color: var(--violet-soft);
  background: var(--accent-light);
  color: var(--violet-soft);
  box-shadow: none;
}
.ui-dropzone svg { width: 30px; height: 30px; }
.ui-dropzone strong { color: var(--text-secondary); font-size: var(--fs-md); }
.ui-dropzone small { font-family: var(--font-mono); font-size: var(--fs-xs); }

/* ==================== Misc utilities ==================== */

.ui-divider { height: 1px; background: var(--border-color); border: none; margin: 16px 0; }

.ui-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ui-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 760px) {
  .ui-grid-2, .ui-grid-3 { grid-template-columns: 1fr; }
}

.ui-stack { display: flex; flex-direction: column; gap: 14px; }
.ui-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.text-muted { color: var(--text-tertiary); }
.text-success { color: var(--success-text); }
.text-error { color: var(--error-text); }
.text-warning { color: var(--warning-text); }
.font-mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.ui-section-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  margin: 26px 0 14px;
}
.ui-section-title:first-child { margin-top: 0; }

/* copyable code/value pill */
.ui-code-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: var(--r-xs);
  background: rgba(5, 3, 12, 0.5);
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
[data-theme="light"] .ui-code-pill { background: var(--panel-2); }
.ui-code-pill:hover { border-color: var(--acid); color: var(--acid); }
[data-theme="light"] .ui-code-pill:hover { border-color: var(--violet-soft); color: var(--violet-soft); }
.ui-code-pill svg { width: 13px; height: 13px; color: var(--text-tertiary); }

/* ==================== Keyframes (single source of truth) ==================== */

@keyframes ui-spin { to { transform: rotate(360deg); } }

@keyframes ui-fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes ui-pop-in {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes ui-toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes ui-toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(24px); }
}

@keyframes ui-timer { from { width: 100%; } to { width: 0%; } }

@keyframes ui-shimmer { to { transform: translateX(100%); } }

/* kernel entrance */
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* legacy keyframe aliases still referenced by old inline styles / page JS */
@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(24px); }
  6% { opacity: 1; transform: translateX(0); }
  94% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(24px); }
}
@keyframes timerBar { from { width: 100%; } to { width: 0%; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
