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

@layer tokens {
  :root {
    --font-sans: "Manrope", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: "Space Grotesk", "Manrope", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    --text-2xs: 0.6875rem;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-lg: 1.0625rem;
    --text-xl: clamp(1.125rem, 1.05rem + 0.35vw, 1.25rem);
    --text-2xl: clamp(1.35rem, 1.2rem + 0.75vw, 1.75rem);
    --text-3xl: clamp(1.75rem, 1.45rem + 1.5vw, 2.5rem);
    --text-4xl: clamp(2.25rem, 1.8rem + 2.2vw, 3.25rem);

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 9999px;

    --header-h: 4rem;
    --sidebar-w: 18rem;
    --content-max: 64rem;

    --dur-fast: 120ms;
    --dur-base: 200ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  }

  [data-theme="light"] {
    color-scheme: light;
    --surface-page: #f8fafc;
    --surface-raised: #ffffff;
    --surface-sunken: #f1f5f9;
    --surface-header: rgba(255, 255, 255, 0.85);
    --surface-drawer: #ffffff;
    --surface-card: #ffffff;

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-inverse: #f8fafc;

    --border-subtle: #e2e8f0;
    --border-default: #cbd5e1;
    --border-focus: #0284c7;

    --link: #0284c7;
    --link-hover: #0369a1;

    --brand-primary: #059669;
    --brand-primary-soft: #d1fae5;
    --brand-cyan: #0284c7;
    --brand-cyan-soft: #e0f2fe;
    --brand-purple: #7c3aed;
    --brand-purple-soft: #ede9fe;
    --brand-amber: #d97706;
    --brand-amber-soft: #fef3c7;
    --brand-red: #dc2626;
    --brand-red-soft: #fee2e2;

    --gradient-text: linear-gradient(135deg, #0f172a 30%, #0284c7 100%);
    --gradient-hero-glow: radial-gradient(60% 60% at 85% 10%, rgba(2, 132, 199, 0.12), transparent 70%),
                          radial-gradient(40% 40% at 10% 90%, rgba(5, 150, 105, 0.10), transparent 70%);

    --code-bg: #0f172a;
    --code-fg: #f8fafc;
    --code-muted: #94a3b8;
    --code-border: #1e293b;

    --form-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");

    --scrollbar-thumb: #cbd5e1;
    --scrollbar-track: #f1f5f9;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 6px 16px -2px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 16px 32px -4px rgba(0, 0, 0, 0.1);
  }

  [data-theme="dark"] {
    color-scheme: dark;
    --surface-page: #0b0f17;
    --surface-raised: #111827;
    --surface-sunken: #1a2234;
    --surface-header: rgba(11, 15, 23, 0.85);
    --surface-drawer: #111827;
    --surface-card: #111827;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-inverse: #0b0f17;

    --border-subtle: #1e293b;
    --border-default: #334155;
    --border-focus: #38bdf8;

    --link: #38bdf8;
    --link-hover: #7dd3fc;

    --brand-primary: #10b981;
    --brand-primary-soft: rgba(16, 185, 129, 0.15);
    --brand-cyan: #38bdf8;
    --brand-cyan-soft: rgba(56, 189, 248, 0.15);
    --brand-purple: #a855f7;
    --brand-purple-soft: rgba(168, 85, 247, 0.15);
    --brand-amber: #f59e0b;
    --brand-amber-soft: rgba(245, 158, 11, 0.15);
    --brand-red: #f87171;
    --brand-red-soft: rgba(248, 113, 113, 0.15);

    --gradient-text: linear-gradient(135deg, #ffffff 40%, #38bdf8 100%);
    --gradient-hero-glow: radial-gradient(60% 60% at 85% 10%, rgba(56, 189, 248, 0.18), transparent 70%),
                          radial-gradient(40% 40% at 10% 90%, rgba(16, 185, 129, 0.12), transparent 70%);

    --code-bg: #070a0f;
    --code-fg: #f8fafc;
    --code-muted: #94a3b8;
    --code-border: #1e293b;

    --form-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");

    --scrollbar-thumb: #334155;
    --scrollbar-track: #0b0f17;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 48px -8px rgba(0, 0, 0, 0.7);
  }
}

@layer reset {
  * {
   &,
   &::before,
   &::after {
    box-sizing: border-box;
   }
  }
  :where(body, h1, h2, h3, h4, p, figure, ul, ol, dl, dd){ margin: 0; padding: 0; }
  :where(ul, ol){ list-style: none; }
  :where(img, svg){ display: block; max-width: 100%; }
  :where(button, input, select, textarea){ font: inherit; color: inherit; }
  button { background: none; border: 0; cursor: pointer; }
}

@layer base {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 1.5rem);
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
  }

  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.65;
    background-color: var(--surface-page);
    color: var(--text-primary);
    background-image: var(--gradient-hero-glow);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
  }

  /* Scrollers Standard Scrollbar Styling */
  :where(.sidebar, pre, .table-wrapper, .custom-select-dropdown){
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
  }

  /* Legacy WebKit Scroller Fallback */
  @supports not (scrollbar-color: auto) {
    html::-webkit-scrollbar,
    .sidebar::-webkit-scrollbar,
    pre::-webkit-scrollbar,
    .table-wrapper::-webkit-scrollbar,
    .custom-select-dropdown::-webkit-scrollbar {
      width: 8px;
      height: 8px;
    }

    html::-webkit-scrollbar-thumb,
    .sidebar::-webkit-scrollbar-thumb,
    pre::-webkit-scrollbar-thumb,
    .table-wrapper::-webkit-scrollbar-thumb,
    .custom-select-dropdown::-webkit-scrollbar-thumb {
      background: var(--scrollbar-thumb);
      border-radius: 4px;
    }

    html::-webkit-scrollbar-track,
    .sidebar::-webkit-scrollbar-track,
    pre::-webkit-scrollbar-track,
    .table-wrapper::-webkit-scrollbar-track,
    .custom-select-dropdown::-webkit-scrollbar-track {
      background: var(--scrollbar-track);
    }
  }

  a {
    color: var(--link);
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-out);
    &:hover { color: var(--link-hover); text-decoration: underline; }
  }

  :focus-visible:not(input, textarea) {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
  }

  :where(input, textarea){
    &:focus,
    &:focus-visible {
      outline: none;
      border-color: var(--border-focus);
      box-shadow: 0 0 0 3px var(--brand-cyan-soft);
    }
  }

  .skip-link {
    position: absolute;
    top: -100px;
    left: 1rem;
    background: var(--brand-primary);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    z-index: 100;
    font-weight: 600;
    &:focus { top: 1rem; }
  }
}

