/* ==========================================================================
   Ninja EMP — Tenant UI design system
   Tokens + components. Themes are pure CSS custom properties, selected by
   [data-theme] (palette) and [data-mode] (light|dark). Components reference
   ONLY tokens — never hard-coded colors — so adding a theme is CSS-only.
   ========================================================================== */

/* ---- Reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, h4, h5, h6, p { margin: 0; }

/* ---- Base tokens (shared across themes) -------------------------------- */
:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10), 0 2px 4px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16), 0 4px 8px rgba(15, 23, 42, 0.08);

  --sidebar-w: 208px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 60px;

  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Neutral · light --------------------------------------------------- */
[data-theme="neutral"][data-mode="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;
  --surface-inset: #eef1f5;
  --border: #e3e7ec;
  --border-strong: #cdd4dd;
  --text: #1a2230;
  --text-muted: #5b6675;
  --text-subtle: #626e7c;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;
  --accent-contrast: #ffffff;
  --sidebar-bg: #ffffff;
  --sidebar-text: #3a4453;
  --sidebar-muted: #626e7c;
  --sidebar-active-bg: #eef0fe;
  --sidebar-active-text: #4338ca;
  --sidebar-border: #e9ecf1;
  --success: #0b7a43;
  --success-soft: #e6f6ee;
  --warning: #b7791f;
  --warning-soft: #fdf3e2;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --focus: #6366f1;
  --overlay: rgba(15, 23, 42, 0.45);
}

/* ---- Neutral · dark ---------------------------------------------------- */
[data-theme="neutral"][data-mode="dark"] {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1b2129;
  --surface-3: #212832;
  --surface-inset: #10151b;
  --border: #262d38;
  --border-strong: #333c49;
  --text: #e8ecf1;
  --text-muted: #9aa5b4;
  --text-subtle: #7d8b9c;
  --accent: #7c7cf5;
  --accent-hover: #8f8ff7;
  --accent-soft: #1e2138;
  --accent-contrast: #0e1116;
  --sidebar-bg: #12161d;
  --sidebar-text: #b6c0cd;
  --sidebar-muted: #7d8b9c;
  --sidebar-active-bg: #1e2138;
  --sidebar-active-text: #a5a5f8;
  --sidebar-border: #1f2630;
  --success: #34d399;
  --success-soft: #10281f;
  --warning: #fbbf24;
  --warning-soft: #2a2210;
  --danger: #f87171;
  --danger-soft: #2c1616;
  --info: #60a5fa;
  --info-soft: #12203a;
  --focus: #8f8ff7;
  --overlay: rgba(0, 0, 0, 0.6);
}

/* ---- Dark-blue · light ------------------------------------------------ */
[data-theme="dark-blue"][data-mode="light"] {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f8;
  --surface-inset: #e9eef6;
  --border: #dde4ee;
  --border-strong: #c3cede;
  --text: #14213d;
  --text-muted: #4a5a76;
  --text-subtle: #5c6b84;
  --accent: #1e3a8a;
  --accent-hover: #1b3479;
  --accent-soft: #e7ecf8;
  --accent-contrast: #ffffff;
  --sidebar-bg: #14213d;
  --sidebar-text: #c3cede;
  --sidebar-muted: #7c8aa3;
  --sidebar-active-bg: #1e3a8a;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #22304f;
  --success: #0b7a43;
  --success-soft: #e6f6ee;
  --warning: #b7791f;
  --warning-soft: #fdf3e2;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --focus: #3b5bdb;
  --overlay: rgba(15, 23, 42, 0.45);
}

/* ---- Dark-blue · dark -------------------------------------------------- */
[data-theme="dark-blue"][data-mode="dark"] {
  --bg: #0a1020;
  --surface: #111a30;
  --surface-2: #16203a;
  --surface-3: #1c2846;
  --surface-inset: #0c1426;
  --border: #22304f;
  --border-strong: #2f4066;
  --text: #e6ecf7;
  --text-muted: #9fb0cc;
  --text-subtle: #8493a6;
  --accent: #5b8def;
  --accent-hover: #6f9bf2;
  --accent-soft: #16233f;
  --accent-contrast: #0a1020;
  --sidebar-bg: #0c1426;
  --sidebar-text: #b3c2dd;
  --sidebar-muted: #8493a6;
  --sidebar-active-bg: #1e3a8a;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #1a2540;
  --success: #34d399;
  --success-soft: #0f2a22;
  --warning: #fbbf24;
  --warning-soft: #2a2210;
  --danger: #f87171;
  --danger-soft: #2c1616;
  --info: #60a5fa;
  --info-soft: #12203a;
  --focus: #6f9bf2;
  --overlay: rgba(0, 0, 0, 0.6);
}

/* ---- Base element styling --------------------------------------------- */
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

/* ---- Typography helpers ------------------------------------------------ */
.h1 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; }
.h2 { font-size: var(--text-xl); font-weight: 650; letter-spacing: -0.01em; }
.h3 { font-size: var(--text-lg); font-weight: 600; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.strong { font-weight: 600; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

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

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }

.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-lg { height: 46px; padding: 0 var(--space-6); font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Inputs ------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field > label { font-size: var(--text-sm); font-weight: 550; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { height: auto; padding: var(--space-3); resize: vertical; min-height: 84px; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* Windows paints a styled select's highlight with the option color, so the
   label vanishes on hover unless the popup colors are set explicitly. */
[data-mode="light"] select {
  color-scheme: light;
}
[data-mode="light"] select option {
  background-color: var(--surface);
  color: var(--text);
}
[data-mode="light"] select option:hover,
[data-mode="light"] select option:focus,
[data-mode="light"] select option:checked {
  background-color: var(--accent);
  color: var(--accent-contrast);
}
.input::placeholder { color: var(--text-subtle); }

/* ---- Cards ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-body { padding: var(--space-5); }
.card-foot {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---- Badges / pills ---------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }
.badge-dot::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Stat cards -------------------------------------------------------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}
.stat-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: var(--space-2);
  font-variant-numeric: tabular-nums;
}
.stat-delta { font-size: var(--text-sm); margin-top: var(--space-1); }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ---- Progress ---------------------------------------------------------- */
.progress { height: 8px; border-radius: var(--radius-full); background: var(--surface-inset); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---- Empty state ------------------------------------------------------- */
.empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}
.empty svg { width: 40px; height: 40px; margin: 0 auto var(--space-4); color: var(--text-subtle); }

/* ---- Flash / alerts ---------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: var(--text-base);
}
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.alert-info    { background: var(--info-soft);    border-color: transparent; color: var(--info); }

/* ---- Segmented control ------------------------------------------------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-inset);
  border-radius: var(--radius);
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px var(--space-3);
  border-radius: calc(var(--radius) - 3px);
  font-size: var(--text-sm);
  font-weight: 550;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
.segmented .seg-btn {
  display: inline-block;
  padding: 5px var(--space-3);
  border-radius: calc(var(--radius) - 3px);
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text-muted);
  cursor: pointer;
}
.segmented .seg-btn.is-selected,
.segmented .seg-btn:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ---- Utility ----------------------------------------------------------- */
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: var(--space-5); }
.cols-2, .cols-3, .cols-4, .form-split, .split-aside { grid-template-columns: 1fr; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (min-width: 45rem) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-split, .split-aside { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}
@media (min-width: 68.75rem) {
  .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
