/*
 * Simplest1 CSS: the Ink & Paper design system.
 * Tonal monochrome, one sans (IBM Plex Sans), IBM Plex Mono for data.
 * See docs/design/DESIGN.md (doctrine) and docs/design/CSS.md (components).
 * Written fresh 2026-07-21 for the redesign (docs/design/REDESIGN.md).
 */

@view-transition {
  navigation: auto;
}

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

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBM_Plex_Sans/IBMPlexSans-Variable.ttf") format("truetype-variations");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBM_Plex_Sans/IBMPlexSans-Italic-Variable.ttf") format("truetype-variations");
  font-weight: 100 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/IBM_Plex_Mono/IBMPlexMono-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   Reset
   ========================================================================== */

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

  html {
    font-size: 16px;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  body {
    min-height: 100dvh;
    line-height: 1.6;
  }

  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
  }

  input, button, textarea, select {
    font: inherit;
    color: inherit;
  }

  button, summary { cursor: pointer; }

  h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
    text-wrap: balance;
  }

  p { text-wrap: pretty; }
  ul, ol { list-style: none; }
  table { border-collapse: collapse; }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ==========================================================================
   Design Tokens (Ink & Paper)
   ========================================================================== */

@layer tokens {
  :root {
    /* === Color: tonal monochrome === */
    --ink: #141413;
    --ink-2: #5f5e5a;
    --ink-3: #8a8985;
    --paper: #ffffff;
    --paper-2: #f7f6f4;
    --line: rgba(20, 20, 19, 0.14);
    --line-soft: rgba(20, 20, 19, 0.07);
    --accent: #e8604c; /* the wordmark "1" only; never UI states */

    /* Semantic aliases (canonical names for component CSS) */
    --color-fg: var(--ink);
    --color-fg-muted: var(--ink-2);
    --color-fg-subtle: var(--ink-3);
    --color-bg: var(--paper);
    --color-bg-secondary: var(--paper-2);
    --color-bg-hover: var(--paper-2);
    --color-border: var(--line);
    --color-border-light: var(--line-soft);
    --color-link: var(--ink);
    --color-link-hover: var(--ink);

    /* Status colors are ink: state is carried by copy, not hue */
    --color-success: var(--ink);
    --color-success-bg: var(--paper);
    --color-success-fg: var(--ink);
    --color-danger: var(--ink);
    --color-danger-bg: var(--paper);
    --color-danger-fg: var(--ink);
    --color-warning: var(--ink);
    --color-warning-bg: var(--paper);
    --color-warning-fg: var(--ink);
    --color-error-border: var(--ink);

    /* === Typography === */
    --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont,
                 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px */
    --text-base: 1rem;      /* 16px */
    --text-md: 1.125rem;    /* 18px */
    --text-lg: 1.375rem;    /* 22px */
    --text-xl: 1.75rem;     /* 28px */
    --text-2xl: 2.125rem;   /* 34px */
    --text-3xl: 2.625rem;   /* 42px */
    --text-4xl: 3.25rem;    /* 52px */
    --text-5xl: 4rem;       /* 64px */
    --text-hero: clamp(2.375rem, 5.2vw, 3.5rem);

    --leading-tight: 1.15;
    --leading-normal: 1.5;
    --leading-relaxed: 1.7;

    --weight-light: 400;    /* light retired; alias to regular */
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;

    --tracking-tight: -0.022em;
    --tracking-normal: -0.011em;

    /* === Spacing (4px grid) === */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-24: 6rem;
    --space-32: 8rem;

    /* === Layout === */
    --max-width-narrow: 38rem;
    --max-width-default: 56rem;
    --max-width-wide: 72rem;
    --max-width-prose: 38rem;

    /* === Depth: hairlines + the fixed radius scale. No shadows. === */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-pill: 999px;
    --radius: var(--radius-sm); /* legacy alias */
    --border: 1px solid var(--line);
    --underline-offset: 0.2em;

    /* === Motion === */
    --duration: 150ms;
    --ease: ease;
  }

  /* === Dark mode: tonal, not inversion === */
  @media (prefers-color-scheme: dark) {
    :root {
      --ink: #f2f1ee;
      --ink-2: #a3a29d;
      --ink-3: #7c7b76;
      --paper: #121211;
      --paper-2: #1b1b1a;
      --line: rgba(242, 241, 238, 0.16);
      --line-soft: rgba(242, 241, 238, 0.08);
    }
  }
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-relaxed);
    letter-spacing: var(--tracking-normal);
    color: var(--color-fg);
    background-color: var(--color-bg);
  }

  /* One family everywhere. Hierarchy = weight + size, never a second face
     and never ALL CAPS. */
  h1, h2, h3, h4, h5, h6 {
    font-weight: var(--weight-medium);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    color: var(--color-fg);
  }

  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }

  /* Small headings: 600 and neutral tracking. Bold plus negative tracking
     chokes at these sizes. */
  h3 { font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: normal; }
  h4 { font-size: var(--text-md); font-weight: var(--weight-semibold); letter-spacing: normal; }
  h5 { font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: normal; }
  h6 { font-size: var(--text-sm); font-weight: var(--weight-semibold); letter-spacing: normal; }

  p { color: var(--color-fg); }

  a {
    color: inherit;
    text-decoration: underline;
    text-decoration-skip-ink: auto;
    text-underline-offset: var(--underline-offset);
    text-decoration-color: var(--line);
    transition: text-decoration-color var(--duration) var(--ease);

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

  strong {
    font-weight: var(--weight-bold);
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background-color: var(--paper-2);
    border-radius: 4px;
    padding: 0.125em 0.375em;
  }

  pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    background-color: var(--paper-2);
    border-radius: var(--radius-sm);
    padding: var(--space-6);
    overflow-x: auto;

    & code {
      background: none;
      border-radius: 0;
      padding: 0;
    }
  }

  /* Dates are data: mono, tabular */
  time {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  blockquote {
    font-size: var(--text-lg);
    color: var(--color-fg-muted);
    padding-left: var(--space-6);
    border-left: 2px solid var(--line);
  }

  hr {
    border: none;
    border-top: 1px solid var(--line-soft);
    margin: var(--space-12) 0;
  }

  ul, ol {
    padding-left: var(--space-6);
  }

  fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: var(--space-3) var(--space-4);
  }

  ul { list-style-type: disc; }
  ol { list-style-type: decimal; }

  li {
    padding-left: var(--space-2);
    margin-bottom: var(--space-2);

    &::marker {
      color: var(--color-fg-subtle);
    }
  }

  ::selection {
    background: var(--color-fg);
    color: var(--color-bg);
  }

  :focus-visible {
    outline: 2px solid var(--color-fg);
    outline-offset: 3px;
    border-radius: 2px;
  }
}

