/* ============================================================
   OrgLens — Design System Tokens
   ============================================================ */

:root {
  /* Brand — primary is tweakable via --primary */
  --primary: #2c4fe0;           /* shifted from salesforce blue into a more distinctive cobalt */
  --primary-hover: color-mix(in oklab, var(--primary) 88%, black);
  --primary-press: color-mix(in oklab, var(--primary) 76%, black);
  --primary-tint: color-mix(in oklab, var(--primary) 10%, transparent);
  --primary-ink: #ffffff;        /* text on primary */

  /* Accent — used sparingly for risk / call-outs */
  --accent: #ff5a1f;

  /* Semantic */
  --success: #0f8a5f;
  --warning: #b36b00;
  --danger:  #c6301c;
  --info:    var(--primary);

  /* Risk-specific (design system commits to color+icon+label) */
  --risk-high:   #c6301c;
  --risk-med:    #b36b00;
  --risk-low:    #667388;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl: 24px;
  --r-full: 9999px;

  /* Space — 4px grid */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --s-20: 80px;
  --s-24: 96px;

  /* Type scale */
  --font-sans: "General Sans", "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-serif: "Fraunces", "Newsreader", Georgia, serif;

  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-28: 28px;
  --fs-32: 32px;
  --fs-40: 40px;
  --fs-48: 48px;
  --fs-56: 56px;
  --fs-72: 72px;

  --lh-tight: 1.1;
  --lh-snug:  1.25;
  --lh-base:  1.45;
  --lh-loose: 1.65;

  /* Transitions */
  --dur-fast: 120ms;
  --dur:      200ms;
  --dur-slow: 360ms;
  --ease:     cubic-bezier(0.2, 0.8, 0.2, 1);

  /* LIGHT palette (default) */
  --bg:         #fafaf7;         /* warm parchment */
  --bg-alt:     #f3f2ec;
  --surface:    #ffffff;
  --surface-2:  #f7f6f0;
  --surface-3:  #edebe3;
  --hover:      rgba(15, 18, 28, 0.04);
  --border:     #e3dfd3;
  --border-strong: #cfcabb;
  --divider:    #eae6da;

  --text:       #121620;         /* near-black, cool */
  --text-2:     #3a3f4c;
  --text-3:     #6a6e7b;
  --text-4:     #989aa3;

  --shadow-xs: 0 1px 0 rgba(15, 18, 28, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 18, 28, 0.06), 0 0 0 1px rgba(15, 18, 28, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 18, 28, 0.08), 0 0 0 1px rgba(15, 18, 28, 0.04);
  --shadow-lg: 0 16px 40px rgba(15, 18, 28, 0.12), 0 0 0 1px rgba(15, 18, 28, 0.06);
  --shadow-inner: inset 0 1px 0 rgba(255, 255, 255, 0.5);

  --focus-ring: 0 0 0 3px color-mix(in oklab, var(--primary) 30%, transparent);

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:         #0b0d12;
  --bg-alt:     #0f1219;
  --surface:    #14171f;
  --surface-2:  #191d26;
  --surface-3:  #222733;
  --hover:      rgba(255, 255, 255, 0.04);
  --border:     #262b36;
  --border-strong: #363c4a;
  --divider:    #1e222c;

  --text:       #eef1f7;
  --text-2:     #bcc3d0;
  --text-3:     #858c9a;
  --text-4:     #5d6371;

  --primary-ink: #ffffff;
  --primary-tint: color-mix(in oklab, var(--primary) 20%, transparent);

  --shadow-xs: 0 1px 0 rgba(0,0,0,0.4);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.03);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  --shadow-inner: inset 0 1px 0 rgba(255, 255, 255, 0.04);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-15);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

::selection { background: var(--primary); color: var(--primary-ink); }

/* Utility */
.mono { font-family: var(--font-mono); font-feature-settings: "zero", "ss01"; }
.serif { font-family: var(--font-serif); }
.small-caps { font-variant-caps: all-small-caps; letter-spacing: 0.06em; }
.num { font-variant-numeric: tabular-nums; }

.h1 { font-size: var(--fs-48); line-height: var(--lh-tight); letter-spacing: -0.03em; font-weight: 540; }
.h2 { font-size: var(--fs-32); line-height: var(--lh-snug); letter-spacing: -0.02em; font-weight: 540; }
.h3 { font-size: var(--fs-24); line-height: var(--lh-snug); letter-spacing: -0.015em; font-weight: 540; }
.h4 { font-size: var(--fs-18); line-height: var(--lh-snug); letter-spacing: -0.01em; font-weight: 540; }
.eyebrow {
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 540;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-feature-settings: "zero";
}