@layer layout {
  .site-header {
    position: sticky;
    top: 0;
    height: var(--header-h);
    background: var(--surface-header);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 50;

    .header-left {
      display: flex;
      align-items: center;
      gap: 1rem;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      text-decoration: none;
      color: var(--text-primary);

      .brand-logo {
        width: 34px;
        height: 34px;
        background: linear-gradient(135deg, var(--brand-primary), var(--brand-cyan));
        border-radius: var(--radius-sm);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-family: var(--font-mono);
        font-weight: 800;
        font-size: 1rem;
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
      }

      .brand-title {
        font-family: var(--font-display);
        font-size: 1.25rem;
        font-weight: 700;
        letter-spacing: -0.02em;
      }

      .version-badge {
        font-size: var(--text-2xs);
        font-family: var(--font-mono);
        background: var(--surface-sunken);
        border: 1px solid var(--border-default);
        color: var(--text-muted);
        padding: 2px 8px;
        border-radius: var(--radius-pill);
        font-weight: 600;
      }
    }

    .header-right {
      display: flex;
      align-items: center;
      gap: 0.75rem;

      .icon-btn {
        width: 36px;
        height: 36px;
        border-radius: var(--radius-sm);
        border: 1px solid var(--border-subtle);
        background: var(--surface-raised);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        transition: all var(--dur-fast) var(--ease-out);

        &:hover {
          color: var(--text-primary);
          border-color: var(--border-default);
          background: var(--surface-sunken);
        }

        svg { width: 18px; height: 18px; }
      }
    }

    .menu-toggle-btn {
      display: none;
      @media (width <= 64rem) { display: flex; }
    }
  }

  .app-shell {
    display: flex;
    max-width: 100dvw;
    margin: 0 auto;
    min-height: calc(100vh - var(--header-h));
  }

  .sidebar {
    width: var(--sidebar-w);
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    border-right: 1px solid var(--border-subtle);
    flex-shrink: 0;

    @media (width <= 64rem) {
      position: fixed;
      left: 0;
      top: 0;
      bottom: 0;
      height: 100vh;
      background: var(--surface-drawer);
      z-index: 60;
      transform: translateX(-100%);
      transition: transform var(--dur-base) var(--ease-out);
      box-shadow: var(--shadow-lg);

      &.is-open { transform: translateX(0); }
    }

    .sidebar-search-box {
      position: relative;
      margin-bottom: 1.5rem;

      input {
        width: 100%;
        background: var(--surface-sunken);
        border: 1px solid var(--border-subtle);
        color: var(--text-primary);
        padding: 0.5rem 0.75rem 0.5rem 2.25rem;
        border-radius: var(--radius-sm);
        font-size: var(--text-sm);
        transition: border-color var(--dur-fast) var(--ease-out),
                    box-shadow var(--dur-fast) var(--ease-out),
                    background-color var(--dur-fast) var(--ease-out);

        &:focus,
        &:focus-visible {
          outline: none;
          border-color: var(--border-focus);
          background: var(--surface-raised);
          box-shadow: 0 0 0 3px var(--brand-cyan-soft);
        }
      }

      svg {
        position: absolute;
        left: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        width: 14px;
        height: 14px;
        color: var(--text-muted);
      }
    }

    .nav-section-title {
      font-size: var(--text-2xs);
      text-transform: uppercase;
      font-weight: 700;
      letter-spacing: 0.08em;
      color: var(--text-muted);
      margin: 1.25rem 0 0.5rem 0.5rem;
    }

    .nav-list a {
      display: block;
      padding: 0.45rem 0.75rem;
      border-radius: var(--radius-sm);
      color: var(--text-secondary);
      font-size: var(--text-sm);
      font-weight: 500;
      transition: all var(--dur-fast) var(--ease-out);

      &:hover {
        color: var(--text-primary);
        background: var(--surface-sunken);
        text-decoration: none;
      }

      &.active {
        color: var(--brand-cyan);
        background: var(--brand-cyan-soft);
        font-weight: 600;
      }
    }
  }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-out);

    &.is-active {
      opacity: 1;
      pointer-events: auto;
    }
  }

  .content-col {
    flex: 1;
    min-width: 0;
    padding: 2.5rem 3.5rem;

    @media (width <= 48rem) {
      padding: 1.5rem 1rem;
    }
  }
}

