/* ═══════════════════════════════════════════════════════════
   adminkit — Precision Noir
   A refined, dark-first admin shell inspired by Linear & Vercel.
   Uses OpenProps tokens, CSS nesting, semantic selectors.
   ═══════════════════════════════════════════════════════════ */

@import "https://unpkg.com/open-props" layer(design.tokens);
/* Self-hosted Plus Jakarta Sans + JetBrains Mono — no fonts.googleapis/gstatic
   request from the admin (GDPR / supply-chain, #111). Relative path resolves
   under whatever prefix the admin shell is mounted at ({prefix}/static/...). */
@import "fonts/admin-fonts.css";

/* ── Design Tokens ── */

:root {
  --font-sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Surface system — layered depth */
  --surface-0: #0c0c0f;
  --surface-1: #111114;
  --surface-2: #18181c;
  --surface-3: #1f1f24;
  --surface-4: #26262c;
  --surface-raised: #2a2a32;

  /* Text hierarchy */
  --text-1: #ececef;
  --text-2: #a1a1aa;
  --text-3: #63636e;
  --text-ghost: #3f3f47;

  /* Accent — indigo with violet undertone */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.25);

  /* Semantic */
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.12);

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.1);
  --border-focus: var(--accent);

  /* Layout */
  --nav-width: 252px;
  --panel-width: 380px;
  --header-height: 52px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  /* Motion — snappy, not sluggish */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 120ms;
  --duration: 200ms;
  --duration-slow: 350ms;
}

/* ── Reset ── */

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

body {
  font-family: var(--font-sans);
  background: var(--surface-0);
  color: var(--text-1);
  line-height: 1.55;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* ── Buttons ── */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  user-select: none;

  &:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }

  &:active {
    transform: scale(0.97);
  }

  &.secondary {
    background: var(--surface-3);
    border-color: var(--border);
    color: var(--text-1);
    box-shadow: none;

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

  &.small {
    padding: 3px 7px;
    font-size: 12px;
    background: transparent;
    border: none;
    color: var(--text-3);
    box-shadow: none;

    &:hover {
      color: var(--text-1);
      background: var(--surface-3);
    }
  }

  &.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-2);
    box-shadow: none;

    &:hover {
      background: var(--surface-3);
      color: var(--text-1);
    }
  }

  &.danger {
    background: var(--danger);
    border-color: transparent;
    color: white;

    &:hover {
      filter: brightness(1.15);
    }
  }

  & svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }
}

/* ── Inputs ── */

input,
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--surface-1);
  color: var(--text-1);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);

  &::placeholder {
    color: var(--text-ghost);
  }

  &:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
  }
}

input[type="search"] {
  &::-webkit-search-cancel-button {
    -webkit-appearance: none;
  }
}

input[type="checkbox"][role="switch"] {
  width: 32px;
  height: 18px;
  appearance: none;
  background: var(--surface-4);
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border);
  padding: 0;
  transition: background var(--duration) var(--ease-out);

  &::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--text-3);
    border-radius: 50%;
    transition: transform var(--duration) var(--ease-spring), background var(--duration) var(--ease-out);
  }

  &:checked {
    background: var(--accent);
    border-color: var(--accent);

    &::after {
      transform: translateX(14px);
      background: white;
    }
  }
}

/* ── Labels ── */

label {
  display: block;
  margin-bottom: 16px;

  & > span {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
  }

  &:has(input[role="switch"]) {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;

    & > span {
      margin-bottom: 0;
      font-size: 13px;
      font-weight: 500;
    }
  }

  & .required {
    color: var(--danger);
    font-weight: 400;
    font-size: inherit;
    background: none;
    padding: 0;
    margin-left: 1px;
  }

  & .field-error {
    display: block;
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
  }

  & .field-hint {
    display: block;
    font-size: 12px;
    color: var(--text-2);
    margin-top: 4px;
  }

  &.has-error > input,
  &.has-error > textarea,
  &.has-error > select {
    border-color: var(--danger);
  }
}

/* ── Badge (mark) ── */

mark {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: capitalize;
  background: var(--surface-3);
  color: var(--text-2);

  &::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
  }

  &[data-variant="success"] {
    background: var(--success-soft);
    color: var(--success);
  }

  &[data-variant="warning"] {
    background: var(--warning-soft);
    color: var(--warning);
  }

  &[data-variant="danger"] {
    background: var(--danger-soft);
    color: var(--danger);
  }

  &[data-variant="info"] {
    background: var(--info-soft);
    color: var(--info);
  }
}

/* ── Description List ── */

dl {
  & dt {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 16px;

    &:first-of-type {
      margin-top: 0;
    }
  }

  & dd {
    padding: 6px 0 0;
    font-size: 14px;
    color: var(--text-1);
  }
}

/* ═══════════════════════════════════════
   Admin Shell
   ═══════════════════════════════════════ */

