/* ═══════════════════════════════════════════════════════════════════════════
 * MD.Scribe 3.0 — application stylesheet (Tailwind CSS v4 + shadcn/ui tokens)
 *
 * Built locally by tools/frontend/build.mjs → public/assets/css/app.css.
 * No CDN, ever: fonts, icons, KaTeX and Mermaid are all vendored.
 *
 * Token model follows shadcn/ui exactly (--background, --foreground,
 * --primary, --ring, …). Theme combinations live in themes.css and are
 * selected via [data-neutral] / [data-accent] attributes + the .dark class.
 * ═════════════════════════════════════════════════════════════════════════ */

@import "tailwindcss";

@source "../../../../templates";
@source "../../../../src";
@source "../../../../public/assets/js";

/* ── shadcn token → Tailwind color mapping ─────────────────────────────── */
@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-border: var(--sidebar-border);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);

  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --font-sans: var(--md-font-sans);
  --font-mono: var(--md-font-mono);
}

/* ── Fallback tokens (zinc light) — themes.css overrides per selection ─── */
:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.141 0.005 285.823);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.141 0.005 285.823);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.141 0.005 285.823);
  --primary: oklch(0.21 0.006 285.885);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.967 0.001 286.375);
  --secondary-foreground: oklch(0.21 0.006 285.885);
  --muted: oklch(0.967 0.001 286.375);
  --muted-foreground: oklch(0.552 0.016 285.938);
  --accent: oklch(0.967 0.001 286.375);
  --accent-foreground: oklch(0.21 0.006 285.885);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.985 0 0);
  --border: oklch(0.92 0.004 286.32);
  --input: oklch(0.92 0.004 286.32);
  --ring: oklch(0.705 0.015 286.067);
  --radius: 0.625rem;
  --md-font-sans: "Inter Variable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --md-font-mono: "JetBrains Mono Variable", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  /* reading preferences (set from JS via CSSOM — CSP-safe) */
  --md-reader-scale: 1;
  --md-reader-width: 46rem;
  --md-reader-leading: 1.75;
}

/* ── Local fonts (woff2, subset, variable) ─────────────────────────────── */
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-cyrillic-wght-italic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-latin-ext-wght-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../vendor/fonts/inter-cyrillic-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "JetBrains Mono Variable";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("../vendor/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono Variable";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("../vendor/fonts/jetbrains-mono-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* ═══ Base ═══════════════════════════════════════════════════════════════ */
@layer base {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: 5.5rem;
    -webkit-tap-highlight-color: transparent;
  }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
  body { font-family: var(--md-font-sans); }
  :focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: 2px;
  }
  ::selection { background: color-mix(in oklch, var(--primary) 18%, transparent); }
  /* Slim, theme-aware scrollbars */
  * {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in oklch, var(--muted-foreground) 35%, transparent) transparent;
  }
}

/* ═══ Components (shadcn-style, hand-built) ══════════════════════════════ */

/* ── Buttons ──────────────────────────────────────────────────────────── */
.md-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  height: 2.25rem; padding: 0 0.9rem; border-radius: calc(var(--radius) - 2px);
  font-size: 0.8125rem; font-weight: 500; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; cursor: pointer; user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.md-btn:active { transform: scale(0.98); }
.md-btn:disabled, .md-btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.md-btn-sm { height: 1.875rem; padding: 0 0.65rem; font-size: 0.75rem; border-radius: calc(var(--radius) - 3px); }
.md-btn-lg { height: 2.75rem; padding: 0 1.4rem; font-size: 0.9375rem; }

.md-btn-primary {
  background: var(--primary); color: var(--primary-foreground);
  box-shadow: 0 1px 2px oklch(0 0 0 / 8%);
}
.md-btn-primary:hover { background: color-mix(in oklch, var(--primary) 88%, var(--background)); }

.md-btn-outline {
  background: var(--background); color: var(--foreground);
  border-color: var(--input);
  box-shadow: 0 1px 2px oklch(0 0 0 / 4%);
}
.md-btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }

.md-btn-ghost { background: transparent; color: var(--foreground); }
.md-btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }

.md-btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.md-btn-destructive:hover { background: color-mix(in oklch, var(--destructive) 88%, black); }

