/* ============================================================
   Nexus Viam Design System
   Tokens · Light + Dark
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Instrument+Serif:ital@0;1&display=swap");

:root {
  /* ── Type families ─────────────────────────────────────── */
  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* ── Type scale (px @ 16px root) ───────────────────────── */
  --t-display: 56px;       /* Instrument Serif, hero */
  --t-h1: 32px;
  --t-h2: 24px;
  --t-h3: 18px;
  --t-h4: 15px;
  --t-body: 14px;
  --t-body-sm: 13px;
  --t-caption: 12px;
  --t-micro: 11px;
  --t-mono: 12.5px;

  --lh-tight: 1.15;
  --lh-snug: 1.3;
  --lh-base: 1.5;
  --lh-loose: 1.65;

  --tracking-tight: -0.02em;
  --tracking-base: -0.005em;
  --tracking-wide: 0.04em;
  --tracking-mega: 0.12em;

  /* ── Spacing (4px base) ────────────────────────────────── */
  --s-0: 0px;
  --s-px: 1px;
  --s-0-5: 2px;
  --s-1: 4px;
  --s-1-5: 6px;
  --s-2: 8px;
  --s-2-5: 10px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 28px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --s-20: 80px;
  --s-24: 96px;

  /* ── Radius ────────────────────────────────────────────── */
  --r-0: 0px;
  --r-1: 2px;
  --r-2: 4px;     /* default */
  --r-3: 6px;
  --r-4: 8px;
  --r-pill: 999px;

  /* ── Elevation (subtle, true-neutral shadows) ──────────── */
  --shadow-0: none;
  --shadow-1: 0 1px 0 0 rgba(15, 17, 21, 0.04), 0 1px 2px 0 rgba(15, 17, 21, 0.04);
  --shadow-2: 0 1px 0 0 rgba(15, 17, 21, 0.04), 0 4px 12px -2px rgba(15, 17, 21, 0.06);
  --shadow-3: 0 1px 0 0 rgba(15, 17, 21, 0.05), 0 12px 32px -8px rgba(15, 17, 21, 0.10);
  --shadow-pop: 0 24px 64px -16px rgba(15, 17, 21, 0.18);
  --shadow-focus: 0 0 0 3px var(--accent-ring);

  /* ── Motion ────────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --d-fast: 120ms;
  --d-base: 180ms;
  --d-slow: 280ms;

  /* ── Z-index ───────────────────────────────────────────── */
  --z-rail: 10;
  --z-sticky: 20;
  --z-overlay: 80;
  --z-modal: 100;
  --z-toast: 120;
}

/* ============================================================
   Light theme — true cool neutrals
   ============================================================ */
:root,
[data-theme="light"] {
  /* Surfaces */
  --bg-canvas: #fafafa;            /* page background */
  --bg-surface: #ffffff;           /* cards, modals, popovers */
  --bg-sunken: #f3f4f5;            /* inset wells, code blocks */
  --bg-inset: #ebedf0;             /* deeper insets, kbd */
  --bg-overlay: rgba(15, 17, 21, 0.40);

  /* Text */
  --fg-primary: #0f1115;           /* headings, primary text */
  --fg-secondary: #4a5060;         /* body text */
  --fg-tertiary: #6b7280;          /* meta, labels */
  --fg-muted: #9099a8;              /* placeholders, disabled */
  --fg-on-accent: #fafafa;          /* text on accent */
  --fg-on-inverse: #fafafa;         /* text on near-black */
  --fg-link: var(--accent-600);

  /* Borders */
  --border-subtle: #ececef;
  --border-default: #dfe1e5;
  --border-strong: #c7cad0;
  --border-focus: var(--accent-500);

  /* Accent — forest green (oklch family from question 3) */
  --accent-50: #ecf3ef;
  --accent-100: #d6e6dd;
  --accent-200: #a9c8b6;
  --accent-300: #7caa8e;
  --accent-400: #558d6d;
  --accent-500: #3a6b4f;            /* PRIMARY */
  --accent-600: #2f5a41;
  --accent-700: #244633;
  --accent-800: #1a3325;
  --accent-ring: rgba(58, 107, 79, 0.18);

  /* Semantic */
  --success-bg: #ecf3ef;
  --success-border: #a9c8b6;
  --success-fg: #244633;
  --warning-bg: #fbf3e3;
  --warning-border: #e8d39a;
  --warning-fg: #6b4f15;
  --danger-bg: #fbecec;
  --danger-border: #e8b8b8;
  --danger-fg: #7a2424;
  --info-bg: #ebf1f8;
  --info-border: #b8cce0;
  --info-fg: #284b73;

  /* Layer hues — for the four data-clarity layers */
  --layer-raw-fg: #6b7280;
  --layer-raw-bg: #ebedf0;
  --layer-context-fg: #284b73;
  --layer-context-bg: #ebf1f8;
  --layer-design-fg: #6b4f15;
  --layer-design-bg: #fbf3e3;
  --layer-final-fg: #244633;
  --layer-final-bg: #ecf3ef;

  /* Component-specific */
  --btn-primary-bg: #0f1115;
  --btn-primary-fg: #fafafa;
  --btn-primary-bg-hover: #25282f;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-fg: #0f1115;
  --btn-secondary-border: #dfe1e5;
  --btn-secondary-bg-hover: #f3f4f5;

  /* Patterns */
  --grid-line: rgba(15, 17, 21, 0.04);
}