[data-admin] {
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "nav header"
    "nav content";
  min-height: 100vh;
  background: var(--surface-0);

  /* ── Left Sidebar ── */
  & > #admin-nav {
    grid-area: nav;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;

    /* Scrollbar */
    &::-webkit-scrollbar { width: 4px; }
    &::-webkit-scrollbar-thumb {
      background: var(--surface-4);
      border-radius: 4px;
    }

    & [role="banner"] {
      padding: 16px 18px;
      font-size: 14px;
      font-weight: 700;
      color: var(--text-1);
      letter-spacing: -0.01em;
      display: flex;
      align-items: center;
      gap: 10px;
      border-bottom: 1px solid var(--border);
      min-height: var(--header-height);

      & strong {
        font-weight: 700;
      }
    }

    & [role="menubar"] {
      list-style: none;
      flex: 1;
      padding: 8px;

      & [role="separator"] {
        padding: 20px 10px 6px;
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-ghost);
        user-select: none;
      }

      & [role="none"] {
        margin: 1px 0;
      }

      & [role="menuitem"] {
        display: flex;
        align-items: center;
        gap: 9px;
        padding: 7px 10px;
        cursor: pointer;
        border-radius: var(--radius-sm);
        text-decoration: none;
        color: var(--text-2);
        font-size: 13px;
        font-weight: 500;
        transition:
          background var(--duration-fast) var(--ease-out),
          color var(--duration-fast) var(--ease-out);
        position: relative;

        &:hover {
          background: var(--surface-3);
          color: var(--text-1);
        }

        &[aria-current="page"] {
          background: var(--accent-soft);
          color: var(--accent-hover);

          &::before {
            content: "";
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 2px;
            height: 16px;
            background: var(--accent);
            border-radius: 2px;
          }
        }

        & [aria-hidden] {
          width: 18px;
          height: 18px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 14px;
          opacity: 0.7;
          flex-shrink: 0;
        }

        & svg {
          width: 16px;
          height: 16px;
          opacity: 0.5;
          flex-shrink: 0;
        }
      }

      /* Collapsible nav groups */
      & .nav-group {
        & > [role="menuitem"] {
          justify-content: space-between;
          background: transparent;
          border: none;
          box-shadow: none;
          width: 100%;
          font-family: var(--font-sans);
          min-height: auto;

          & .nav-chevron {
            width: 14px;
            height: 14px;
            opacity: 0.3;
            margin-left: auto;
            flex-shrink: 0;
            transition: transform var(--duration-fast) var(--ease-out);
          }

          &[aria-expanded="true"] .nav-chevron {
            transform: rotate(90deg);
            opacity: 0.5;
          }
        }

        & [role="group"] {
          list-style: none;
          padding: 0 0 2px 27px;
          margin: 0;

          & [role="menuitem"] {
            font-size: 12.5px;
            padding: 5px 10px;
            color: var(--text-3);

            & svg {
              width: 14px;
              height: 14px;
            }
          }
        }
      }
    }

    & > footer {
      padding: 12px 18px;
      border-top: 1px solid var(--border);
      font-size: 12px;
      color: var(--text-3);
      display: flex;
      align-items: center;
      gap: 8px;

      & > span {
        font-weight: 500;
      }
    }
  }

  /* ── Header ── */
  & > header {
    grid-area: header;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    min-height: var(--header-height);

    & h1 {
      font-size: 14px;
      font-weight: 600;
      color: var(--text-1);
      letter-spacing: -0.01em;
    }

    & > span {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 12px;
      color: var(--text-3);
      font-weight: 500;
    }
  }

  /* ── Page wrapper (holds data-init SSE connection) ── */
  & > #admin-page {
    display: contents;
  }

  /* ── Main Content ── */
  & > #admin-page > main,
  & > main {
    grid-area: content;
    padding: 28px 32px;
    overflow-y: auto;
    background: var(--surface-0);

    /* Scrollbar */
    &::-webkit-scrollbar { width: 6px; }
    &::-webkit-scrollbar-thumb {
      background: var(--surface-4);
      border-radius: 6px;
    }

    & > section {
      max-width: 1100px;
    }
  }

  /* ── Toast Container ── */
  & > [role="status"] {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    max-width: 360px;

    & [role="alert"] {
      pointer-events: auto;
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px 14px;
      border-radius: var(--radius);
      background: var(--surface-3);
      border: 1px solid var(--border);
      box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.2);
      font-size: 13px;
      font-weight: 500;
      color: var(--text-1);
      backdrop-filter: blur(12px);
      animation: toast-enter var(--duration-slow) var(--ease-spring);

      &[data-level="success"] {
        border-left: 3px solid var(--success);
      }

      &[data-level="error"] {
        border-left: 3px solid var(--danger);
      }

      &[data-level="info"] {
        border-left: 3px solid var(--accent);
      }

      & span {
        flex: 1;
      }
    }
  }
}

/* ── Page Header (hgroup) ── */

hgroup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;

  & h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.02em;
  }

  & nav {
    display: flex;
    gap: 8px;
  }
}

/* ── Statistics Grid ── */

[role="grid"][aria-label] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;

  & > article {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    transition: border-color var(--duration) var(--ease-out);

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

    & data {
      display: block;
      font-size: 28px;
      font-weight: 700;
      color: var(--text-1);
      letter-spacing: -0.03em;
      font-variant-numeric: tabular-nums;
      font-family: var(--font-sans);
    }

    & p {
      font-size: 12px;
      color: var(--text-3);
      margin-top: 4px;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }

    & small {
      display: block;
      font-size: 11px;
      font-weight: 600;
      margin-top: 6px;
      color: var(--text-3);

      &[data-variant="success"] { color: var(--success); }
      &[data-variant="warning"] { color: var(--warning); }
      &[data-variant="danger"] { color: var(--danger); }
    }
  }
}

/* ── Table ── */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;

  & th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
    user-select: none;
  }

  & td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-2);
  }

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

  & td a {
    color: var(--text-1);
    text-decoration: none;
    font-weight: 500;

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

/* ── Empty State ── */

section[role="status"] {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-3);
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 14px;

  & p {
    max-width: 300px;
    margin: 0 auto 16px;
    line-height: 1.6;
  }
}

/* ── Panel (right sidebar) ── */

aside[aria-label] {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-width);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  z-index: 7000;
  display: flex;
  flex-direction: column;
  box-shadow:
    -8px 0 24px rgba(0, 0, 0, 0.3),
    -2px 0 8px rgba(0, 0, 0, 0.15);
  animation: panel-enter var(--duration-slow) var(--ease-out);

  & > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);

    & h3 {
      font-size: 14px;
      font-weight: 650;
      color: var(--text-1);
    }
  }

  & > div {
    padding: 20px;
    overflow-y: auto;
    flex: 1;

    &::-webkit-scrollbar { width: 4px; }
    &::-webkit-scrollbar-thumb {
      background: var(--surface-4);
      border-radius: 4px;
    }
  }
}

/* ── Dialog (modal) ── */

dialog[open] {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  border: none;
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: backdrop-enter var(--duration) var(--ease-out);

  & > article {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
      0 16px 48px rgba(0, 0, 0, 0.5),
      0 4px 16px rgba(0, 0, 0, 0.3);
    animation: modal-enter var(--duration-slow) var(--ease-spring);

    & > header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;

      & h3 {
        font-size: 15px;
        font-weight: 650;
        color: var(--text-1);
      }
    }

    & > div {
      padding: 20px;
      color: var(--text-2);
      font-size: 14px;
      line-height: 1.6;
      overflow-y: auto;
      flex: 1;
    }

    & > footer {
      display: flex;
      gap: 8px;
      justify-content: flex-end;
      padding: 14px 20px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }
  }
}

dialog[open] fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 0;

  & legend {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    padding: 0 4px;
  }

  & label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    flex-direction: row;

    & input[type="checkbox"] {
      width: 16px;
      height: 16px;
      margin: 0;
    }

    & span {
      font-size: 13px;
      color: var(--text-1);
    }
  }
}

/* ── Search ── */

search {
  display: block;
  margin-bottom: 16px;
  position: relative;

  & input {
    padding-left: 36px;
    background: var(--surface-2);
  }

  &::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background: var(--text-ghost);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") center / contain no-repeat;
    pointer-events: none;
    z-index: 1;
  }
}

/* ═══════════════════════════════════════
   Login Page
   ═══════════════════════════════════════ */

