/* ============================================
   WCorp Dashboard — Design Tokens & Globals
   ============================================ */

:root {
  /* Type */
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "JetBrains Mono", monospace;

  /* Accent (overridden by tweaks) */
  --accent: oklch(0.78 0.16 175);
  --accent-strong: oklch(0.7 0.16 175);
  --accent-soft: oklch(0.78 0.16 175 / 0.14);
  --accent-fg: #00120e;

  /* Status */
  --danger: oklch(0.68 0.2 25);
  --danger-soft: oklch(0.68 0.2 25 / 0.14);
  --warn: oklch(0.82 0.16 75);
  --warn-soft: oklch(0.82 0.16 75 / 0.14);
  --ok: oklch(0.74 0.16 155);
  --ok-soft: oklch(0.74 0.16 155 / 0.14);
  --info: oklch(0.74 0.13 240);
  --info-soft: oklch(0.74 0.13 240 / 0.14);

  /* Density */
  --row-h: 36px;
  --pad-x: 20px;
  --radius: 8px;
  --radius-sm: 5px;
}

[data-theme="dark"] {
  /* Slate, very subtle blue-green tint */
  --bg: oklch(0.18 0.01 200);
  --bg-1: oklch(0.21 0.01 200);
  --bg-2: oklch(0.24 0.012 200);
  --bg-3: oklch(0.28 0.014 200);
  --bg-hover: oklch(0.26 0.013 200);
  --line: oklch(0.32 0.013 200);
  --line-soft: oklch(0.27 0.012 200);

  --fg: oklch(0.96 0.005 200);
  --fg-1: oklch(0.78 0.008 200);
  --fg-2: oklch(0.6 0.01 200);
  --fg-3: oklch(0.45 0.012 200);

  --shadow-1: 0 1px 0 oklch(1 0 0 / 0.04) inset, 0 0 0 1px oklch(0 0 0 / 0.2);
  --shadow-pop: 0 8px 24px -8px oklch(0 0 0 / 0.5), 0 0 0 1px oklch(1 0 0 / 0.04);
}

[data-theme="light"] {
  --bg: oklch(0.985 0.003 200);
  --bg-1: oklch(1 0 0);
  --bg-2: oklch(0.97 0.005 200);
  --bg-3: oklch(0.94 0.007 200);
  --bg-hover: oklch(0.96 0.006 200);
  --line: oklch(0.88 0.01 200);
  --line-soft: oklch(0.92 0.008 200);

  --fg: oklch(0.18 0.013 200);
  --fg-1: oklch(0.34 0.012 200);
  --fg-2: oklch(0.5 0.012 200);
  --fg-3: oklch(0.65 0.012 200);

  --accent: oklch(0.62 0.14 175);
  --accent-strong: oklch(0.55 0.14 175);
  --accent-soft: oklch(0.62 0.14 175 / 0.14);
  --accent-fg: #ffffff;

  --shadow-1: 0 1px 0 oklch(1 0 0 / 0.6) inset, 0 0 0 1px oklch(0 0 0 / 0.04);
  --shadow-pop: 0 8px 24px -8px oklch(0 0 0 / 0.16), 0 0 0 1px oklch(0 0 0 / 0.04);
}

/* Density variants */
[data-density="comfortable"] { --row-h: 44px; --pad-x: 24px; }
[data-density="compact"]     { --row-h: 32px; --pad-x: 16px; }

/* ============================================
   Reset
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.display {
  font-family: "Instrument Serif", "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: -0.025em;
  font-style: italic;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
input:focus, select:focus, textarea:focus, button:focus { outline: none; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--fg); }

/* ============================================
   Layout
   ============================================ */
.app {
  display: grid;
  grid-template-columns: 56px 1fr;
  height: 100vh;
  background: var(--bg);
}
.app[data-sidebar="wide"] { grid-template-columns: 220px 1fr; }

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: var(--bg);
}
.sidebar-brand {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  color: var(--fg);
  font-weight: 600; font-size: 16px;
  letter-spacing: -0.04em;
  flex-shrink: 0;
  font-family: "Instrument Serif", serif;
  font-style: italic;
}
.brand-name { font-weight: 500; letter-spacing: -0.025em; font-size: 14.5px; color: var(--fg); }
.brand-name .dot { color: var(--accent); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 1px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  height: 34px;
  border-radius: 6px;
  color: var(--fg-2);
  font-size: 13px;
  position: relative;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--fg); }
.nav-item[data-active="true"] {
  background: transparent;
  color: var(--fg);
  font-weight: 500;
}
.nav-item[data-active="true"] .nav-icon { color: var(--accent); }
.app[data-sidebar="narrow"] .nav-item { justify-content: center; padding: 0; }
.app[data-sidebar="narrow"] .nav-item .nav-label { display: none; }
.app[data-sidebar="narrow"] .sidebar-brand { justify-content: center; padding: 0; }
.app[data-sidebar="narrow"] .brand-name { display: none; }