@layer components {
  /* ── Hero ── */
  .hero-section {
    margin-bottom: 3.5rem;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border-subtle);

    .hero-badges-row {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem;
      margin-bottom: 1.25rem;
    }

    h1 {
      font-family: var(--font-display);
      font-size: var(--text-4xl);
      font-weight: 800;
      line-height: 1.15;
      letter-spacing: -0.03em;
      margin-bottom: 1rem;
      background: var(--gradient-text);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .hero-lead {
      font-size: var(--text-lg);
      color: var(--text-secondary);
      max-width: 50rem;
      line-height: 1.6;
      margin-bottom: 2rem;
    }

    .hero-cta-group {
      display: flex;
      flex-wrap: wrap;
      gap: 1rem;
      align-items: center;

      .btn {
        padding: 0.75rem 1.5rem;
        border-radius: var(--radius-sm);
        font-weight: 600;
        font-size: var(--text-sm);
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        transition: all var(--dur-fast) var(--ease-out);

        &.btn-primary {
          background: linear-gradient(135deg, var(--brand-primary), var(--brand-cyan));
          color: #fff;
          box-shadow: 0 4px 14px rgba(2, 132, 199, 0.3);
          &:hover { transform: translateY(-1px); opacity: 0.95; text-decoration: none; }
        }

        &.btn-outline {
          background: var(--surface-raised);
          border: 1px solid var(--border-default);
          color: var(--text-primary);
          box-shadow: var(--shadow-sm);
          &:hover { background: var(--surface-sunken); text-decoration: none; }
        }
      }
    }
  }

  /* ── Universal Custom Select Dropdown Component ── */
  .custom-select-wrapper {
      position: relative;
      display: inline-block;
      user-select: none;

      select.custom-select {
          position: absolute !important;
          opacity: 0 !important;
          pointer-events: none !important;
          width: 1px !important;
          height: 1px !important;
          margin: -1px !important;
          border: 0 !important;
          padding: 0 !important;
          clip: rect(0 0 0 0) !important;
          overflow: hidden !important;
      }
  }

  .custom-select-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background-color: var(--surface-raised);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.85rem;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    line-height: 1.4;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out);

    &:hover {
      border-color: var(--border-focus);
      background-color: var(--surface-sunken);
    }

    &:focus-visible, &.is-open {
      border-color: var(--border-focus);
      outline: none;
      box-shadow: 0 0 0 3px var(--brand-cyan-soft);
    }

    .trigger-label {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .trigger-chevron {
      width: 14px;
      height: 14px;
      color: var(--text-muted);
      flex-shrink: 0;
      transition: transform var(--dur-fast) var(--ease-out);
    }

    &.is-open .trigger-chevron {
      transform: rotate(180deg);
      color: var(--brand-cyan);
    }
  }

  .custom-select-dropdown {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: 22rem;
    max-height: 18rem;
    overflow-y: auto;
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.35rem;
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px) scale(0.98);
    transform-origin: top left;
    transition: opacity var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out),
                visibility var(--dur-fast) var(--ease-out);

    &.is-open {
      opacity: 1;
      visibility: visible;
      transform: translateY(0) scale(1);
    }

    .custom-select-option {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 0.25rem;
      padding: 0.5rem 0.75rem;
      margin-bottom: 2px;
      border-radius: var(--radius-xs);
      font-size: var(--text-xs);
      color: var(--text-primary);
      cursor: pointer;
      transition: background-color var(--dur-fast) var(--ease-out),
                  color var(--dur-fast) var(--ease-out);

      &:hover, &.is-focused {
        background: var(--brand-cyan-soft);
        color: var(--brand-cyan);
      }

      &.is-selected {
        background: var(--brand-cyan);
        color: #fff;
        font-weight: 600;

        .option-check {
          opacity: 1;
          visibility: visible;
        }
      }

      .option-check {
        width: 1rem;
        height: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem;
        font-family: var(--font-mono);
        font-weight: bold;
        opacity: 0;
        visibility: hidden;
        flex-shrink: 0;
      }

      .option-text {
        flex: 1;
        white-space: nowrap;
      }
    }
  }

  /* ── Interactive Terminal Mockup ── */
  .terminal-mockup {
    background: #080c14;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin: 2rem 0;

    .term-header {
      background: #0f172a;
      padding: 0.6rem 1rem;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      border-bottom: 1px solid #1e293b;

      .dot { width: 10px; height: 10px; border-radius: 50%; }
      .dot-red { background: #ef4444; }
      .dot-yellow { background: #f59e0b; }
      .dot-green { background: #10b981; }
      .term-title {
        font-family: var(--font-mono);
        font-size: var(--text-2xs);
        color: #94a3b8;
        margin-left: 0.5rem;
      }
    }

    .term-body {
      padding: 1.25rem;
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: #38bdf8;
      line-height: 1.5;
      overflow-x: auto;

      .term-banner { color: #10b981; font-weight: bold; }
      .term-prompt { color: #f8fafc; }
      .term-dim { color: #64748b; }
      .term-accent { color: #a855f7; }
    }
  }

  /* ── Section Cards ── */
  section {
    margin-bottom: 4rem;
    scroll-margin-top: calc(var(--header-h) + 1.5rem);

    h2 {
      font-family: var(--font-display);
      font-size: var(--text-2xl);
      font-weight: 700;
      letter-spacing: -0.02em;
      margin-bottom: 0.75rem;
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    h3 {
      font-family: var(--font-display);
      font-size: var(--text-xl);
      font-weight: 600;
      margin: 2rem 0 0.75rem;
    }

    p {
      color: var(--text-secondary);
      margin-bottom: 1rem;
    }
  }

  /* ── Tabs Component ── */
  .tab-container {
    margin: 1.5rem 0;

    .tab-buttons {
      display: flex;
      gap: 0.5rem;
      border-bottom: 1px solid var(--border-subtle);
      overflow-x: auto;

      .tab-btn {
        padding: 0.65rem 1.25rem;
        font-size: var(--text-sm);
        font-weight: 600;
        color: var(--text-muted);
        border-bottom: 2px solid transparent;
        transition: all var(--dur-fast) var(--ease-out);
        white-space: nowrap;

        &:hover { color: var(--text-primary); }

        &.active {
          color: var(--brand-cyan);
          border-bottom-color: var(--brand-cyan);
        }
      }
    }

    .tab-pane {
      display: none;
      padding-top: 1rem;
      &.active { display: block; }
    }
  }

  /* ── Code Blocks ── */
  pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.55;
    color: var(--code-fg);
    position: relative;
    margin: 1rem 0;

    .copy-code-btn {
      position: absolute;
      top: 0.6rem;
      right: 0.6rem;
      background: rgba(255, 255, 255, 0.1);
      border: 1px solid rgba(255, 255, 255, 0.15);
      color: #cbd5e1;
      padding: 0.3rem 0.6rem;
      border-radius: var(--radius-xs);
      font-size: var(--text-2xs);
      font-family: var(--font-sans);
      font-weight: 600;
      transition: all var(--dur-fast) var(--ease-out);

      &:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }
    }
  }

  code:not(pre code) {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-xs);
    color: var(--brand-cyan);
  }

  /* ── Search & Filter Rule Catalog ── */
  .rule-filter-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;

    .rule-search-input-wrapper {
      position: relative;

      input {
        width: 100%;
        background: var(--surface-card);
        border: 1px solid var(--border-default);
        color: var(--text-primary);
        padding: 0.75rem 1rem 0.75rem 2.75rem;
        border-radius: var(--radius-md);
        font-size: var(--text-base);
        box-shadow: var(--shadow-sm);

        &:focus {
          border-color: var(--border-focus);
          box-shadow: 0 0 0 3px var(--brand-cyan-soft);
        }
      }

      svg {
        position: absolute;
        left: 1rem;
        top: 50%;
        transform: translateY(-50%);
        width: 18px;
        height: 18px;
        color: var(--text-muted);
      }
    }

    .filter-dropdown-and-pills-row {
      display: flex;
      align-items: center;
      gap: 1rem;
      flex-wrap: wrap;

      .custom-select {
        min-width: 13rem;
      }
    }

    .category-pills {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem;

      .pill-btn {
        padding: 0.35rem 0.85rem;
        border-radius: var(--radius-pill);
        font-size: var(--text-xs);
        font-weight: 600;
        background: var(--surface-sunken);
        border: 1px solid var(--border-subtle);
        color: var(--text-secondary);
        transition: all var(--dur-fast) var(--ease-out);

        &:hover {
          background: var(--surface-raised);
          color: var(--text-primary);
        }

        &.active {
          background: var(--brand-cyan);
          border-color: var(--brand-cyan);
          color: #fff;
        }
      }
    }
  }

  .rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
    gap: 1.5rem;
  }

  .rule-card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: all var(--dur-base) var(--ease-out);

    &:hover {
      border-color: var(--brand-cyan);
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
    }

    .rule-card-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      margin-bottom: 0.75rem;

      .rule-id {
        font-family: var(--font-mono);
        font-weight: 700;
        font-size: var(--text-sm);
        color: var(--text-primary);
      }

      .badge {
        font-size: var(--text-2xs);
        font-weight: 700;
        text-transform: uppercase;
        padding: 2px 8px;
        border-radius: var(--radius-pill);

        &.badge-safe { background: var(--brand-primary-soft); color: var(--brand-primary); }
        &.badge-modern { background: var(--brand-cyan-soft); color: var(--brand-cyan); }
        &.badge-refactor { background: var(--brand-purple-soft); color: var(--brand-purple); }
      }
    }

    .rule-card-desc {
      font-size: var(--text-sm);
      color: var(--text-muted);
      margin-bottom: 1rem;
      line-height: 1.5;
    }

    .diff-snippet {
      background: var(--code-bg);
      border: 1px solid var(--code-border);
      border-radius: var(--radius-xs);
      padding: 0.75rem;
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      line-height: 1.45;
      overflow-x: auto;

      .diff-sub { color: var(--brand-red); }
      .diff-add { color: var(--brand-primary); }
    }
  }

  /* ── Tables ── */
  .table-wrapper {
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);

    table {
      width: 100%;
      border-collapse: collapse;
      font-size: var(--text-sm);

      th, td {
        padding: 0.85rem 1.25rem;
        border-bottom: 1px solid var(--border-subtle);
        text-align: left;
      }

      th {
        background: var(--surface-sunken);
        font-weight: 700;
        color: var(--text-primary);
      }

      tr:last-child td { border-bottom: none; }
      tr:hover td { background: var(--surface-sunken); }
    }
  }

  /* ── Benefits & Gaps Grid ── */
  .benefits-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0 2.5rem;

    .benefit-card {
      background: var(--surface-card);
      border: 1px solid var(--border-default);
      border-radius: var(--radius-md);
      padding: 1.5rem;
      box-shadow: var(--shadow-sm);
      display: flex;
      flex-direction: column;
      transition: transform var(--dur-base) var(--ease-out),
                  box-shadow var(--dur-base) var(--ease-out),
                  border-color var(--dur-base) var(--ease-out);

      &:hover {
        border-color: var(--brand-primary);
        box-shadow: 0 10px 24px -4px rgba(16, 185, 129, 0.16);
        transform: translateY(-3px);
      }

      .benefit-icon {
        width: 2.75rem;
        height: 2.75rem;
        display: grid;
        place-items: center;
        border-radius: var(--radius-sm);
        background: var(--brand-primary-soft);
        font-size: 1.35rem;
        margin-bottom: 1rem;
        flex-shrink: 0;
      }

      .benefit-title {
        font-family: var(--font-display);
        font-weight: 700;
        font-size: var(--text-sm);
        color: var(--text-primary);
        margin-bottom: 0.5rem;
        line-height: 1.3;
      }

      .benefit-desc {
        font-size: var(--text-xs);
        color: var(--text-secondary);
        line-height: 1.65;
        flex: 1;
      }
    }
  }

  /* ── Strict Non-Goals Grid ── */
  .non-goals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0 2.5rem;

    .non-goal-card {
      background: var(--surface-card);
      border: 1px solid var(--border-default);
      border-top: 3px solid var(--brand-red);
      border-radius: var(--radius-md);
      padding: 1.5rem;
      box-shadow: var(--shadow-sm);
      display: flex;
      flex-direction: column;
      transition: transform var(--dur-base) var(--ease-out),
                  box-shadow var(--dur-base) var(--ease-out),
                  border-color var(--dur-base) var(--ease-out);

      &:hover {
        border-color: var(--brand-red);
        box-shadow: 0 10px 24px -4px rgba(248, 113, 113, 0.18);
        transform: translateY(-3px);
      }

      .non-goal-header {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-bottom: 0.75rem;

        .non-goal-badge {
          align-self: flex-start;
          font-size: var(--text-2xs);
          font-weight: 800;
          letter-spacing: 0.05em;
          text-transform: uppercase;
          padding: 2px 8px;
          border-radius: var(--radius-xs);
          background: var(--brand-red-soft);
          color: var(--brand-red);
        }

        h4 {
          font-family: var(--font-display);
          font-size: var(--text-sm);
          font-weight: 700;
          color: var(--text-primary);
          margin: 0;
          line-height: 1.35;
        }
      }

      p {
        font-size: var(--text-xs);
        color: var(--text-secondary);
        line-height: 1.65;
        margin: 0;
        flex: 1;
      }
    }
  }

  /* ── Toast Notification ── */
  .toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
    pointer-events: none;

    .toast {
      background: var(--surface-raised);
      border: 1px solid var(--border-default);
      color: var(--text-primary);
      padding: 0.75rem 1.25rem;
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-lg);
      font-size: var(--text-sm);
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      opacity: 0;
      transform: translateY(1rem);
      transition: all var(--dur-base) var(--ease-out);

      &.is-visible {
        opacity: 1;
        transform: translateY(0);
      }
    }
  }

  /* ── Footer ── */
  footer.site-footer {
    border-top: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: var(--text-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
  }
}