body[data-page="login"] {
  background: var(--surface-0);
  min-height: 100vh;

  /* Subtle radial glow behind the card */
  &::before {
    content: "";
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 400px;
    background: radial-gradient(ellipse, var(--accent-soft), transparent 70%);
    pointer-events: none;
    z-index: 0;
  }

  & > main {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;

    & > article {
      background: var(--surface-1);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 36px;
      width: 100%;
      max-width: 380px;
      box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.2);

      & h1 {
        font-size: 18px;
        font-weight: 700;
        margin-bottom: 24px;
        text-align: center;
        color: var(--text-1);
        letter-spacing: -0.02em;
      }

      & p {
        text-align: center;
        color: var(--text-3);
        margin-bottom: 20px;
        font-size: 13px;
        line-height: 1.5;

        & strong {
          color: var(--text-1);
          font-weight: 600;
        }
      }

      & [role="alert"] {
        color: var(--danger);
        font-size: 13px;
        text-align: center;
        margin-bottom: 12px;
        font-weight: 500;
      }

      & button {
        width: 100%;
        padding: 9px 16px;
        margin-top: 4px;
      }
    }
  }
}

/* ═══════════════════════════════════════
   User Avatar
   ═══════════════════════════════════════ */

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ═══════════════════════════════════════
   Mobile Navigation
   ═══════════════════════════════════════ */

.mobile-nav-toggle {
  display: none;
}

.mobile-nav-close {
  display: none;
}

/* ═══════════════════════════════════════
   Section Heading (dashboard)
   ═══════════════════════════════════════ */

.section-heading {
  font-size: 14px;
  font-weight: 650;
  color: var(--text-2);
  margin: 24px 0 12px;
  letter-spacing: -0.01em;
}

/* ═══════════════════════════════════════
   Contextual element styles
   ═══════════════════════════════════════ */

/* Buttons in panels fill width */
aside[aria-label] button:not(.small) {
  width: 100%;
  margin-bottom: 8px;
}

/* Dividers in panels */
aside[aria-label] hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Monospace code in table cells and definition lists */
td code,
dd code {
  font-family: var(--font-mono);
  font-size: 12px;
}

code.muted {
  color: var(--text-3);
}

/* Empty table row placeholder */
.empty-row {
  text-align: center;
  padding: 32px !important;
  color: var(--text-3);
}

/* Muted text (used for counts, etc.) */
.muted {
  color: var(--text-3);
}

/* Standalone muted paragraph (for counts below tables, etc.) */
p.muted {
  font-size: 12px;
  margin-top: 12px;
}

/* Panel subheading */
.panel-subheading {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

/* Assignment list (role users, etc.) */
.assignment-list {
  list-style: none;
  padding: 0;
  margin: 0;

  & > li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
  }
}

/* ═══════════════════════════════════════
   Monospace Input
   ═══════════════════════════════════════ */

.mono-input {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ═══════════════════════════════════════
   Panel / Block Components
   ═══════════════════════════════════════ */

.panel-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.inline-select {
  width: auto;
  padding: 4px 8px;
  font-size: 12px;
}

.empty-hint {
  text-align: center;
  padding: 20px;
  color: var(--text-3);
  font-size: 13px;
}

.block-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

.block-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.block-type-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
}

.block-card-body {
  font-size: 13px;
  color: var(--text-2);
  word-break: break-word;
}

.block-card-label {
  font-weight: 600;
  font-size: 13px;
}

.block-card-url {
  margin-left: 8px;
  font-size: 11px;
}

.word-break {
  word-break: break-all;
}

/* ═══════════════════════════════════════
   Media Grid
   ═══════════════════════════════════════ */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.media-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out);

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

.media-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
}

.media-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border-radius: 4px;
  font-size: 32px;
  color: var(--text-3);
}