.md-btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.md-btn-secondary:hover { background: color-mix(in oklch, var(--secondary) 80%, var(--foreground)); }

.md-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 2rem; width: 2rem; border-radius: calc(var(--radius) - 2px);
  color: var(--muted-foreground); background: transparent; border: 0; cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.md-icon-btn:hover { background: var(--accent); color: var(--accent-foreground); }
.md-icon-btn:disabled { opacity: 0.4; pointer-events: none; }
.md-icon-btn[aria-pressed="true"], .md-icon-btn.md-active { background: var(--accent); color: var(--primary); }

/* ── Header nav ───────────────────────────────────────────────────────── */
.md-nav-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.7rem; border-radius: calc(var(--radius) - 2px);
  font-size: 0.8125rem; font-weight: 500; color: var(--muted-foreground);
  transition: background-color 0.15s, color 0.15s;
}
.md-nav-link:hover { background: var(--accent); color: var(--accent-foreground); }
.md-nav-link-active { background: var(--accent); color: var(--foreground); }

.md-search-trigger {
  display: inline-flex; align-items: center; gap: 0.5rem;
  height: 2rem; padding: 0 0.5rem; margin-right: 0.25rem; min-width: 2rem;
  border-radius: calc(var(--radius) - 2px); border: 1px solid var(--input);
  background: var(--background); color: var(--muted-foreground);
  font-size: 0.8125rem; cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.md-search-trigger:hover { border-color: var(--ring); box-shadow: 0 1px 6px oklch(0 0 0 / 6%); }
@media (min-width: 640px) { .md-search-trigger { width: 15rem; padding: 0 0.6rem; } }

.md-kbd {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px; border-radius: 4px; font-size: 0.6875rem; font-family: var(--md-font-mono);
  border: 1px solid var(--border); background: var(--muted); color: var(--muted-foreground);
  box-shadow: 0 1px 0 var(--border); line-height: 1.4;
}

/* ── Dropdown menu / popover ──────────────────────────────────────────── */
.md-dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 0.375rem); z-index: 60;
  min-width: 11rem; padding: 0.25rem;
  border-radius: calc(var(--radius) - 2px); border: 1px solid var(--border);
  background: var(--popover); color: var(--popover-foreground);
  box-shadow: 0 8px 30px oklch(0 0 0 / 12%), 0 2px 6px oklch(0 0 0 / 6%);
  animation: md-pop 0.14s ease-out;
}
.md-dropdown-menu[hidden] { display: none; }
.md-popover-wide { min-width: 16rem; }
.md-dropdown-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.4rem 0.55rem; border-radius: calc(var(--radius) - 4px);
  font-size: 0.8125rem; cursor: pointer; text-align: left;
  background: transparent; border: 0; color: inherit; text-decoration: none;
  transition: background-color 0.1s;
}
.md-dropdown-item:hover, .md-dropdown-item:focus-visible { background: var(--accent); color: var(--accent-foreground); outline: none; }
.md-dropdown-item[data-checked="true"] { color: var(--primary); font-weight: 600; }
.md-dropdown-separator { height: 1px; margin: 0.25rem -0.25rem; background: var(--border); }
@keyframes md-pop {
  from { opacity: 0; transform: translateY(-3px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */
.md-card {
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--card); color: var(--card-foreground);
  box-shadow: 0 1px 3px oklch(0 0 0 / 4%);
}
.md-card-header {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.9rem 1.1rem; border-bottom: 1px solid color-mix(in oklch, var(--border) 60%, transparent);
}
.md-card-title { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.9rem; font-weight: 600; }
.md-card-body { padding: 0.5rem 1.1rem; }
.md-card-footer {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.9rem 1.1rem; border-top: 1px solid color-mix(in oklch, var(--border) 60%, transparent);
}

/* ── Dialog ───────────────────────────────────────────────────────────── */
.md-dialog-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: oklch(0 0 0 / 55%);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 1rem;
  animation: md-fade 0.15s ease-out;
}
.md-dialog-backdrop[hidden] { display: none; }
.md-dialog {
  width: 100%; max-width: 34rem; max-height: calc(100dvh - 2rem);
  display: flex; flex-direction: column;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--popover); color: var(--popover-foreground);
  box-shadow: 0 24px 70px oklch(0 0 0 / 30%);
  animation: md-dialog-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  overflow: hidden;
}
.md-dialog-sm { max-width: 27rem; }
.md-dialog-lg { max-width: 56rem; }
.md-dialog-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.md-dialog-title { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.9rem; font-weight: 600; }
.md-dialog-body { padding: 1.1rem; overflow-y: auto; }
.md-dialog-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 0.9rem 1.1rem; border-top: 1px solid var(--border);
}
@keyframes md-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes md-dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* ── Sheet (mobile drawer) ────────────────────────────────────────────── */
.md-sheet-backdrop {
  position: fixed; inset: 0; z-index: 80; background: oklch(0 0 0 / 50%);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  animation: md-fade 0.15s ease-out;
}
.md-sheet-backdrop[hidden] { display: none; }
.md-sheet {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(20rem, 86vw);
  background: var(--popover); color: var(--popover-foreground);
  border-right: 1px solid var(--border);
  box-shadow: 0 0 60px oklch(0 0 0 / 25%);
  animation: md-sheet-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.05);
  display: flex; flex-direction: column; overflow-y: auto;
}
.md-sheet-bottom {
  top: auto; left: 0; right: 0; bottom: 0; width: 100%;
  border-right: 0; border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 82dvh; animation: md-sheet-up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.05);
}
@keyframes md-sheet-in { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes md-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.md-sheet-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem; border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem; font-weight: 500; color: var(--popover-foreground);
  transition: background-color 0.12s;
}
.md-sheet-link:hover { background: var(--accent); }
.md-sheet-toc .md-toc { padding: 0; }