/* ── Forced Colors Mode / High Contrast Accessibility Standards ── */
@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid Highlight !important;
    outline-offset: 2px !important;
  }

  :where(.pill-btn.active, .tab-btn.active, .custom-select-option.is-selected){
    outline: 2px solid Highlight;
    background: Highlight !important;
    color: HighlightText !important;
  }

  :where(.benefit-card, .non-goal-card, .rule-card, .custom-select-dropdown, .table-wrapper){
    border: 1px solid CanvasText !important;
  }
}

/* ── High Contrast Preference: Scrollbar Contrast ── */
@media (prefers-contrast: more) {
  :root {
    --scrollbar-thumb: #000000;
    --scrollbar-track: #ffffff;
  }
  [data-theme="dark"] {
    --scrollbar-thumb: #ffffff;
    --scrollbar-track: #000000;
  }
}

/* ── Screen Reader Only (a11y) ── */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── Prefers Reduced Motion (WCAG 2.2 Standard) ── */
@media (prefers-reduced-motion: reduce) {
  * {
      &,
      &::before,
      &::after {
          animation-duration: 0.01ms !important;
          animation-iteration-count: 1 !important;
          transition-duration: 0.01ms !important;
          scroll-behavior: auto !important;
      }
  }
}

/* ── Performance Optimization: Content Visibility for Long Sections ── */
:where(#rules, #market-comparison, #safety-proof, #why-cssforge){
  content-visibility: auto;
  contain-intrinsic-size: 1px 800px;
}