.media-filename {
  margin: 8px 0 2px;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-preview {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.media-preview-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 48px;
  color: var(--text-3);
}

/* ═══════════════════════════════════════
   Media Picker (choose-an-image dialog)
   ═══════════════════════════════════════ */

dialog.media-picker {
  & > article {
    width: min(760px, 92vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
  }

  & .media-picker-upload {
    display: flex;
    gap: 8px;
    align-items: end;
    padding: 12px 16px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;

    & > .upload-label {
      flex: 1;
      margin: 0;
    }
  }

  & .media-picker-grid-wrap {
    overflow-y: auto;
    flex: 1;
    min-height: 120px;
  }

  /* Image fields show a square thumbnail, not a filename caption list. */
  & .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

/* Inline image field: preview thumbnail + choose/remove actions. */
.media-field {
  display: flex;
  flex-direction: column;
  gap: 8px;

  & > .media-field-preview {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
  }

  & > .media-field-actions {
    display: flex;
    gap: 8px;
  }
}

/* ═══════════════════════════════════════
   Font Picker (choose-a-font dialog)
   ═══════════════════════════════════════ */

dialog.font-picker {
  & > article {
    width: min(680px, 94vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
  }

  & > article > header {
    padding: 20px 22px 14px;
    align-items: flex-start;

    & h3 {
      margin: 0;
    }

    & p {
      margin: 2px 0 0;
      font-size: 13px;
      color: var(--text-3);
    }
  }

  /* Sticky search bar with an inset icon. */
  & .font-search {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 22px 14px;

    & > svg {
      position: absolute;
      left: 36px;
      color: var(--text-3);
      pointer-events: none;
    }

    & > input {
      width: 100%;
      padding-left: 38px;
    }
  }

  & .font-list {
    list-style: none;
    margin: 0;
    padding: 0 22px 22px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  & .font-option {
    width: 100%;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 18px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-out),
      background var(--duration-fast) var(--ease-out),
      transform var(--duration-fast) var(--ease-out);

    &:hover {
      border-color: var(--border-hover);
      background: var(--surface-2);
      transform: translateY(-1px);
    }

    &.active {
      border-color: var(--accent);
      box-shadow: 0 0 0 1px var(--accent) inset;
    }
  }

  & .font-option-head {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  & .font-option-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-1);
    letter-spacing: -0.01em;
  }

  & .font-option-cat {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    background: var(--surface-3);
    padding: 2px 7px;
    border-radius: 999px;
  }

  /* The check sits at the right and only shows for the active font. */
  & .font-option-check {
    margin-left: auto;
    display: inline-flex;
    color: var(--accent);
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-out);
  }

  & .font-option.active .font-option-check {
    opacity: 1;
  }

  /* The live preview, rendered in the font itself (see fontFamilyRules). */
  & .font-option-preview {
    font-size: 28px;
    line-height: 1.25;
    color: var(--text-1);
    /* Avoid layout shift while the web font swaps in. */
    min-height: 1.25em;
  }
}

/* Inline font field: a select-like button that opens the picker. */
.font-field {
  & > .font-field-current {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
}

/* ═══════════════════════════════════════
   Upload Form
   ═══════════════════════════════════════ */

.upload-form {
  display: flex;
  gap: 8px;
  align-items: end;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.upload-label {
  flex: 1;
}

/* ═══════════════════════════════════════
   Error Page
   ═══════════════════════════════════════ */

article[data-error-page] {
  text-align: center;

  & > h1 {
    font-size: 48px;
    font-weight: 800;
    color: var(--text-3);
    margin-bottom: 8px;
    letter-spacing: -0.04em;
  }

  & > p {
    margin-bottom: 24px;
  }

  & > a {
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;

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

/* ═══════════════════════════════════════
   Responsive
   ═══════════════════════════════════════ */

/* Desktop: sidebar nav always visible, override data-show inline style */
@media (min-width: 769px) {
  [data-admin] > #admin-nav {
    display: flex !important;
  }
}

@media (max-width: 768px) {
  .mobile-nav-toggle {
    display: flex;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text-2);
    padding: 4px;
    margin-right: 8px;

    &:hover {
      color: var(--text-1);
      background: var(--surface-3);
    }

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

  .mobile-nav-close {
    display: flex;
    margin-left: auto;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text-3);
    padding: 4px;

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

  [data-admin] {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "header"
      "content";

    & > #admin-nav {
      position: fixed;
      inset: 0;
      z-index: 9999;
      background: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(4px);
      display: flex;
      flex-direction: column;
      animation: nav-overlay-enter var(--duration) var(--ease-out);

      /* Nav content sits on the left side */
      width: 280px;
      background: var(--surface-1);
      border-right: 1px solid var(--border);
      box-shadow: 8px 0 24px rgba(0, 0, 0, 0.3);
    }

    & > #admin-page > main,
    & > main {
      padding: 20px 16px;
    }
  }

  aside[aria-label] {
    width: 100%;
  }

  dialog[open] > article {
    width: 95%;
    max-width: none;
    margin: 0 auto;
  }

  /* Header — compact on mobile */
  [data-admin] > header {
    padding: 0 12px;

    & h1 {
      font-size: 16px;
    }
  }

  /* Tables in admin — allow horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;

    & thead, & tbody, & tr {
      display: table;
      width: 100%;
      table-layout: fixed;
    }
  }

  /* Buttons — adequate touch targets */
  button {
    min-height: 40px;
    padding-left: 14px;
    padding-right: 14px;
  }

  button.small {
    min-height: 34px;
  }

  /* Bottom sheet — modals slide up from bottom on mobile */
  dialog[open] {
    align-items: flex-end;

    & > article {
      width: 100%;
      max-width: 100%;
      max-height: 85vh;
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
      margin: 0;
      padding-bottom: calc(16px + env(safe-area-inset-bottom));
      animation: sheet-enter var(--duration-slow) var(--ease-out);
      overflow-y: auto;
      overscroll-behavior: contain;
    }

    & > article::before {
      content: "";
      display: block;
      width: 36px;
      height: 4px;
      background: var(--surface-4);
      border-radius: 2px;
      margin: 8px auto 12px;
    }
  }

  /* Compact mobile header — show only avatar, hide rest */
  [data-admin] > header .header-actions {
    & > nav[aria-label="Language"],
    & > .theme-toggle,
    & > button[aria-label="Keyboard shortcuts"] {
      display: none;
    }

    /* Hide username text next to avatar */
    font-size: 0;
    gap: 0;

    & > .user-avatar {
      font-size: 11px;
    }
  }

  /* Content padding for tab bar */
  [data-admin] > #admin-page > main,
  [data-admin] > main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
}

/* ═══════════════════════════════════════
   Mobile Tab Bar (bottom navigation)
   ═══════════════════════════════════════ */

#admin-tabbar {
  display: none;
}

@media (max-width: 768px) {
  #admin-tabbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 6000;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
    -webkit-tap-highlight-color: transparent;

    & a, & button {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      padding: 6px 12px;
      font-size: 10px;
      font-weight: 500;
      font-family: var(--font-sans);
      color: var(--text-3);
      text-decoration: none;
      background: transparent;
      border: none;
      box-shadow: none;
      position: relative;
      transition: color var(--duration-fast) ease;
      min-height: auto;

      & svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
      }

      &[aria-current="page"] {
        color: var(--accent);
      }

      &:active {
        color: var(--accent-hover);
      }
    }

    & mark {
      position: absolute;
      top: 2px;
      right: 2px;
      background: var(--danger);
      color: white;
      font-size: 9px;
      font-weight: 700;
      min-width: 16px;
      height: 16px;
      border-radius: 8px;
      display: grid;
      place-items: center;
      padding: 0 4px;
      line-height: 1;
    }
  }
}

/* ═══════════════════════════════════════
   Mobile Utility Classes
   ═══════════════════════════════════════ */

/* Desktop: show desktop-only (natural display), hide mobile-only */
.mobile-only { display: none !important; }

/* Mobile: flip visibility */
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only  { display: block !important; }
}

/* ═══════════════════════════════════════
   Animations
   ═══════════════════════════════════════ */