/* ── Sidebar links (doc nav) ──────────────────────────────────────────── */
.md-sidebar-link {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.375rem 0.6rem; border-radius: calc(var(--radius) - 3px);
  font-size: 0.8125rem; color: var(--muted-foreground);
  border-left: 2px solid transparent;
  transition: background-color 0.12s, color 0.12s, border-color 0.12s;
  min-width: 0;
}
.md-sidebar-link:hover { background: var(--accent); color: var(--accent-foreground); }
.md-sidebar-link-active {
  background: color-mix(in oklch, var(--primary) 8%, transparent);
  color: var(--primary); font-weight: 600; border-left-color: var(--primary);
}
.md-sidebar-badge {
  margin-left: auto; font-size: 0.6875rem; font-variant-numeric: tabular-nums;
  color: var(--muted-foreground); background: var(--muted);
  border-radius: 999px; padding: 1px 7px;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.md-input, .md-textarea, .md-select {
  width: 100%; background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px);
  padding: 0.45rem 0.7rem; font-size: 0.875rem; line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.md-input::placeholder, .md-textarea::placeholder { color: var(--muted-foreground); opacity: 0.7; }
.md-input:focus, .md-textarea:focus, .md-select:focus {
  outline: none; border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 22%, transparent);
}
.md-input-sm { height: 1.875rem; padding: 0.2rem 0.5rem; font-size: 0.8125rem; }
.md-input-lg { height: 2.75rem; font-size: 0.9375rem; border: 0; background: transparent; }
.md-input-lg:focus { box-shadow: none; }
.md-input-wrap {
  display: flex; align-items: center; gap: 0.55rem;
  border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px);
  background: var(--background); padding: 0 0.6rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.md-input-wrap:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 22%, transparent);
}
.md-input-wrap-lg { border-radius: var(--radius); padding: 0 0.9rem; }
.md-input-wrap .md-input { border: 0; padding: 0.4rem 0; }
.md-input-wrap .md-input:focus { box-shadow: none; }
.md-textarea { min-height: 5rem; resize: vertical; }
.md-font-mono { font-family: var(--md-font-mono); }
.md-label { display: block; font-size: 0.8125rem; font-weight: 500; margin-bottom: 0.3rem; }
.md-hint { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 0.3rem; }
.md-field-error { font-size: 0.75rem; color: var(--destructive); margin-top: 0.3rem; }