/* Focus */
:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

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

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-weight: 540;
  font-size: var(--fs-14);
  letter-spacing: -0.005em;
  line-height: 1;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { transform: translateY(-0.5px); }
.btn:active { transform: translateY(0); }
.btn.sm { padding: 6px 10px; font-size: var(--fs-13); border-radius: var(--r-xs); }
.btn.lg { padding: 14px 22px; font-size: var(--fs-15); border-radius: var(--r-md); }
.btn.xl { padding: 18px 28px; font-size: var(--fs-16); border-radius: var(--r-md); }
.btn.block { width: 100%; justify-content: center; }

.btn-primary {
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-sm), var(--shadow-inner);
}
.btn-primary:hover { background: color-mix(in oklab, var(--text) 90%, var(--primary) 10%); }

.btn-brand {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow-sm), var(--shadow-inner);
}
.btn-brand:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-inner);
}
.btn-secondary:hover { background: var(--surface-2); }

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: var(--shadow-sm), var(--shadow-inner);
}
.btn-danger:hover { background: color-mix(in oklab, var(--danger) 88%, black); }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================================
   Form primitives
   ============================================================ */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > label, .label {
  font-size: var(--fs-13);
  font-weight: 540;
  color: var(--text-2);
}
.field .hint, .hint { font-size: var(--fs-13); color: var(--text-3); }
.field .error { font-size: var(--fs-13); color: var(--danger); }

.input, .textarea, .select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: var(--fs-14);
  color: var(--text);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.textarea { resize: vertical; min-height: 96px; font-family: inherit; }
.input.lg { padding: 14px 16px; font-size: var(--fs-15); }

.checkbox {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--surface);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  flex-shrink: 0;
}
.checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.checkbox:checked::after {
  content: "";
  width: 9px; height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}

.radio {
  appearance: none;
  width: 18px; height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease);
}
.radio:checked { border-color: var(--primary); border-width: 5px; }

.toggle {
  appearance: none;
  width: 36px; height: 20px;
  background: var(--border-strong);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--dur) var(--ease);
}
.toggle:checked { background: var(--primary); }
.toggle:checked::after { transform: translateX(16px); }

/* ============================================================
   Surfaces
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card.raised { box-shadow: var(--shadow-md); }
.card-pad { padding: var(--s-6); }
.card-pad-lg { padding: var(--s-8); }

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--r-xs);
  font-size: var(--fs-12);
  font-weight: 540;
  letter-spacing: -0.005em;
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid transparent;
  line-height: 1.2;
  white-space: nowrap;
}
.badge.dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-success { background: color-mix(in oklab, var(--success) 14%, transparent); color: var(--success); }
.badge-warning { background: color-mix(in oklab, var(--warning) 14%, transparent); color: var(--warning); }
.badge-danger  { background: color-mix(in oklab, var(--danger) 14%, transparent); color: var(--danger); }
.badge-info    { background: color-mix(in oklab, var(--primary) 14%, transparent); color: var(--primary); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge.mono    { font-family: var(--font-mono); font-size: 11px; }

.risk-high { background: color-mix(in oklab, var(--risk-high) 14%, transparent); color: var(--risk-high); }
.risk-med  { background: color-mix(in oklab, var(--risk-med) 16%, transparent); color: var(--risk-med); }
.risk-low  { background: var(--surface-3); color: var(--text-3); }

/* Tables */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-14);
}
.tbl th {
  text-align: left;
  font-weight: 540;
  color: var(--text-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
}
.tbl tr:hover td { background: var(--hover); }
.tbl tr[data-selected] td { background: var(--primary-tint); }

/* Chips / tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--divider);
}
.tabs button {
  padding: 10px 14px;
  color: var(--text-3);
  font-size: var(--fs-14);
  font-weight: 540;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--dur-fast) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  border: 1px solid var(--border);
  gap: 2px;
}
.segmented button {
  padding: 6px 14px;
  border-radius: var(--r-sm);
  font-size: var(--fs-13);
  font-weight: 540;
  color: var(--text-3);
  transition: all var(--dur-fast) var(--ease);
}
.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  line-height: 1;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* Skeletons */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s linear infinite;
  border-radius: var(--r-xs);
  display: block;
}
@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner */
.spin {
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