@keyframes toast-enter {
  from {
    opacity: 0;
    transform: translateX(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes backdrop-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes nav-overlay-enter {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes sheet-enter {
  from {
    opacity: 0.8;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ═══════════════════════════════════════
   Light Mode
   Supports both OS preference and explicit toggle via data-theme.
   html[data-theme="dark"] forces dark mode (tokens from :root).
   ═══════════════════════════════════════ */

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    /* Surface system — layered light */
    --surface-0: #f8f9fb;
    --surface-1: #ffffff;
    --surface-2: #f1f3f5;
    --surface-3: #e9ecef;
    --surface-4: #dee2e6;
    --surface-raised: #ffffff;

    /* Text hierarchy */
    --text-1: #1a1a2e;
    --text-2: #495057;
    --text-3: #868e96;
    --text-ghost: #ced4da;

    /* Borders */
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.12);

    /* Accent — keep same hue, slightly deeper for contrast */
    --accent-soft: rgba(99, 102, 241, 0.08);
    --accent-glow: rgba(99, 102, 241, 0.15);

    /* Semantic soft backgrounds — lighter for light mode */
    --success-soft: rgba(52, 211, 153, 0.1);
    --warning-soft: rgba(251, 191, 36, 0.1);
    --danger-soft: rgba(248, 113, 113, 0.1);
    --info-soft: rgba(96, 165, 250, 0.1);
  }
}

html[data-theme="light"] {
  --surface-0: #f8f9fb;
  --surface-1: #ffffff;
  --surface-2: #f1f3f5;
  --surface-3: #e9ecef;
  --surface-4: #dee2e6;
  --surface-raised: #ffffff;
  --text-1: #1a1a2e;
  --text-2: #495057;
  --text-3: #868e96;
  --text-ghost: #ced4da;
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.12);
  --accent-soft: rgba(99, 102, 241, 0.08);
  --accent-glow: rgba(99, 102, 241, 0.15);
  --success-soft: rgba(52, 211, 153, 0.1);
  --warning-soft: rgba(251, 191, 36, 0.1);
  --danger-soft: rgba(248, 113, 113, 0.1);
  --info-soft: rgba(96, 165, 250, 0.1);
}

/* Light mode component overrides — shared between both selectors */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    ::selection { background: rgba(99, 102, 241, 0.15); color: #4f46e5; }
  }
}
html[data-theme="light"] {
  ::selection { background: rgba(99, 102, 241, 0.15); color: #4f46e5; }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) button:not(.secondary):not(.small):not(.ghost) {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    &:hover { box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
  }
}
html[data-theme="light"] button:not(.secondary):not(.small):not(.ghost) {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  &:hover { box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) [data-admin] > #admin-nav {
    background: #f0f1f5;
    & [role="menuitem"] {
      &:hover { background: rgba(0, 0, 0, 0.04); }
      &[aria-current="page"] { background: rgba(99, 102, 241, 0.08); }
    }
  }
}
html[data-theme="light"] [data-admin] > nav {
  background: #f0f1f5;
  & [role="menuitem"] {
    &:hover { background: rgba(0, 0, 0, 0.04); }
    &[aria-current="page"] { background: rgba(99, 102, 241, 0.08); }
  }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) [data-admin] > [role="status"] [role="alert"] {
    background: var(--surface-1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
  }
}
html[data-theme="light"] [data-admin] > [role="status"] [role="alert"] {
  background: var(--surface-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) aside[aria-label] {
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08), -2px 0 8px rgba(0, 0, 0, 0.04);
  }
}
html[data-theme="light"] aside[aria-label] {
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08), -2px 0 8px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) dialog[open] {
    background: rgba(0, 0, 0, 0.25);
    & > article { box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08); }
  }
}
html[data-theme="light"] dialog[open] {
  background: rgba(0, 0, 0, 0.25);
  & > article { box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08); }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) body[data-page="login"] {
    &::before { background: radial-gradient(ellipse, rgba(99, 102, 241, 0.06), transparent 70%); }
    & > main > article { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04); }
  }
}
html[data-theme="light"] body[data-page="login"] {
  &::before { background: radial-gradient(ellipse, rgba(99, 102, 241, 0.06), transparent 70%); }
  & > main > article { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04); }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) ::-webkit-scrollbar-thumb {
    background: var(--surface-4);
    &:hover { background: var(--text-ghost); }
  }
}
html[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  &:hover { background: var(--text-ghost); }
}

/* ═══════════════════════════════════════
   Scrollbar global
   ═══════════════════════════════════════ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: 6px;

  &:hover {
    background: var(--text-ghost);
  }
}

/* ═══════════════════════════════════════
   Activity Feed
   ═══════════════════════════════════════ */

[role="feed"] {
  display: flex;
  flex-direction: column;
  gap: 2px;

  & > article {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    transition: background var(--duration-fast) var(--ease-out);

    &:hover {
      background: var(--surface-2);
    }

    & > span[aria-hidden] {
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      background: var(--surface-3);
      border-radius: 50%;
      color: var(--text-2);

      & svg {
        width: 15px;
        height: 15px;
      }
    }

    & > div {
      flex: 1;
      min-width: 0;

      & > p {
        font-size: 13px;
        font-weight: 550;
        color: var(--text-1);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      & > small {
        display: block;
        font-size: 12px;
        color: var(--text-3);
        margin-top: 1px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    & > time {
      flex-shrink: 0;
      font-size: 12px;
      color: var(--text-3);
      font-variant-numeric: tabular-nums;
    }
  }
}

/* ═══════════════════════════════════════
   Tabs
   ═══════════════════════════════════════ */

[role="tablist"] {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;

  & [role="tab"] {
    padding: 9px 16px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--text-3);
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
    position: relative;
    transition:
      color var(--duration-fast) var(--ease-out),
      background var(--duration-fast) var(--ease-out);

    &:hover {
      color: var(--text-1);
      background: var(--surface-2);
    }

    &[aria-selected="true"] {
      color: var(--accent-hover);
      background: transparent;

      &::after {
        content: "";
        position: absolute;
        bottom: -1px;
        left: 0;
        right: 0;
        height: 2px;
        background: var(--accent);
        border-radius: 2px 2px 0 0;
      }
    }
  }
}

/* ═══════════════════════════════════════
   Filter Bar
   ═══════════════════════════════════════ */

.filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;

  & > label {
    margin-bottom: 0;
    flex: 0 1 auto;
    min-width: 140px;

    & > select {
      background: var(--surface-2);
    }
  }
}

/* ═══════════════════════════════════════
   Key-Value List
   ═══════════════════════════════════════ */

[role="list"][aria-label="Details"] {
  display: flex;
  flex-direction: column;
  gap: 0;

  & > [role="listitem"] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);

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

    & > dt {
      font-size: 13px;
      font-weight: 500;
      color: var(--text-3);
      flex-shrink: 0;
      margin-top: 0;
      text-transform: none;
      letter-spacing: normal;
    }

    & > dd {
      font-size: 13px;
      color: var(--text-1);
      text-align: right;
      padding: 0;
      font-variant-numeric: tabular-nums;
    }
  }
}

/* ═══════════════════════════════════════
   Pagination
   ═══════════════════════════════════════ */

nav[aria-label="Pagination"] {
  margin-top: 20px;
  display: flex;
  justify-content: center;

  & ol {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;

    & li {
      & span[aria-hidden] {
        padding: 4px 6px;
        color: var(--text-ghost);
        font-size: 13px;
        user-select: none;
      }
    }

    & button {
      min-width: 32px;
      padding: 5px 10px;
      font-size: 13px;
      font-variant-numeric: tabular-nums;
      background: var(--surface-3);
      border-color: var(--border);
      color: var(--text-1);
      box-shadow: none;

      &[aria-current="page"] {
        background: var(--accent-soft);
        color: var(--accent-hover);
        border-color: transparent;
        cursor: default;

        &:hover {
          background: var(--accent-soft);
        }

        &:active {
          transform: none;
        }
      }

      &:disabled {
        opacity: 0.35;
        cursor: not-allowed;

        &:active {
          transform: none;
        }
      }
    }
  }
}

/* ═══════════════════════════════════════
   Breadcrumbs
   ═══════════════════════════════════════ */