.md-input-invalid, .md-input-invalid:focus { border-color: var(--destructive); box-shadow: 0 0 0 3px color-mix(in oklch, var(--destructive) 18%, transparent); }

/* ── Switch (shadcn) ──────────────────────────────────────────────────── */
.md-switch {
  position: relative; display: inline-flex; align-items: center;
  width: 2.5rem; height: 1.375rem; border-radius: 999px; flex-shrink: 0;
  background: var(--input); border: 1px solid transparent; cursor: pointer;
  transition: background-color 0.18s;
}
.md-switch[aria-checked="true"] { background: var(--primary); }
.md-switch:disabled { opacity: 0.5; cursor: not-allowed; }
.md-switch-thumb {
  position: absolute; left: 2px; width: 1.0625rem; height: 1.0625rem;
  border-radius: 999px; background: white;
  box-shadow: 0 1px 3px oklch(0 0 0 / 25%);
  transition: transform 0.18s cubic-bezier(0.3, 0.9, 0.4, 1.1);
}
.md-switch[aria-checked="true"] .md-switch-thumb { transform: translateX(1.0625rem); }

/* ── Segmented control ────────────────────────────────────────────────── */
.md-segmented {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: calc(var(--radius) - 1px);
  background: var(--muted); border: 1px solid color-mix(in oklch, var(--border) 60%, transparent);
}
.md-segment {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.35rem 0.75rem; border-radius: calc(var(--radius) - 3px);
  font-size: 0.8125rem; font-weight: 500; color: var(--muted-foreground);
  background: transparent; border: 0; cursor: pointer;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.md-segment:hover { color: var(--foreground); }
.md-segment[aria-checked="true"], .md-segment.md-segment-active {
  background: var(--background); color: var(--foreground);
  box-shadow: 0 1px 3px oklch(0 0 0 / 10%);
}
.md-segment-icon { padding: 0.4rem; }

/* ── Stepper ──────────────────────────────────────────────────────────── */
.md-stepper {
  display: inline-flex; align-items: center; gap: 0.15rem;
  border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px);
  padding: 2px; background: var(--background);
}
.md-stepper-value {
  min-width: 5.5rem; text-align: center; font-size: 0.75rem;
  font-variant-numeric: tabular-nums; color: var(--foreground); font-weight: 500;
}

/* ── Settings rows ────────────────────────────────────────────────────── */
.md-setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1.5rem; padding: 0.85rem 0;
}
.md-setting-label { min-width: 0; flex: 1; cursor: pointer; }
.md-setting-label p:first-child { font-size: 0.875rem; }
.md-setting-label .text-muted-foreground { font-size: 0.75rem; line-height: 1.5; margin-top: 2px; }
.md-lock-badge {
  display: inline-flex; align-items: center; gap: 3px; vertical-align: 1px;
  font-size: 0.625rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted-foreground); background: var(--muted);
  border-radius: 999px; padding: 2px 7px; margin-left: 0.35rem;
}

/* ── Badges / tags / chips ────────────────────────────────────────────── */
.md-tag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.6875rem; font-weight: 500; color: var(--muted-foreground);
  background: var(--muted); border-radius: 999px; padding: 3px 9px;
}
.md-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.6875rem; font-weight: 600; border-radius: 999px;
  padding: 2px 8px; border: 1px solid transparent;
}
.md-badge-success { background: color-mix(in oklch, oklch(0.723 0.219 149.579) 14%, transparent); color: oklch(0.527 0.154 150.069); border-color: color-mix(in oklch, oklch(0.723 0.219 149.579) 30%, transparent); }
.md-badge-warning { background: color-mix(in oklch, oklch(0.769 0.188 70.08) 16%, transparent); color: oklch(0.554 0.135 66.442); border-color: color-mix(in oklch, oklch(0.769 0.188 70.08) 32%, transparent); }
.md-badge-error { background: color-mix(in oklch, var(--destructive) 12%, transparent); color: var(--destructive); border-color: color-mix(in oklch, var(--destructive) 28%, transparent); }
.md-badge-info { background: color-mix(in oklch, var(--primary) 10%, transparent); color: var(--primary); border-color: color-mix(in oklch, var(--primary) 25%, transparent); }
.md-badge-muted { background: var(--muted); color: var(--muted-foreground); border-color: var(--border); }
.dark .md-badge-success { color: oklch(0.723 0.219 149.579); }
.dark .md-badge-warning { color: oklch(0.828 0.189 84.429); }