/* ==========================================================================
   Layout
   ========================================================================== */

@layer layout {
  .site {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  .site__content {
    flex: 1;
  }

  .container {
    width: 100%;
    max-width: var(--max-width-default);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-6);
    padding-right: var(--space-6);

    @media (min-width: 768px) {
      padding-left: var(--space-8);
      padding-right: var(--space-8);
    }
  }

  .container--wide {
    max-width: var(--max-width-wide);
  }

  .container--narrow {
    max-width: var(--max-width-narrow);
  }

  /* Sections separate with whitespace: no rules, no tinted bands */
  .section {
    padding-top: var(--space-16);
    padding-bottom: var(--space-16);
  }
}

/* ==========================================================================
   Components
   ========================================================================== */

@layer components {
  /* --------------------------------------------------------------------------
     Header
     -------------------------------------------------------------------------- */

  .site-header {
    padding: var(--space-5) 0;
  }

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .header__logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-tight);
    color: var(--color-fg);
    text-decoration: none;

    &:hover {
      color: var(--color-fg);
    }

    & img {
      height: 1.5rem;
      width: auto;
    }
  }

  /* The brand wordmark: text, not an image. The "1" is the one place
     --accent may appear. */
  .wm {
    font-weight: var(--weight-bold);
    font-size: var(--text-md);
    letter-spacing: var(--tracking-tight);
    color: var(--color-fg);
    text-decoration: none;
  }

  .wm--lg {
    font-size: var(--text-lg);
  }

  .wm-one {
    color: var(--accent);
  }

  .header__logo-suffix {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-fg-subtle);
  }

  .header__nav {
    display: flex;
    align-items: center;
    gap: var(--space-6);

    & a:not(.btn) {
      font-size: var(--text-sm);
      color: var(--color-fg-muted);
      text-decoration: none;
      transition: color var(--duration) var(--ease);

      &:hover {
        color: var(--color-fg);
      }

      &[aria-current="page"],
      &.active {
        color: var(--color-fg);
        font-weight: var(--weight-medium);
      }
    }
  }

  /* Ink chrome bar (admin/backstage shells). Redesigned in Phase 4;
     kept functional here with tonal values. */
  .header--dark {
    background-color: var(--ink);
    color: var(--paper);
    padding: var(--space-4) var(--space-8);

    & h1 {
      color: var(--paper);
      font-size: var(--text-md);
      margin: 0;
    }

    & .header__nav a,
    & .admin-nav a,
    & .backstage-nav a {
      color: color-mix(in srgb, var(--paper) 70%, transparent);

      &:hover {
        color: var(--paper);
      }

      &.active,
      &[aria-current="page"] {
        color: var(--paper);
      }
    }

    & .btn--link {
      color: color-mix(in srgb, var(--paper) 70%, transparent);

      &:hover {
        color: var(--paper);
      }
    }
  }

  /* --------------------------------------------------------------------------
     Footer
     -------------------------------------------------------------------------- */

  .footer {
    padding: var(--space-8) 0;
    margin-top: var(--space-8);
    border-top: 1px solid var(--line-soft);
  }

  /* --------------------------------------------------------------------------
     Navigation
     -------------------------------------------------------------------------- */

  .admin-nav,
  .backstage-nav {
    display: flex;
    gap: var(--space-6);
    align-items: center;

    & a {
      font-size: var(--text-sm);
      text-decoration: none;
      transition: color var(--duration) var(--ease);
    }
  }

  /* --------------------------------------------------------------------------
     Dropdown (click-based; behavior: dropdown)
     -------------------------------------------------------------------------- */

  .dropdown {
    position: relative;
    display: inline-block;
  }

  .dropdown__trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    text-decoration: none;

    &::after {
      content: "▾";
      font-size: 0.75em;
      opacity: 0.6;
    }

    &:has(.dropdown__icon)::after {
      display: none;
    }
  }

  .dropdown__icon {
    width: 24px;
    height: 24px;
  }

  .dropdown__trigger--icon {
    font-size: var(--text-lg);
    padding: var(--space-1) var(--space-2);
    color: var(--color-fg-muted);

    &::after {
      display: none;
    }

    &:hover {
      color: var(--color-fg);
    }
  }

  .dropdown__menu {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    min-width: 10rem;
    background-color: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: var(--space-1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-0.25rem);
    transition: all var(--duration) var(--ease);
    z-index: 100;
  }

  .dropdown.open .dropdown__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .dropdown--up .dropdown__menu {
    top: auto;
    bottom: calc(100% + var(--space-2));
    transform: translateY(0.25rem);
  }

  .dropdown--up.open .dropdown__menu {
    transform: translateY(0);
  }

  .dropdown__item {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--color-fg);
    text-align: left;
    text-decoration: none;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }

  .dropdown__item:hover {
    background-color: var(--paper-2);
    text-decoration: none;
  }

  .dropdown__item--danger {
    color: var(--color-fg);

    &:hover {
      background-color: var(--ink);
      color: var(--paper);
    }
  }

  .dropdown__label {
    display: block;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    color: var(--color-fg-subtle);
  }

  .dropdown__divider {
    border-top: 1px solid var(--line-soft);
    margin: var(--space-1) 0;
  }

  /* Ink chrome dropdown variant */
  .header--dark .dropdown__trigger {
    color: var(--paper);
  }

  .header--dark .dropdown__menu {
    background-color: var(--paper);
    border-color: var(--line);
  }

  .header--dark .dropdown__item {
    color: var(--ink);

    &:hover {
      background-color: var(--paper-2);
      color: var(--ink);
    }
  }

  /* --------------------------------------------------------------------------
     Buttons: sentence case, pill, tonal hover. One size system.
     -------------------------------------------------------------------------- */

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.5625rem 1.375rem;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-decoration: none;
    color: var(--paper);
    background-color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: opacity var(--duration) var(--ease),
                border-color var(--duration) var(--ease);

    &:hover {
      opacity: 0.85;
      text-decoration: none;
    }
  }

  .btn--secondary,
  .btn--outline {
    color: var(--color-fg);
    background-color: transparent;
    border: 1px solid var(--line);

    &:hover {
      opacity: 1;
      border-color: var(--color-fg);
    }
  }

  .btn--ghost {
    color: var(--color-fg);
    background-color: transparent;
    border-color: transparent;

    &:hover {
      opacity: 1;
      border-color: var(--line);
    }
  }

  .btn--danger {
    color: var(--paper);
    background-color: var(--ink);
    border-color: var(--ink);
  }

  /* One compact size. btn--sm (admin) and btn--small (global) are aliases
     until the Phase 4 template sweep settles on one name. */
  .btn--small,
  .btn--sm {
    padding: 0.375rem 1rem;
    font-size: var(--text-xs);
  }

  .btn--large {
    padding: 0.8125rem 1.875rem;
    font-size: var(--text-base);
  }

  .btn--block {
    width: 100%;
  }

  .btn--link {
    background: none;
    color: var(--color-fg-muted);
    padding: 0;
    border: none;
    border-radius: 0;
    font-weight: var(--weight-regular);
    text-decoration: underline;
    text-underline-offset: var(--underline-offset);
    text-decoration-color: var(--line);

    &:hover {
      opacity: 1;
      background: none;
      color: var(--color-fg);
      text-decoration-color: var(--color-fg);
    }
  }

  /* --------------------------------------------------------------------------
     Forms: hairlines, radius-sm, sentence-case labels
     -------------------------------------------------------------------------- */

  .form-group {
    margin-bottom: var(--space-6);
  }

  .form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-fg);
    margin-bottom: var(--space-2);
  }

  .form-input,
  .form-textarea,
  .form-select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    color: var(--color-fg);
    background-color: var(--color-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    transition: border-color var(--duration) var(--ease);

    &::placeholder {
      color: var(--color-fg-subtle);
    }

    &:focus {
      outline: 2px solid var(--color-fg);
      outline-offset: 2px;
      border-color: var(--line);
    }
  }

  .form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8985' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-10);
    cursor: pointer;
  }

  /* Filterable select (searchable combobox) — behavior: filter-select */
  .filter-select {
    position: relative;
  }

  .filter-select__input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8985' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-10);
  }

  .filter-select__list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: var(--space-1) 0 0 0;
    padding: var(--space-1);
    background-color: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    list-style: none;
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--duration) var(--ease),
                transform var(--duration) var(--ease),
                visibility var(--duration);
  }

  .filter-select--open .filter-select__list {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .filter-select__item {
    margin: 0;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-base);
    color: var(--color-fg);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--duration) var(--ease);

    &:hover,
    &.filter-select__item--hover {
      background-color: var(--paper-2);
    }

    &.filter-select__item--selected {
      font-weight: var(--weight-medium);
    }

    &[hidden] {
      display: none;
    }
  }

  .filter-select__empty {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-fg-subtle);
    font-style: italic;
    cursor: default;
    pointer-events: none;
  }

  .form-textarea {
    min-height: 8rem;
    resize: vertical;
  }

  .form-hint {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-fg-muted);
    margin-top: var(--space-2);
  }

  .form-error {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-fg);
    font-weight: var(--weight-medium);
    margin-top: var(--space-2);
  }

  .form-input--error,
  .form-textarea--error,
  .form-select--error {
    border-color: var(--color-fg);
  }

  .form-check {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
  }

  .form-check-input {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0;
    accent-color: var(--ink);
    cursor: pointer;
  }

  .form-check-label {
    font-size: var(--text-base);
    color: var(--color-fg);
    cursor: pointer;
  }

  /* Input group (subdomain inputs) */
  .input-group {
    display: flex;
  }

  .input-group .form-input {
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  }

  .input-group__addon {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    color: var(--color-fg-muted);
    background-color: var(--paper-2);
    border: 1px solid var(--line);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  }

  .form--narrow {
    max-width: 31rem;
  }

  .form--editor {
    max-width: var(--max-width-default);
  }

  /* --------------------------------------------------------------------------
     Cards: hairline + radius, no shadows
     -------------------------------------------------------------------------- */

  .card {
    background-color: var(--color-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: var(--space-6);
  }

  .card--compact {
    padding: var(--space-4);

    & .owner-row {
      padding: var(--space-2) 0;

      &:first-child {
        padding-top: 0;
      }

      &:last-child {
        padding-bottom: 0;
      }
    }
  }

  /* --------------------------------------------------------------------------
     Alerts & Badges
     -------------------------------------------------------------------------- */

  .alert {
    padding: var(--space-4) var(--space-6);
    background-color: var(--paper-2);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
  }

  .alert--success,
  .alert--warning {
    background-color: var(--paper-2);
    color: var(--color-fg);
  }

  .alert--error,
  .alert--danger {
    background-color: var(--paper);
    color: var(--color-fg);
    border: 1px solid var(--ink);
  }

  .badge {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.625rem;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-fg-muted);
    background-color: var(--color-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
  }

  .badge--success,
  .badge--danger,
  .badge--warning {
    color: var(--color-fg);
    border-color: var(--color-fg);
  }

  .badge--muted {
    color: var(--color-fg-subtle);
    border-color: var(--line-soft);
  }

  .dev-notice {
    background-color: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--color-fg);
    padding: var(--space-4);
    text-align: left;

    & p {
      margin: 0 0 var(--space-2) 0;
      color: var(--color-fg);

      &:last-child {
        margin-bottom: 0;
      }
    }

    & a {
      color: var(--color-fg);
      word-break: break-all;
    }
  }

  /* --------------------------------------------------------------------------
     Tables: hairline dividers, sentence-case headers
     -------------------------------------------------------------------------- */

  .table {
    width: 100%;
  }

  .table th,
  .table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
  }

  .table th {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-fg-muted);
    border-bottom: 1px solid var(--line);
  }

  .table td {
    border-bottom: 1px solid var(--line-soft);
  }

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

  .table tbody tr {
    transition: background-color var(--duration) var(--ease);
  }

  .table tbody tr:hover {
    background-color: var(--paper-2);
  }

  .table tbody a {
    text-decoration: none;
  }

  .table tbody a:hover:not(.dropdown__item) {
    text-decoration: underline;
  }

  @keyframes flash-row {
    from { background-color: var(--paper-2); }
    to { background-color: transparent; }
  }

  .table tbody tr.flash {
    animation: flash-row 1.5s ease-out;
  }

  .data-table {
    width: 100%;
    border-collapse: collapse;

    & th,
    & td {
      padding: var(--space-3) var(--space-4);
      text-align: left;
      border-bottom: 1px solid var(--line-soft);
    }

    & th {
      font-size: var(--text-sm);
      font-weight: var(--weight-medium);
      color: var(--color-fg-muted);
      border-bottom: 1px solid var(--line);
    }

    & tr:last-child td {
      border-bottom: none;
    }
  }

  /* Detail list: responsive key-value metadata grid */
  .detail-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--line-soft);
  }

  .detail-list > div {
    padding: var(--space-4);
    border-bottom: 1px solid var(--line-soft);
  }

  .detail-list > div:nth-last-child(-n+2):not(.detail-full) {
    border-bottom: none;
  }

  .detail-list > div.detail-full:last-child {
    border-bottom: none;
  }

  .detail-list > .detail-full {
    grid-column: 1 / -1;
  }

  .detail-list__label {
    display: block;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-fg-subtle);
    margin-bottom: var(--space-1);
  }

  @media (max-width: 640px) {
    .detail-list {
      grid-template-columns: 1fr;
    }

    .detail-list > div:nth-last-child(-n+2):not(.detail-full) {
      border-bottom: 1px solid var(--line-soft);
    }

    .detail-list > div:last-child {
      border-bottom: none;
    }
  }

  /* --------------------------------------------------------------------------
     Page Layouts
     -------------------------------------------------------------------------- */

  .auth-page {
    max-width: 25rem;
    margin: var(--space-16) auto;
    padding: 0 var(--space-6);
  }

  .auth-page--wide {
    max-width: 31rem;
  }

  .auth-page__title {
    font-size: var(--text-2xl);
    text-align: center;
    margin-bottom: var(--space-8);
  }

  .auth-page__message {
    text-align: center;
    color: var(--color-fg-muted);
    margin-bottom: var(--space-6);
  }

  .auth-page__footer {
    text-align: center;
    margin-top: var(--space-8);
    color: var(--color-fg-muted);
    font-size: var(--text-sm);
  }

  .maintenance-bar {
    background-color: var(--ink);
    color: var(--paper);
    text-align: center;
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);

    & a {
      color: var(--paper);
      font-weight: var(--weight-medium);
    }
  }

  .form-textarea--code {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    white-space: pre;
    overflow-wrap: normal;
  }

  .form-input--color {
    height: 3rem;
    padding: var(--space-2);
    cursor: pointer;
  }

  .form-input--short {
    width: 140px;
  }

  .empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 40vh;
    text-align: center;
    color: var(--color-fg-muted);
  }

  /* --------------------------------------------------------------------------
     Article Content
     -------------------------------------------------------------------------- */

  .article {
    font-size: var(--text-md);
    line-height: var(--leading-relaxed);

    & > * + * {
      margin-top: var(--space-6);
    }

    & h2 {
      font-size: var(--text-xl);
      margin-top: var(--space-12);
      margin-bottom: var(--space-4);
    }

    & h3 {
      font-size: var(--text-lg);
      margin-top: var(--space-8);
      margin-bottom: var(--space-3);
    }

    & p {
      max-width: var(--max-width-prose);
    }

    & a:not(.btn):not(.badge) {
      text-decoration: underline;
    }
  }

  /* --------------------------------------------------------------------------
     Pagination
     -------------------------------------------------------------------------- */

  .pagination {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-8) 0;
  }

  .pagination__item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-fg-muted);
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    text-decoration: none;
    transition: all var(--duration) var(--ease);

    &:hover {
      color: var(--color-fg);
      border-color: var(--line);
      text-decoration: none;
    }

    &[aria-current="page"] {
      color: var(--paper);
      background-color: var(--ink);
      border-color: var(--ink);
    }
  }

  .pagination__ellipsis {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    font-size: var(--text-sm);
    color: var(--color-fg-subtle);
  }

  /* --------------------------------------------------------------------------
     Misc Components
     -------------------------------------------------------------------------- */

  .skip-link {
    position: absolute;
    top: var(--space-4);
    left: var(--space-4);
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--paper);
    background-color: var(--ink);
    border-radius: var(--radius-pill);
    text-decoration: none;
    transform: translateY(-200%);
    transition: transform var(--duration) var(--ease);
    z-index: 9999;

    &:focus {
      transform: translateY(0);
    }
  }

  .prose {
    max-width: var(--max-width-prose);
  }

  .meta-text {
    font-size: var(--text-sm);
    color: var(--color-fg-muted);
  }

  /* Legacy name from the uppercase era: now a quiet small label.
     Uppercase is retired (DESIGN.md). Rename in the Phase 4 sweep. */
  .caps {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-fg-subtle);
  }

  .dim {
    color: var(--color-fg-muted);
  }

  .lead {
    font-size: var(--text-md);
    color: var(--color-fg-muted);
    line-height: 1.6;
  }

  .small {
    font-size: var(--text-sm);
  }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