nav[aria-label="Breadcrumb"] {
  & ol {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    font-size: 13px;
  }

  & a {
    color: var(--text-3);
    cursor: pointer;
    text-decoration: none;

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

  & [aria-current] {
    color: var(--text-1);
    font-weight: 500;
  }

  & [aria-hidden] {
    color: var(--text-ghost);
  }
}

/* ═══════════════════════════════════════
   Notification Bell & Dropdown
   ═══════════════════════════════════════ */

.notif-bell {
  position: relative;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text-3);
  padding: 4px;
  cursor: pointer;

  &:hover {
    color: var(--text-1);
    background: var(--surface-3);
  }

  & svg {
    width: 16px;
    height: 16px;
  }
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.notif-dropdown {
  position: absolute;
  top: calc(var(--header-height) - 4px);
  right: 16px;
  width: 340px;
  max-height: 400px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 6000;
  overflow: hidden;
  animation: modal-enter var(--duration) var(--ease-out);

  & > header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
  }

  & ul {
    list-style: none;
    max-height: 340px;
    overflow-y: auto;
  }

  & li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background var(--duration-fast) var(--ease-out);

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

    &:hover {
      background: var(--surface-3);
    }

    &[data-unread="true"] {
      background: var(--accent-soft);
    }

    &[data-level="success"] .notif-content strong { color: var(--success); }
    &[data-level="warning"] .notif-content strong { color: var(--warning); }
    &[data-level="error"] .notif-content strong { color: var(--danger); }
    &[data-level="info"] .notif-content strong { color: var(--info); }
  }

  & .notif-content {
    flex: 1;
    min-width: 0;

    & strong {
      display: block;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-1);
    }

    & p {
      font-size: 12px;
      color: var(--text-3);
      margin-top: 2px;
      line-height: 1.4;
    }
  }

  & time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-ghost);
    font-variant-numeric: tabular-nums;
  }

  & .notif-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
  }
}

/* ═══════════════════════════════════════
   Theme Toggle
   ═══════════════════════════════════════ */

.theme-toggle {
  position: relative;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text-3);
  padding: 4px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  overflow: hidden;

  &:hover {
    color: var(--text-1);
    background: var(--surface-3);
  }

  & svg {
    width: 16px;
    height: 16px;
  }
}

/* Dark mode (default): show sun icon to switch to light */
.theme-icon-light { display: inline-flex; }
.theme-icon-dark { display: none; }

/* Light mode: show moon icon to switch to dark */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    .theme-icon-light { display: none; }
    .theme-icon-dark { display: inline-flex; }
  }
}
html[data-theme="light"] {
  .theme-icon-light { display: none; }
  .theme-icon-dark { display: inline-flex; }
}
html[data-theme="dark"] {
  .theme-icon-light { display: inline-flex; }
  .theme-icon-dark { display: none; }
}

/* Header actions container */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;

  & nav[aria-label="Language"] {
    display: flex;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    overflow: hidden;

    & button {
      background: none;
      border: none;
      padding: 4px 10px;
      font-size: 11px;
      font-weight: 500;
      color: var(--text-2);
      cursor: pointer;
      transition: all var(--transition);

      &:not(:last-child) { border-right: 1px solid var(--border); }
      &:hover { color: var(--text-0); }
      &[aria-current="true"] {
        background: var(--accent);
        color: white;
        cursor: default;
      }
    }
  }
}

/* ═══════════════════════════════════════
   Date Picker / Date Range
   ═══════════════════════════════════════ */

input[type="date"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) input[type="date"] {
    color-scheme: light;
  }
}
html[data-theme="light"] input[type="date"] {
  color-scheme: light;
}

.date-range {
  display: flex;
  align-items: flex-end;
  gap: 12px;

  & > label {
    flex: 1;
    margin-bottom: 16px;
  }
}

/* ═══════════════════════════════════════
   Tag Input / Multi-Select
   ═══════════════════════════════════════ */


/* ═══════════════════════════════════════
   Map Component (Leaflet)
   ═══════════════════════════════════════ */

.leaflet-map {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  z-index: 0;
}

/* ═══════════════════════════════════════
   Calendar View
   ═══════════════════════════════════════ */

.calendar {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.calendar-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calendar-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--text-1);
  letter-spacing: -0.01em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-dow {
  padding: 8px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  user-select: none;
}

.calendar-day {
  min-height: 80px;
  padding: 4px 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: background var(--duration-fast) var(--ease-out);

  &:nth-child(7n + 14) {
    border-right: none;
  }

  &:hover {
    background: var(--surface-2);
  }

  & > [aria-hidden] {
    display: block;
    height: 20px;
    margin: 1px 0;
  }
}

.calendar-day-blank {
  background: var(--surface-2);
  opacity: 0.5;
}

.calendar-day-today {
  background: var(--accent-soft);

  & .calendar-day-num {
    background: var(--accent);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.calendar-day-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  display: block;
  margin-bottom: 2px;
}

.calendar-events {
  display: flex;
  gap: 3px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.calendar-event {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;

  &[data-variant="success"] { background: var(--success); }
  &[data-variant="info"] { background: var(--info); }
  &[data-variant="warning"] { background: var(--warning); }
  &[data-variant="danger"] { background: var(--danger); }
}

.calendar-bar {
  display: block;
  height: 20px;
  line-height: 20px;
  border-radius: 0;
  margin: 1px 0;
  padding: 0;
  background: var(--info);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  transition: filter var(--duration-fast) var(--ease-out);

  &:hover { filter: brightness(1.15); }

  &[data-variant="discount"] { background: var(--accent); }
  &[data-variant="sale"] { background: var(--success); }

  /* Extend bars into cell borders to create seamless connection */
  &[data-start] {
    margin-left: 6px;
    padding-left: 6px;
    border-radius: 4px 0 0 4px;
    margin-right: -1px;
  }
  &[data-middle] {
    margin-left: -1px;
    margin-right: -1px;
  }
  &[data-end] {
    margin-right: 6px;
    margin-left: -1px;
    border-radius: 0 4px 4px 0;
  }
  &[data-single] {
    margin-left: 6px;
    margin-right: 6px;
    padding-left: 6px;
    border-radius: 4px;
  }

  /* Row-start: bar continues from previous week, show label with left margin */
  &[data-row-start] {
    margin-left: 6px;
    padding-left: 6px;
    border-radius: 4px 0 0 4px;
    margin-right: -1px;
  }

  /* Row-end: bar continues to next week, flush right */
  &[data-row-end] {
    margin-left: -1px;
    margin-right: 0;
    border-radius: 0;
  }

  /* Both row-start and row-end (single day that continues both ways) */
  &[data-row-start][data-row-end] {
    margin-left: 6px;
    margin-right: 0;
    border-radius: 4px 0 0 4px;
  }
}

.calendar-legend {
  display: flex;
  gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);

  & > span {
    display: flex;
    align-items: center;
    gap: 6px;

    &::before {
      content: '';
      width: 10px;
      height: 6px;
      border-radius: 3px;
      display: inline-block;
    }
  }

  & > span:first-child::before { background: var(--accent); }
  & > span:nth-child(2)::before { background: var(--success); }
}

.calendar-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calendar-sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-1);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-out);

  &:hover { background: var(--surface-2); }

  & > .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  & > .dot[data-variant="discount"] { background: var(--accent); }
  & > .dot[data-variant="sale"] { background: var(--success); }

  & > .meta {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
  }
}