.md-folder-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.75rem; font-size: 0.8125rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--foreground);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.md-folder-chip:hover { border-color: var(--ring); box-shadow: 0 2px 8px oklch(0 0 0 / 6%); transform: translateY(-1px); }

/* ── Tables (browser + admin) ─────────────────────────────────────────── */
.md-table { border-collapse: collapse; font-size: 0.8125rem; }
.md-table th, .md-table td { padding: 0.55rem 0.9rem; text-align: left; vertical-align: middle; }
.md-table thead th {
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted-foreground); font-weight: 600;
  border-bottom: 1px solid var(--border); background: color-mix(in oklch, var(--muted) 40%, transparent);
  white-space: nowrap;
}
.md-table tbody tr { border-bottom: 1px solid color-mix(in oklch, var(--border) 55%, transparent); transition: background-color 0.1s; }
.md-table tbody tr:hover { background: color-mix(in oklch, var(--accent) 55%, transparent); }
.md-table tbody tr:last-child { border-bottom: 0; }
.md-th-sortable { cursor: pointer; user-select: none; }
.md-th-sortable:hover { color: var(--foreground); }
.md-th-sortable[data-sorted="asc"]::after { content: " ↑"; }
.md-th-sortable[data-sorted="desc"]::after { content: " ↓"; }
.md-file-link { display: flex; align-items: center; gap: 0.65rem; min-width: 0; padding: 0.3rem 0; color: inherit; text-decoration: none; }
.md-file-link:hover .font-medium { color: var(--primary); }
.md-file-row[data-hidden="1"] { display: none; }

/* ── Search results ───────────────────────────────────────────────────── */
.md-result-card {
  display: block; padding: 0.85rem 1rem; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.md-result-card:hover { border-color: var(--ring); box-shadow: 0 3px 14px oklch(0 0 0 / 7%); transform: translateY(-1px); }
.md-result-head { display: flex; align-items: center; gap: 0.45rem; font-size: 0.9rem; }
.md-result-path { display: block; font-size: 0.6875rem; color: var(--muted-foreground); font-family: var(--md-font-mono); margin-top: 3px; }
.md-result-snippet { display: block; font-size: 0.8rem; color: var(--muted-foreground); margin-top: 0.4rem; line-height: 1.55; }
.md-result-snippet mark, .md-body mark, mark {
  background: color-mix(in oklch, oklch(0.769 0.188 70.08) 35%, transparent);
  color: inherit; border-radius: 3px; padding: 0 2px;
}

/* ── Command palette ──────────────────────────────────────────────────── */
.md-palette-dialog { max-width: 40rem; align-self: start; margin-top: 12dvh; }
.md-palette-input-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border);
}
.md-palette-input {
  flex: 1; background: transparent; border: 0; font-size: 0.9375rem; color: var(--foreground);
  outline: none;
}
.md-palette-input::placeholder { color: var(--muted-foreground); opacity: 0.7; }
.md-palette-list { max-height: min(24rem, 55dvh); overflow-y: auto; padding: 0.4rem; }
.md-palette-group {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted-foreground); padding: 0.55rem 0.6rem 0.25rem;
}
.md-palette-item {
  display: flex; align-items: center; gap: 0.6rem; width: 100%;
  padding: 0.5rem 0.6rem; border-radius: calc(var(--radius) - 4px);
  font-size: 0.8125rem; cursor: pointer; text-align: left;
  background: transparent; border: 0; color: inherit;
}
.md-palette-item[data-active="true"] { background: var(--accent); color: var(--accent-foreground); }
.md-palette-item .md-palette-sub { margin-left: auto; font-size: 0.6875rem; color: var(--muted-foreground); font-family: var(--md-font-mono); }
.md-palette-empty { padding: 2rem 1rem; text-align: center; color: var(--muted-foreground); font-size: 0.8125rem; }
.md-palette-footer {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.5rem 1rem; border-top: 1px solid var(--border);
  font-size: 0.6875rem; color: var(--muted-foreground);
}
.md-palette-footer .md-kbd { margin-right: 3px; }