@layer utilities {
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Text */
  .text-center { text-align: center; }
  .text-muted { color: var(--color-fg-muted); }
  .text-danger { color: var(--color-fg); font-weight: var(--weight-medium); }
  .text-xs { font-size: var(--text-xs); }
  .text-sm,
  .text-small { font-size: var(--text-sm); }
  .text-lg { font-size: var(--text-lg); }
  .text-nowrap { white-space: nowrap; }
  .invisible { visibility: hidden; }
  .text-strong { font-weight: var(--weight-medium); }
  .text-mono { font-family: var(--font-mono); }
  .tracking-wide { letter-spacing: 0.01em; }

  /* Truncation (works in table cells via max-width: 0) */
  .truncate {
    max-width: 0;
    width: 100%;
  }
  .truncate > * {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Font weight */
  .font-medium { font-weight: var(--weight-medium); }
  .font-semibold { font-weight: var(--weight-medium); }
  .fw-normal { font-weight: var(--weight-regular); }

  /* Spacing - margin */
  .mb-0 { margin-bottom: 0; }
  .mb-2 { margin-bottom: var(--space-2); }
  .mb-3 { margin-bottom: var(--space-3); }
  .mb-4 { margin-bottom: var(--space-4); }
  .mb-6 { margin-bottom: var(--space-6); }
  .mb-8 { margin-bottom: var(--space-8); }
  .mt-2 { margin-top: var(--space-2); }
  .mt-4 { margin-top: var(--space-4); }
  .mt-6 { margin-top: var(--space-6); }
  .mt-8 { margin-top: var(--space-8); }

  /* Spacing - padding */
  .py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
  .py-8 { padding-top: var(--space-8); padding-bottom: var(--space-8); }
  .pt-8 { padding-top: var(--space-8); }

  /* Borders */
  .border-t { border-top: 1px solid var(--line-soft); }
  .border-b { border-bottom: 1px solid var(--line-soft); }

  /* Flexbox */
  .flex { display: flex; }
  .flex-1 { flex: 1; }
  .items-center { align-items: center; }
  .justify-between { justify-content: space-between; }
  .gap-2 { gap: var(--space-2); }
  .gap-4 { gap: var(--space-4); }
  .gap-8 { gap: var(--space-8); }

  /* Grid */
  .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8);
  }

  .grid-2--divided {
    gap: var(--space-12);

    & > *:first-child {
      padding-right: var(--space-6);
      border-right: 1px solid var(--line-soft);
    }
  }

  @media (max-width: 768px) {
    .grid-2 {
      grid-template-columns: 1fr;
    }

    .grid-2--divided > *:first-child {
      padding-right: 0;
      border-right: none;
    }
  }

  /* Responsive visibility */
  .hide-desktop { display: none; }
  .hide-mobile { display: inline; }

  @media (max-width: 639px) {
    .hide-desktop { display: inline; }
    .hide-mobile { display: none; }
  }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
  *, *::before, *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  a { text-decoration: underline; }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  h2, h3 {
    page-break-after: avoid;
  }

  img, pre, blockquote {
    page-break-inside: avoid;
  }
}