/* ═══════════════════════════════════════
   Keyboard Shortcuts Modal
   ═══════════════════════════════════════ */

#admin-shortcuts {
  /* data-show handles visibility; when hidden, display:none */

  & .shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 0;

    & > div {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid var(--border);

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

    & dt {
      margin-top: 0;
      text-transform: none;
      letter-spacing: normal;
    }

    & dd {
      font-size: 13px;
      color: var(--text-2);
      padding: 0;
    }
  }

  & kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-1);
  }
}

/* ═══════════════════════════════════════
   Detail Cards — section-based editing
   ═══════════════════════════════════════ */

.admin-card {
  background: var(--surface-3);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 0.75rem;

  & > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
  }

  & > header > h3 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
  }

  & > p {
    font-size: 0.875rem;
    margin: 0;
  }
}

/* 2-column grid definition list for detail cards */
dl.admin-dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 2rem;
  margin: 0;

  & > div { min-width: 0; }
  & > div.full { grid-column: 1 / -1; }

  & dt {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 2px 0;
  }

  & dd {
    font-size: 13px;
    color: var(--text-1);
    margin: 0;
    padding: 0;
  }
}

/* Inline edit forms within cards */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;

  & label > span {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-3);
    margin-bottom: 4px;
  }
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding-top: 0.25rem;
}

/* --- Searchable Single-Select ---
   Server-driven picker variant that manages one ID at a time. Shares the
   search-input + options-list structure with the multi-select, but has no
   chip row — the parent template shows the current value, and clicks set
   the scalar signal client-side. */
.searchable-single-select {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;

  & > label {
    display: flex;
    flex-direction: column;
    gap: 4px;

    & > span {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-2);
      letter-spacing: 0.01em;
    }

    & > input[type="search"] {
      width: 100%;
    }
  }

  & > ul[role="listbox"] {
    max-height: 220px;
    overflow-y: auto;
    background: var(--surface-1);
    border: 1px solid var(--border-color, var(--border));
    border-radius: var(--radius-2, var(--radius));
    box-shadow: var(--shadow-3);
    list-style: none;
    margin: 0;
    padding: 4px;

    & > li {
      padding: 8px 12px;
      border-radius: var(--radius-1, 4px);
      font-size: 13px;
      cursor: pointer;
      transition: background var(--duration-fast) var(--ease-out);

      &[role="option"]:hover {
        background: var(--surface-3);
      }

      &[role="option"][aria-selected="true"] {
        background: var(--accent-soft);
        color: var(--accent-hover);
        font-weight: 550;

        &::before {
          content: "✓";
          display: inline-block;
          margin-right: 6px;
          color: var(--accent);
        }
      }

      &[aria-disabled="true"] {
        color: var(--text-2);
        font-style: italic;
        cursor: default;
        text-align: center;
      }
    }
  }
}

/* --- Searchable Multi-Select ---
   Server-driven picker: search input debounces to an SSE endpoint that
   morphs the whole <section> back. The two child <ul>s are distinguished
   by role — role="list" carries the selected chips, role="listbox" carries
   the filtered options. */
.searchable-multi-select {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;

  & > label {
    display: flex;
    flex-direction: column;
    gap: 4px;

    & > span {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-2);
      letter-spacing: 0.01em;
    }

    & > input[type="search"] {
      width: 100%;
    }
  }

  & > ul[role="list"] {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;

    & > li {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 2px 2px 2px 10px;
      border-radius: 999px;
      background: var(--accent-soft);
      border: 1px solid var(--accent);
      color: var(--accent-hover);
      font-size: 12px;
      font-weight: 550;

      & > mark {
        background: transparent;
        color: inherit;
        padding: 0;
      }

      & > button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        padding: 0;
        border-radius: 50%;
        font-size: 11px;
        line-height: 1;
        color: inherit;

        &:hover {
          background: var(--accent);
          color: var(--surface-1);
        }
      }
    }
  }

  & > ul[role="listbox"] {
    max-height: 220px;
    overflow-y: auto;
    background: var(--surface-1);
    border: 1px solid var(--border-color, var(--border));
    border-radius: var(--radius-2, var(--radius));
    box-shadow: var(--shadow-3);
    list-style: none;
    margin: 0;
    padding: 4px;

    & > li {
      padding: 8px 12px;
      border-radius: var(--radius-1, 4px);
      font-size: 13px;
      cursor: pointer;
      transition: background var(--duration-fast) var(--ease-out);

      &[role="option"]:hover {
        background: var(--surface-3);
      }

      &[aria-disabled="true"] {
        color: var(--text-2);
        font-style: italic;
        cursor: default;
        text-align: center;
      }
    }
  }
}

/* ============================================
   Theme Builder — Split-pane customizer
   ============================================ */
.theme-builder {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 3.5rem);
  margin: calc(var(--admin-gap, 1.5rem) * -1);
}