.nav-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-badge {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.app[data-sidebar="narrow"] .nav-badge {
  position: absolute;
  top: 2px; right: 2px;
  margin: 0;
  font-size: 9px;
  padding: 0 4px;
  min-width: 14px;
  height: 14px;
  display: grid; place-items: center;
}

.sidebar-foot {
  padding: 8px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Main panel */
.main {
  display: grid;
  grid-template-rows: 56px 1fr;
  min-width: 0;
  min-height: 0;
}

/* Topbar */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--pad-x);
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.topbar-title .crumb { color: var(--fg-3); }
.topbar-title .sep { color: var(--fg-3); opacity: 0.5; }
.topbar-spacer { flex: 1; }

/* Search / cmd palette */
.cmd-input {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 10px 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--fg-3);
  width: 240px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.cmd-input:hover { background: var(--bg-2); border-color: var(--line-soft); }
.cmd-input:hover { border-color: var(--line); }
.cmd-input .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--fg-3);
}

/* Content */
.content {
  overflow-y: auto;
  padding: 0;
  background: var(--bg);
}

/* ============================================
   Reusable primitives
   ============================================ */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  color: var(--fg);
  transition: background 0.1s, border-color 0.1s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--line); }
.btn:active { transform: translateY(0.5px); }
.btn[data-variant="primary"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.15);
}
.btn[data-variant="primary"]:hover {
  background: var(--accent-strong);
}
.btn[data-variant="ghost"] {
  background: transparent;
  border-color: transparent;
  color: var(--fg-2);
}
.btn[data-variant="ghost"]:hover { background: var(--bg-hover); color: var(--fg); }
.btn[data-variant="danger"] {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}
.btn[data-variant="danger"]:hover { background: var(--danger); color: white; }
.btn[data-size="sm"] { height: 26px; padding: 0 8px; font-size: 12px; gap: 4px; }
.btn[data-size="xs"] { height: 22px; padding: 0 6px; font-size: 11px; gap: 4px; }
.btn[data-square] { padding: 0; width: 30px; }
.btn[data-square][data-size="sm"] { width: 26px; }
.btn[data-square][data-size="xs"] { width: 22px; }
.btn .ic { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.btn[data-size="sm"] .ic { width: 13px; height: 13px; }
.btn[data-size="xs"] .ic { width: 12px; height: 12px; }

/* Card */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-h {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-h h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card-h .sub {
  color: var(--fg-3);
  font-size: 12px;
}

/* Pill / badge */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-3);
  color: var(--fg-1);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill[data-tone="ok"]      { background: var(--ok-soft); color: var(--ok); }
.pill[data-tone="warn"]    { background: var(--warn-soft); color: var(--warn); }
.pill[data-tone="danger"]  { background: var(--danger-soft); color: var(--danger); }
.pill[data-tone="info"]    { background: var(--info-soft); color: var(--info); }
.pill[data-tone="accent"]  { background: var(--accent-soft); color: var(--accent); }
.pill .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.pill .dot[data-pulse="true"] {
  animation: pulse-dot 1.6s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px transparent; }
}

/* Form controls */
.input, .select, .textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--fg);
  font-size: 13px;
  padding: 0 10px;
  height: 32px;
  transition: border-color 0.1s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  background: var(--bg-1);
}
.textarea { padding: 8px 10px; height: auto; resize: vertical; min-height: 80px; font-family: var(--font-mono); font-size: 12px; }
.input::placeholder { color: var(--fg-3); }

.label {
  display: block;
  font-size: 12px;
  color: var(--fg-2);
  margin-bottom: 6px;
  font-weight: 500;
}

/* Toggle switch */
.switch {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--bg-3);
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  flex-shrink: 0;
  transition: background 0.15s;
  cursor: pointer;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--fg-2);
  transition: all 0.15s;
}
.switch[data-on="true"] {
  background: var(--accent);
  border-color: transparent;
}
.switch[data-on="true"]::after {
  left: 16px;
  background: var(--accent-fg);
}

/* Avatars */
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0;
}
.avatar[data-size="sm"] { width: 22px; height: 22px; font-size: 10px; }
.avatar[data-size="lg"] { width: 36px; height: 36px; font-size: 13px; }

/* Scrollbar */
.content::-webkit-scrollbar, .scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.content::-webkit-scrollbar-thumb, .scroll::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: 10px;
  border: 2px solid var(--bg);
}
.content::-webkit-scrollbar-thumb:hover, .scroll::-webkit-scrollbar-thumb:hover {
  background: var(--line);
}

/* Mono */
.mono { font-family: var(--font-mono); font-size: 12px; }
.tnum { font-variant-numeric: tabular-nums; }

/* Utility */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.dim { color: var(--fg-2); }
.dim-2 { color: var(--fg-3); }
.muted { color: var(--fg-3); }
.divider { height: 1px; background: var(--line-soft); }
.vdivider { width: 1px; align-self: stretch; background: var(--line-soft); }
.spacer { flex: 1; }

