/* ClearStack Tools — Smart Minimalist Editorial Design System (Docs Site)
 * Pure native CSS, zero external fonts, zero CDN dependencies.
 * Light (Warm Alabaster) + Dark (Neutral Obsidian) with light-dark() & fallbacks.
 */

@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    margin: 0;
  }

  h1,
  h2,
  h3,
  h4,
  p,
  ul,
  ol,
  dl,
  dd {
    margin: 0;
  }

  table {
    border-collapse: collapse;
    border-spacing: 0;
  }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
      system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco,
      Consolas, "Liberation Mono", monospace;

    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-subtle: #f3f2ee;
    --surface-hover: #eae8e2;

    --ink: #141413;
    --ink-secondary: #4a4843;
    --ink-muted: #69665f;

    --border: rgba(20, 20, 19, 0.11);
    --border-strong: rgba(20, 20, 19, 0.22);

    --btn-primary-bg: #141413;
    --btn-primary-ink: #fafaf9;

    --accent: #1d4ed8;
    --safe: #047857;
    --safe-subtle: rgba(4, 120, 87, 0.08);
    --amber: #b45309;
    --leak: #b91c1c;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
  }

  @supports (color: light-dark(white, black)) {
    :root {
      --bg: light-dark(#fafaf9, #0c0c0b);
      --surface: light-dark(#ffffff, #141413);
      --surface-subtle: light-dark(#f3f2ee, #1b1b19);
      --surface-hover: light-dark(#eae8e2, #242421);

      --ink: light-dark(#141413, #f5f5f3);
      --ink-secondary: light-dark(#4a4843, #c5c2ba);
      --ink-muted: light-dark(#69665f, #949087);

      --border: light-dark(rgba(20, 20, 19, 0.11), rgba(245, 245, 243, 0.11));
      --border-strong: light-dark(
        rgba(20, 20, 19, 0.22),
        rgba(245, 245, 243, 0.22)
      );

      --btn-primary-bg: light-dark(#141413, #f5f5f3);
      --btn-primary-ink: light-dark(#fafaf9, #0c0c0b);

      --accent: light-dark(#1d4ed8, #60a5fa);
      --safe: light-dark(#047857, #34d399);
      --safe-subtle: light-dark(
        rgba(4, 120, 87, 0.08),
        rgba(52, 211, 153, 0.13)
      );
      --amber: light-dark(#b45309, #fbbf24);
      --leak: light-dark(#b91c1c, #f87171);
    }
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0c0c0b;
      --surface: #141413;
      --surface-subtle: #1b1b19;
      --surface-hover: #242421;

      --ink: #f5f5f3;
      --ink-secondary: #c5c2ba;
      --ink-muted: #949087;

      --border: rgba(245, 245, 243, 0.11);
      --border-strong: rgba(245, 245, 243, 0.22);

      --btn-primary-bg: #f5f5f3;
      --btn-primary-ink: #0c0c0b;

      --accent: #60a5fa;
      --safe: #34d399;
      --safe-subtle: rgba(52, 211, 153, 0.13);
      --amber: #fbbf24;
      --leak: #f87171;
    }
  }

  :root[data-theme="light"] {
    color-scheme: light;
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-subtle: #f3f2ee;
    --surface-hover: #eae8e2;
    --ink: #141413;
    --ink-secondary: #4a4843;
    --ink-muted: #69665f;
    --border: rgba(20, 20, 19, 0.11);
    --border-strong: rgba(20, 20, 19, 0.22);
    --btn-primary-bg: #141413;
    --btn-primary-ink: #fafaf9;
    --accent: #1d4ed8;
    --safe: #047857;
    --safe-subtle: rgba(4, 120, 87, 0.08);
    --amber: #b45309;
    --leak: #b91c1c;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0c0c0b;
    --surface: #141413;
    --surface-subtle: #1b1b19;
    --surface-hover: #242421;
    --ink: #f5f5f3;
    --ink-secondary: #c5c2ba;
    --ink-muted: #949087;
    --border: rgba(245, 245, 243, 0.11);
    --border-strong: rgba(245, 245, 243, 0.22);
    --btn-primary-bg: #f5f5f3;
    --btn-primary-ink: #0c0c0b;
    --accent: #60a5fa;
    --safe: #34d399;
    --safe-subtle: rgba(52, 211, 153, 0.13);
    --amber: #fbbf24;
    --leak: #f87171;
  }
}

@layer base {
  html,
  body {
    background-color: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }

  a {
    color: var(--accent);
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background-color: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
  }
}

@layer layout {
  .site-wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 28px 20px 64px;
    width: 100%;
  }

  .site-section {
    padding: 36px 0;
    border-bottom: 1px solid var(--border);
  }

  .site-section:last-of-type {
    border-bottom: none;
  }

  .site-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
  }

  @media (max-width: 760px) {
    .site-grid-3 {
      grid-template-columns: 1fr;
    }

    .site-wrap {
      padding: 20px 16px 48px;
    }
  }
}

@layer components {
  .site-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
  }

  .site-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.02em;
  }

  .site-brand:hover {
    text-decoration: none;
  }

  .site-emblem {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-md);
    background-color: var(--btn-primary-bg);
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 2.5px;
    padding: 5px;
    flex: 0 0 26px;
  }

  .site-emblem-r1 {
    display: flex;
    gap: 2px;
    align-items: center;
  }

  .site-emblem-bar {
    flex: 1;
    height: 2.5px;
    border-radius: 1px;
    background-color: var(--btn-primary-ink);
  }

  .site-emblem-dot {
    width: 3.5px;
    height: 3.5px;
    border-radius: 50%;
    background-color: var(--safe);
  }

  .site-emblem-r2 {
    height: 2.5px;
    border-radius: 1px;
    background-color: var(--btn-primary-ink);
  }

  .site-emblem-r3 {
    height: 2.5px;
    width: 60%;
    align-self: center;
    border-radius: 1px;
    background-color: var(--btn-primary-ink);
  }

  .site-nav-links {
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 13.5px;
    flex-wrap: wrap;
  }

  .site-nav-links a {
    color: var(--ink-secondary);
    font-weight: 500;
  }

  .site-nav-links a[aria-current="page"] {
    color: var(--ink);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
  }

  .site-kicker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--safe);
    margin-bottom: 12px;
  }

  .site-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--safe);
  }

  .site-h1 {
    font-size: clamp(26px, 4vw, 38px);
    line-height: 1.16;
    letter-spacing: -0.025em;
    font-weight: 700;
    color: var(--ink);
    max-width: 720px;
  }

  .site-lead {
    margin-top: 14px;
    font-size: 16px;
    color: var(--ink-secondary);
    max-width: 680px;
  }

  .site-h2 {
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin-bottom: 10px;
  }

  .site-h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
  }

  .site-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .site-card-num {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--ink-muted);
  }

  .site-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-top: 24px;
    overflow: hidden;
  }

  .site-strip-cell {
    padding: 14px 16px;
    border-right: 1px solid var(--border);
  }

  .site-strip-cell:last-child {
    border-right: none;
  }

  .site-strip-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-muted);
  }

  .site-strip-val {
    font-size: 19px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    margin-top: 2px;
  }

  @media (max-width: 700px) {
    .site-strip {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .site-strip-cell {
      border-right: none;
      border-bottom: 1px solid var(--border);
    }

    .site-strip-cell:nth-child(odd) {
      border-right: 1px solid var(--border);
    }

    .site-strip-cell:nth-last-child(-n + 2) {
      border-bottom: none;
    }
  }

  .site-cta-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 22px;
    flex-wrap: wrap;
  }

  .site-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    color: var(--ink);
    font-size: 14px;
    font-weight: 500;
  }

  .site-btn:hover {
    text-decoration: none;
    background-color: var(--surface-hover);
  }

  .site-btn-primary {
    background-color: var(--btn-primary-bg);
    color: var(--btn-primary-ink);
    border-color: var(--btn-primary-bg);
  }

  .site-btn-primary:hover {
    opacity: 0.9;
    background-color: var(--btn-primary-bg);
  }

  .cs-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--surface);
  }

  .site-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13.5px;
  }

  .site-table th {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-muted);
    background-color: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }

  .site-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--ink);
    vertical-align: top;
    font-variant-numeric: tabular-nums;
  }

  .site-table tbody tr:last-child td {
    border-bottom: none;
  }

  .site-list {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    color: var(--ink-secondary);
  }

  .site-callout {
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--safe);
    border-radius: var(--radius-md);
    background-color: var(--safe-subtle);
    color: var(--ink-secondary);
    font-size: 13.5px;
  }

  .site-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    font-size: 12.5px;
    color: var(--ink-muted);
    flex-wrap: wrap;
  }

  .site-footer-links {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
  }
}

@layer utilities {
  .cs-num {
    font-variant-numeric: tabular-nums;
  }

  .cs-mono {
    font-family: var(--font-mono);
  }

  .cs-safe {
    color: var(--safe);
  }

  .cs-secondary {
    color: var(--ink-secondary);
  }

  .cs-muted {
    color: var(--ink-muted);
  }
}