.builder-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-block-end: 1px solid var(--border, #e0e0e0);
  background: var(--surface-1, #fff);
  flex-shrink: 0;
}

.builder-tabs {
  display: flex;
  background: var(--surface-2, #f5f5f5);
  border-radius: 6px;
  padding: 2px;

  & button {
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 4px;
    background: none;
    color: var(--text-2, #666);
    border: none;
    cursor: pointer;

    &.active {
      background: var(--surface-1, #fff);
      color: var(--text-1, #111);
      box-shadow: 0 1px 3px oklch(0 0 0 / 0.08);
    }
  }
}

.builder-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.device-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface-2, #f5f5f5);
  border-radius: 6px;
  padding: 2px;

  & button.active {
    background: var(--surface-1, #fff);
    box-shadow: 0 1px 3px oklch(0 0 0 / 0.08);
  }
}

.builder-panes {
  display: grid;
  /* Edit panel scales with the window (never too cramped for section rows + the add-section
     grid), preview takes the rest. */
  grid-template-columns: clamp(440px, 30%, 560px) 1fr;
  flex: 1;
  overflow: hidden;
  position: relative; /* anchor for the quick-edit overlay panel */
}

/* Quick-edit mode: a focused, full-width editor for simple content pages (Terms/About)
   where the iframe adds little. The panel OVERLAYS the preview rather than hiding it, so the
   preview keeps its measured width and re-fits correctly the moment quick-edit is toggled off. */
.theme-builder.quick-edit .builder-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--surface, #fff);
  border-inline-end: none;
  /* Cover the whole panes area so the (still-measured) preview underneath is hidden,
     and center the editor content to a comfortable reading width. */
  padding-inline: max(1.5rem, calc((100% - 860px) / 2));
}

.builder-panel {
  overflow-y: auto;
  border-inline-end: 1px solid var(--border, #e0e0e0);
  padding: 1rem;
}

.builder-preview {
  background: var(--surface-2, #f5f5f5);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1rem;
  overflow: hidden;
  position: relative;

  /* Desktop renders a real 1440px desktop viewport scaled to fit the pane (size/transform set
     by Datastar from the measured pane, since CSS can't compute a unitless scale from a width).
     This fills the pane AND shows the page proportionally — not a tiny box, not a 1:1 zoom-in. */
  & iframe {
    flex-shrink: 0; /* keep the 1440px logical width — the transform does the fitting, not flexbox */
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    background: oklch(0.99 0 0);
    transform-origin: top center;
  }

  /* Mobile preview is a centred phone frame filling the available height. */
  &.mobile iframe {
    width: 390px;
    height: 100%;
    max-height: 860px;
    transform: none;
    border-radius: 24px;
    box-shadow: 0 8px 32px oklch(0 0 0 / 0.12);
  }
}

.builder-sections h3,
.builder-add-section h4 {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2, #666);
  margin-block-end: 0.75rem;
}

.builder-section-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 6px;
  margin-block-end: 0.375rem;
  background: var(--surface-1, #fff);

  &:hover { border-color: var(--text-2, #999); }
  &.hidden-section { opacity: 0.5; }
  &.drag-over {
    position: relative;

    &::before {
      content: "";
      position: absolute;
      top: -3px;
      left: 0;
      right: 0;
      height: 3px;
      background: var(--brand-1, #4a6cf7);
      border-radius: 2px;
    }
  }

  &.dragging {
    opacity: 0.4;
  }
}

.section-drag-handle {
  color: var(--text-2, #999);
  cursor: grab;
  flex-shrink: 0;
}

.section-info {
  flex: 1;
  min-width: 0;

  & strong { font-size: 0.8125rem; font-weight: 500; }

  & .badge-muted {
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
    background: var(--surface-2, #f5f5f5);
    border-radius: 3px;
    color: var(--text-2, #666);
    margin-inline-start: 0.375rem;
  }
}

.section-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;

  & button {
    padding: 0.25rem;
    color: var(--text-2, #999);
    &:hover { color: var(--text-1, #111); }
  }
}

.builder-add-section { margin-block-start: 1.5rem; }

.add-section-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.375rem;
}

.add-section-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  padding: 0.75rem 0.5rem;
  border: 1px dashed var(--border, #ddd);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 0.6875rem;
  color: var(--text-2, #666);

  &:hover {
    border-color: var(--brand-1, #4a6cf7);
    background: oklch(0.97 0.01 250);
    color: var(--text-1, #111);
  }

  & svg { width: 20px; height: 20px; }
}

/* Constrain the settings form so the label↔control pairs read as a tidy form
   instead of being flung to opposite edges of the wide builder pane. */
.builder-design {
  max-width: 460px;
}

.builder-design h3 {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2, #666);
  margin-block-end: 1rem;
}

.design-group {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem;

  & legend {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-1, #111);
    margin-block-end: 0.75rem;
  }

  & label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.375rem 0;

    & span { font-size: 0.8125rem; }

    & select, & input[type="text"] {
      width: 160px;
      padding: 0.375rem 0.5rem;
      font-size: 0.8125rem;
      border: 1px solid var(--border, #ddd);
      border-radius: 4px;
    }

    & input[type="color"] {
      width: 40px;
      height: 28px;
      border: 1px solid var(--border, #ddd);
      border-radius: 4px;
      cursor: pointer;
      padding: 2px;
    }
  }
}

@media (max-width: 900px) {
  .builder-panes { grid-template-columns: 1fr; }
  .builder-preview { display: none; }
}

/* ── Sub-navigation ── */

.sub-nav {
  display: flex;
  gap: var(--size-2);
  padding-block-end: var(--size-3);
  margin-block-end: var(--size-4);
  border-block-end: 1px solid var(--border);

  & a {
    padding: var(--size-1) var(--size-3);
    border-radius: var(--radius-2);
    font-size: var(--font-size-0);
    color: var(--text-2);
    text-decoration: none;
    transition: background 0.15s;
  }

  & a:hover {
    background: var(--surface-2);
    color: var(--text-1);
  }

  & a[aria-current="page"] {
    background: var(--surface-3);
    color: var(--text-1);
    font-weight: var(--font-weight-6);
  }
}

@media (max-width: 600px) {
  .sub-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;

    & a {
      white-space: nowrap;
      flex-shrink: 0;
    }
  }
}

.badge-draft {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  background: oklch(0.92 0.08 85);
  color: oklch(0.4 0.1 85);
  border-radius: 3px;
  margin-inline-start: 0.5rem;
}

.badge-published {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  background: oklch(0.92 0.08 145);
  color: oklch(0.35 0.1 145);
  border-radius: 3px;
}

/* --- Command palette (Ctrl/Cmd-K global search) --- */
.cmdk {
	position: fixed;
	inset: 0;
	z-index: 2000;
	margin: 0;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	border: none;
	padding: 0;
	background: rgba(0, 0, 0, 0.45);
	display: none;
}
.cmdk[open] { display: block; }
.cmdk-box {
	position: absolute;
	top: 12vh;
	left: 50%;
	transform: translateX(-50%);
	width: min(640px, 92vw);
	background: var(--surface-1, #fff);
	border-radius: 12px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
	overflow: hidden;
}
.cmdk-input {
	width: 100%;
	border: none;
	border-bottom: 1px solid var(--border, #e5e5e5);
	padding: 1rem 1.25rem;
	font-size: 1.05rem;
	background: transparent;
	color: inherit;
	outline: none;
}
.cmdk-results { max-height: 60vh; overflow-y: auto; padding: 0.5rem; }
.cmdk-hint { padding: 1rem 1.25rem; color: var(--text-2, #888); font-size: 0.9rem; margin: 0; }
.cmdk-group-label { padding: 0.5rem 0.85rem 0.25rem; font-size: 0.72rem; text-transform: uppercase; color: var(--text-2, #999); letter-spacing: 0.04em; }
.cmdk-result {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.6rem 0.85rem;
	border-radius: 8px;
	color: inherit;
	text-decoration: none;
}
.cmdk-result:hover, .cmdk-result:focus { background: var(--surface-2, #f4f4f5); outline: none; }
.cmdk-result-type {
	font-size: 0.68rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--text-2, #999);
	background: var(--surface-3, #eee);
	padding: 0.12rem 0.5rem;
	border-radius: 999px;
	flex-shrink: 0;
}
.cmdk-result-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-result-meta { color: var(--text-2, #999); font-size: 0.85rem; flex-shrink: 0; }

/* Support impersonation banner — persistent, high-visibility */
.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: #b45309;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 5000;
}
.impersonation-banner span { display: inline-flex; align-items: center; gap: 0.5rem; }
.impersonation-banner strong { font-weight: 700; }
.impersonation-banner button { flex: none; }