/* ── Toasts (sonner-style) ────────────────────────────────────────────── */
.md-toaster {
  position: fixed; z-index: 100; bottom: 1rem; right: 1rem;
  display: flex; flex-direction: column-reverse; gap: 0.5rem;
  list-style: none; margin: 0; padding: 0; width: min(23rem, calc(100vw - 2rem));
  pointer-events: none;
}
.md-toast {
  display: flex; align-items: flex-start; gap: 0.55rem; pointer-events: auto;
  padding: 0.7rem 0.9rem; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--popover); color: var(--popover-foreground);
  box-shadow: 0 10px 35px oklch(0 0 0 / 16%);
  font-size: 0.8125rem; line-height: 1.45;
  animation: md-toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.md-toast[data-leaving="1"] { animation: md-toast-out 0.18s ease-in forwards; }
.md-toast-success > svg { color: oklch(0.627 0.194 149.214); }
.md-toast-error > svg { color: var(--destructive); }
.md-toast-info > svg { color: var(--primary); }
.md-toast-warning > svg { color: oklch(0.666 0.179 58.318); }
@keyframes md-toast-in { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes md-toast-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }

/* ── Themes page ──────────────────────────────────────────────────────── */
.md-theme-card {
  text-align: left; padding: 0.55rem; border-radius: calc(var(--radius) + 2px);
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.md-theme-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px oklch(0 0 0 / 8%); }
.md-theme-card[aria-pressed="true"] { border-color: var(--ring); box-shadow: 0 0 0 2px color-mix(in oklch, var(--ring) 35%, transparent); }
.md-theme-card[aria-pressed="true"] .md-theme-check { opacity: 1; }
.md-theme-check { opacity: 0; transition: opacity 0.15s; margin-left: auto; }
.md-theme-card-label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8125rem; }
.md-theme-preview {
  display: block; border-radius: calc(var(--radius) - 2px); overflow: hidden;
  border: 1px solid color-mix(in oklch, var(--foreground) 12%, transparent);
  background: var(--md-pv-bg, oklch(0.98 0 0));
}
.md-theme-preview-bar { display: block; height: 14px; background: var(--md-pv-card, #fff); border-bottom: 1px solid var(--md-pv-border, rgba(0,0,0,.08)); position: relative; }
.md-theme-preview-bar::after { content: ""; position: absolute; left: 6px; top: 5px; width: 26px; height: 4px; border-radius: 2px; background: var(--md-pv-accent, #333); }
.md-theme-preview-body { display: flex; gap: 6px; padding: 8px; min-height: 84px; }
.md-theme-preview-side { width: 22%; border-radius: 4px; background: var(--md-pv-muted, rgba(0,0,0,.06)); }
.md-theme-preview-main { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.md-theme-preview-title { height: 8px; width: 70%; border-radius: 3px; background: var(--md-pv-fg, #222); opacity: 0.85; }
.md-theme-preview-line { height: 5px; border-radius: 3px; background: var(--md-pv-fg, #222); opacity: 0.22; }
.md-theme-preview-btn {
  margin-top: auto; align-self: start; font-size: 8px; line-height: 1;
  padding: 4px 8px; border-radius: 4px;
  background: var(--md-pv-accent, #333); color: var(--md-pv-accent-fg, #fff); font-weight: 600;
}
.md-swatch {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.7rem 0.35rem 0.45rem; font-size: 0.8125rem; font-weight: 500;
  border: 1px solid var(--border); border-radius: 999px; background: var(--card);
  color: var(--foreground); cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.md-swatch:hover { border-color: var(--ring); }
.md-swatch[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in oklch, var(--primary) 30%, transparent); }
.md-swatch-dot { width: 1rem; height: 1rem; border-radius: 999px; border: 1px solid oklch(0 0 0 / 12%); display: inline-block; }

/* ── Dropzone ─────────────────────────────────────────────────────────── */
.md-dropzone {
  display: grid; place-items: center; gap: 0.4rem; text-align: center;
  border: 1.5px dashed var(--input); border-radius: var(--radius);
  padding: 2rem 1.25rem; background: color-mix(in oklch, var(--muted) 35%, transparent);
  transition: border-color 0.15s, background-color 0.15s;
}
.md-dropzone[data-dragover="1"] { border-color: var(--primary); background: color-mix(in oklch, var(--primary) 7%, transparent); }

/* ── Pager ────────────────────────────────────────────────────────────── */
.md-pager {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.8rem 1rem; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}
.md-pager:hover { border-color: var(--ring); box-shadow: 0 2px 10px oklch(0 0 0 / 6%); }
.md-pager-label { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); }
.md-pager-title { font-size: 0.875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-pager-next { text-align: right; align-items: flex-end; }

/* ── Breadcrumb + links ───────────────────────────────────────────────── */
.md-crumb { color: var(--muted-foreground); text-decoration: none; }
.md-crumb:hover { color: var(--foreground); text-decoration: underline; text-underline-offset: 3px; }
.md-link { color: var(--primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in oklch, var(--primary) 40%, transparent); transition: color 0.12s, text-decoration-color 0.12s; }
.md-link:hover { text-decoration-color: var(--primary); }

/* ── Lightbox ─────────────────────────────────────────────────────────── */
.md-lightbox {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: oklch(0.12 0.005 285 / 92%); padding: 2.5rem 1.25rem;
  animation: md-fade 0.15s ease-out; cursor: zoom-out;
}
.md-lightbox[hidden] { display: none; }
.md-lightbox img {
  max-width: 100%; max-height: calc(100dvh - 7rem); object-fit: contain;
  border-radius: calc(var(--radius) - 2px); box-shadow: 0 30px 90px oklch(0 0 0 / 60%);
  cursor: default; animation: md-dialog-in 0.2s ease-out;
}
.md-lightbox-close {
  position: absolute; top: 1rem; right: 1rem; z-index: 2;
  display: grid; place-items: center; width: 2.5rem; height: 2.5rem;
  border-radius: 999px; border: 0; cursor: pointer;
  background: oklch(1 0 0 / 12%); color: white;
  transition: background-color 0.15s;
}
.md-lightbox-close:hover { background: oklch(1 0 0 / 22%); }
.md-lightbox-caption { position: absolute; bottom: 1.25rem; left: 0; right: 0; text-align: center; color: oklch(0.92 0 0); font-size: 0.8125rem; padding: 0 1rem; }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.md-error-details { font-family: var(--md-font-mono); white-space: pre-wrap; word-break: break-word; }
.glossary-term-demo, .md-body .glossary-term {
  border-bottom: 1.5px dotted color-mix(in oklch, var(--primary) 55%, transparent);
  cursor: help;
}
.md-blocked-embed {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.75rem; color: var(--muted-foreground);
  border: 1px dashed var(--border); border-radius: calc(var(--radius) - 3px);
  padding: 0.2rem 0.5rem; background: var(--muted);
}
.md-skeleton {
  border-radius: calc(var(--radius) - 3px);
  background: linear-gradient(90deg, var(--muted) 25%, color-mix(in oklch, var(--muted) 60%, var(--background)) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: md-shimmer 1.4s infinite;
}
@keyframes md-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.md-empty-state { display: grid; place-items: center; gap: 0.75rem; padding: 4rem 1.5rem; text-align: center; }

/* ── Print ────────────────────────────────────────────────────────────── */
@media print {
  header, footer, aside, .md-toaster, .md-lightbox, .md-pager,
  #md-palette, #md-sheet, #md-toc-mobile, .md-btn, .md-icon-btn,
  .md-search-trigger, .md-anchor, .md-code-bar, .md-mermaid-bar, .md-quote-copy { display: none !important; }
  body { background: white !important; color: black !important; }
  .md-body { max-width: 100% !important; font-size: 11.5pt !important; }
  .md-card { border-color: #ccc !important; box-shadow: none !important; }
  a { color: inherit !important; text-decoration: underline !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.75em; color: #555; word-break: break-all; }
  .md-code, pre { white-space: pre-wrap !important; word-break: break-word; border: 1px solid #ccc !important; }
  .md-code pre { background: #f6f6f6 !important; color: #111 !important; }
  .hljs, .hljs * { color: #111 !important; background: transparent !important; }
}