/* Page padding */
.page {
  padding: 20px var(--pad-x);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.page-head h1 {
  margin: 0;
  font-size: 38px;
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1;
  font-family: "Instrument Serif", "Times New Roman", serif;
}
.page-head h1 em { color: var(--accent); font-style: italic; }
.page-head p { margin: 8px 0 0; color: var(--fg-2); font-size: 13px; }
.page { padding: 28px var(--pad-x) 32px; gap: 22px; }

/* Stat tile — editorial */
.stat {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  position: relative;
}
.stat .label { margin-bottom: 0; font-size: 11px; color: var(--fg-2); letter-spacing: 0.04em; font-weight: 500; text-transform: uppercase; }
.stat .value { font-size: 36px; font-weight: 400; letter-spacing: -0.035em; font-variant-numeric: tabular-nums; line-height: 1; font-family: "Instrument Serif", serif; }
.stat .value-num { font-family: var(--font-sans); font-weight: 500; font-size: 32px; letter-spacing: -0.03em; }
.stat .delta { font-size: 11px; color: var(--fg-3); display: flex; align-items: center; gap: 5px; }
.stat .delta[data-trend="up"] { color: var(--ok); }
.stat .delta[data-trend="down"] { color: var(--danger); }
.stat-hero {
  grid-column: span 2;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 24px 28px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
}
.stat-hero .label { font-size: 11px; color: var(--fg-2); letter-spacing: 0.06em; font-weight: 500; text-transform: uppercase; margin-bottom: 12px; }
.stat-hero .value { font-size: 84px; font-weight: 400; letter-spacing: -0.045em; font-variant-numeric: tabular-nums; line-height: 0.92; font-family: "Instrument Serif", serif; }
.stat-hero .value em { font-style: italic; color: var(--accent); }
.stat-hero .value sub { font-size: 28px; color: var(--fg-3); font-style: normal; vertical-align: baseline; margin-left: 4px; }
.stat-hero .ctx { color: var(--fg-2); font-size: 12.5px; max-width: 280px; line-height: 1.5; margin-top: 12px; }
.stat-hero .side { display: flex; flex-direction: column; gap: 14px; align-items: flex-end; min-width: 200px; }

/* Table */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl td {
  padding: 0 12px;
  height: var(--row-h);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.tbl tr:hover td { background: var(--bg-hover); }
.tbl tr[data-selected="true"] td { background: var(--accent-soft); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--fg-3);
}

/* ============================================
   Sparkline / heatmap
   ============================================ */
.spark {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 18px;
}
.spark-bar {
  width: 3px;
  background: var(--accent);
  border-radius: 1px;
  flex-shrink: 0;
  opacity: 0.85;
}
.heat {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 1px;
  height: 14px;
}
.heat-cell {
  background: var(--bg-3);
  border-radius: 1px;
}
.heat-cell[data-l="1"] { background: var(--accent-soft); }
.heat-cell[data-l="2"] { background: oklch(from var(--accent) l c h / 0.4); }
.heat-cell[data-l="3"] { background: oklch(from var(--accent) l c h / 0.7); }
.heat-cell[data-l="4"] { background: var(--accent); }
.heat-cell[data-l="warn"] { background: var(--warn); }
.heat-cell[data-l="danger"] { background: var(--danger); }

/* Threat meter */
.threat {
  display: flex;
  gap: 2px;
  align-items: center;
}
.threat-pip {
  width: 4px;
  height: 10px;
  background: var(--bg-3);
  border-radius: 1px;
}
.threat[data-level="low"] .threat-pip:nth-child(-n+1) { background: var(--ok); }
.threat[data-level="med"] .threat-pip:nth-child(-n+2) { background: var(--warn); }
.threat[data-level="high"] .threat-pip:nth-child(-n+3) { background: var(--danger); }
.threat[data-level="crit"] .threat-pip { background: var(--danger); }

/* Live dot */
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 oklch(from var(--danger) l c h / 0.5);
  animation: live-pulse 2s ease-out infinite;
  flex-shrink: 0;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 oklch(from var(--danger) l c h / 0.5); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* Modal / dialog (simple) */
.modal-backdrop {
  position: fixed; inset: 0;
  background: oklch(0 0 0 / 0.5);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.modal {
  position: fixed;
  z-index: 91;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  width: 480px;
  max-width: 90vw;
  overflow: hidden;
}

/* Toast */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  min-width: 280px;
  max-width: 360px;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.toast[data-tone="ok"] { border-left: 2px solid var(--ok); }
.toast[data-tone="warn"] { border-left: 2px solid var(--warn); }
.toast[data-tone="danger"] { border-left: 2px solid var(--danger); }

/* Dropdown menu */
.menu {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  padding: 4px;
  min-width: 180px;
  z-index: 50;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  color: var(--fg);
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item .ic { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.5; fill: none; }
.menu-item .kbd { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }
.menu-sep { height: 1px; background: var(--line-soft); margin: 4px 0; }