/* ============================================================
   Dark theme — engineered, neutral
   ============================================================ */
[data-theme="dark"] {
  --bg-canvas: #0d0e10;
  --bg-surface: #16181c;
  --bg-sunken: #1c1e23;
  --bg-inset: #25282f;
  --bg-overlay: rgba(0, 0, 0, 0.60);

  --fg-primary: #f5f6f7;
  --fg-secondary: #b8bcc4;
  --fg-tertiary: #8a8f99;
  --fg-muted: #5a5f6a;
  --fg-on-accent: #f5f6f7;
  --fg-on-inverse: #0d0e10;
  --fg-link: var(--accent-300);

  --border-subtle: #1f2228;
  --border-default: #2a2d34;
  --border-strong: #3a3e47;
  --border-focus: var(--accent-400);

  --accent-50: #1a3325;
  --accent-100: #244633;
  --accent-200: #2f5a41;
  --accent-300: #558d6d;
  --accent-400: #7caa8e;
  --accent-500: #7caa8e;
  --accent-600: #a9c8b6;
  --accent-700: #d6e6dd;
  --accent-800: #ecf3ef;
  --accent-ring: rgba(124, 170, 142, 0.22);

  --success-bg: #14241b;
  --success-border: #2f5a41;
  --success-fg: #a9c8b6;
  --warning-bg: #2a2114;
  --warning-border: #6b4f15;
  --warning-fg: #e8d39a;
  --danger-bg: #2a1414;
  --danger-border: #7a2424;
  --danger-fg: #e8b8b8;
  --info-bg: #14202a;
  --info-border: #284b73;
  --info-fg: #b8cce0;

  --layer-raw-fg: #8a8f99;
  --layer-raw-bg: #1f2228;
  --layer-context-fg: #b8cce0;
  --layer-context-bg: #14202a;
  --layer-design-fg: #e8d39a;
  --layer-design-bg: #2a2114;
  --layer-final-fg: #a9c8b6;
  --layer-final-bg: #14241b;

  --btn-primary-bg: #f5f6f7;
  --btn-primary-fg: #0d0e10;
  --btn-primary-bg-hover: #e0e2e6;
  --btn-secondary-bg: #16181c;
  --btn-secondary-fg: #f5f6f7;
  --btn-secondary-border: #2a2d34;
  --btn-secondary-bg-hover: #1c1e23;

  --grid-line: rgba(255, 255, 255, 0.035);

  --shadow-1: 0 1px 0 0 rgba(0,0,0,0.5), 0 1px 2px 0 rgba(0,0,0,0.4);
  --shadow-2: 0 1px 0 0 rgba(0,0,0,0.5), 0 4px 12px -2px rgba(0,0,0,0.5);
  --shadow-3: 0 1px 0 0 rgba(0,0,0,0.6), 0 12px 32px -8px rgba(0,0,0,0.6);
  --shadow-pop: 0 24px 64px -16px rgba(0,0,0,0.7);
}

/* ============================================================
   Density
   ============================================================ */
[data-density="spacious"] {
  --density-row: 44px;
  --density-pad-y: 12px;
  --density-pad-x: 16px;
}
[data-density="comfortable"],
:root {
  --density-row: 36px;
  --density-pad-y: 8px;
  --density-pad-x: 12px;
}
[data-density="compact"] {
  --density-row: 28px;
  --density-pad-y: 4px;
  --density-pad-x: 10px;
}

/* ============================================================
   Base reset (scoped)
   ============================================================ */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: var(--lh-base);
  letter-spacing: var(--tracking-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss02", "cv11";
}

::selection { background: var(--accent-500); color: var(--fg-on-accent); }

button { font: inherit; }
