/* =====================================================================
   ManageYourProject — design tokens, reset and shared components.
   No build step: plain CSS with custom properties and cascade layers.
   ===================================================================== */

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

@layer tokens {
  :root {
    /* Brand ramp — indigo/violet with a warm accent */
    --brand-50:#eef2ff;  --brand-100:#e0e7ff; --brand-200:#c7d2fe;
    --brand-300:#a5b4fc; --brand-400:#818cf8; --brand-500:#6366f1;
    --brand-600:#4f46e5; --brand-700:#4338ca; --brand-800:#3730a3;
    --brand-900:#312e81;  --brand-950:#1e1b4b;

    --accent-400:#fb923c; --accent-500:#f97316; --accent-600:#ea580c;
    --violet-400:#a78bfa; --violet-500:#8b5cf6; --violet-600:#7c3aed;

    --ok-50:#ecfdf5;  --ok-400:#34d399; --ok-500:#10b981; --ok-600:#059669;
    --warn-50:#fffbeb; --warn-400:#fbbf24; --warn-500:#f59e0b; --warn-600:#d97706;
    --bad-50:#fef2f2;  --bad-400:#f87171; --bad-500:#ef4444; --bad-600:#dc2626;
    --info-50:#eff6ff; --info-400:#60a5fa; --info-500:#3b82f6; --info-600:#2563eb;

    --gray-0:#ffffff;  --gray-25:#fcfcfd; --gray-50:#f9fafb; --gray-100:#f3f4f6;
    --gray-150:#eceef1; --gray-200:#e5e7eb; --gray-300:#d1d5db; --gray-400:#9ca3af;
    --gray-500:#6b7280; --gray-600:#4b5563; --gray-700:#374151; --gray-800:#1f2937;
    --gray-900:#111827; --gray-950:#030712;

    /* Semantic surfaces */
    --bg:            var(--gray-50);
    --bg-elevated:   var(--gray-0);
    --bg-sunken:     var(--gray-100);
    --bg-hover:      var(--gray-100);
    --bg-active:     var(--gray-150);
    --bg-inverse:    var(--gray-900);
    --border:        var(--gray-200);
    --border-strong: var(--gray-300);
    --text:          var(--gray-900);
    --text-muted:    var(--gray-500);
    --text-subtle:   var(--gray-400);
    --text-inverse:  var(--gray-0);
    --link:          var(--brand-600);

    --radius-xs:4px; --radius-sm:6px; --radius:10px; --radius-md:12px;
    --radius-lg:16px; --radius-xl:22px; --radius-full:999px;

    --shadow-xs: 0 1px 2px 0 rgb(16 24 40 / .05);
    --shadow-sm: 0 1px 3px 0 rgb(16 24 40 / .08), 0 1px 2px -1px rgb(16 24 40 / .06);
    --shadow:    0 4px 8px -2px rgb(16 24 40 / .08), 0 2px 4px -2px rgb(16 24 40 / .05);
    --shadow-md: 0 12px 16px -4px rgb(16 24 40 / .08), 0 4px 6px -2px rgb(16 24 40 / .04);
    --shadow-lg: 0 20px 24px -4px rgb(16 24 40 / .10), 0 8px 8px -4px rgb(16 24 40 / .04);
    --shadow-xl: 0 24px 48px -12px rgb(16 24 40 / .20);
    --shadow-glow: 0 0 0 4px var(--brand-100);

    --font: "InterVariable", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
            Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --fs-xs:.75rem; --fs-sm:.8125rem; --fs-base:.875rem; --fs-md:.9375rem;
    --fs-lg:1.0625rem; --fs-xl:1.25rem; --fs-2xl:1.5rem; --fs-3xl:1.875rem;
    --fs-4xl:2.25rem; --fs-5xl:3rem; --fs-6xl:3.75rem;

    --sp-1:.25rem; --sp-2:.5rem; --sp-3:.75rem; --sp-4:1rem; --sp-5:1.25rem;
    --sp-6:1.5rem; --sp-8:2rem; --sp-10:2.5rem; --sp-12:3rem; --sp-16:4rem;
    --sp-20:5rem; --sp-24:6rem;

    --topbar-h:56px;
    --sidebar-w:248px;
    --sidebar-collapsed-w:60px;
    --container:1200px;
    --container-wide:1400px;

    --ease: cubic-bezier(.4,0,.2,1);
    --ease-out: cubic-bezier(.16,1,.3,1);
    --dur:.16s;
    --z-sticky:100; --z-dropdown:400; --z-drawer:500; --z-modal:600; --z-toast:700; --z-cmdk:800;
  }

  [data-theme="dark"] {
    --bg:            #0b0d12;
    --bg-elevated:   #14171f;
    --bg-sunken:     #090b0f;
    --bg-hover:      #1c2029;
    --bg-active:     #232833;
    --bg-inverse:    var(--gray-100);
    --border:        #242935;
    --border-strong: #333a4a;
    --text:          #e8eaf0;
    --text-muted:    #98a1b3;
    --text-subtle:   #6b7484;
    --text-inverse:  var(--gray-900);
    --link:          var(--brand-400);
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / .4);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / .5);
    --shadow:    0 4px 10px -2px rgb(0 0 0 / .55);
    --shadow-md: 0 12px 20px -6px rgb(0 0 0 / .6);
    --shadow-lg: 0 24px 40px -12px rgb(0 0 0 / .7);
    --shadow-xl: 0 32px 64px -16px rgb(0 0 0 / .8);
    --shadow-glow: 0 0 0 4px rgb(99 102 241 / .25);
    color-scheme: dark;
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; tab-size: 4; }
  html:focus-within { scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) {
    html:focus-within { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; }
  }
  body {
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-variant-ligatures: contextual;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
  }
  img, svg, video, canvas { display: block; max-width: 100%; height: auto; }
  /* icon() always emits .ico. Blocking every svg is right for images but
     breaks an icon sitting beside inline text, which gets pushed onto its own
     line. Flex and grid children are blockified anyway, so this is a no-op
     in the layouts that already work. */
  .ico { display: inline-block; vertical-align: -.15em; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; }
  a { color: var(--link); text-decoration: none; }
  a:hover { text-decoration: underline; text-underline-offset: 2px; }
  h1,h2,h3,h4,h5,h6 { font-weight: 640; line-height: 1.2; letter-spacing: -.018em; text-wrap: balance; }
  p, li { text-wrap: pretty; }
  ul, ol { padding: 0; list-style: none; }
  table { border-collapse: collapse; width: 100%; }
  hr { border: 0; border-top: 1px solid var(--border); }
  code, pre, kbd { font-family: var(--font-mono); font-size: .92em; }
  :focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; border-radius: var(--radius-xs); }
  ::selection { background: var(--brand-200); color: var(--brand-900); }
  [hidden] { display: none !important; }
  dialog { border: 0; padding: 0; background: none; color: inherit; max-width: none; max-height: none; }
  dialog::backdrop { background: rgb(16 24 40 / .55); backdrop-filter: blur(3px); }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: content-box; }
  .scroll-thin { scrollbar-width: thin; }
}

@layer layout {
  .container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--sp-5); }
  .container-wide { max-width: var(--container-wide); }
  .container-narrow { max-width: 760px; }
  .stack > * + * { margin-top: var(--gap, var(--sp-4)); }
  .row { display: flex; align-items: center; gap: var(--gap, var(--sp-3)); }
  .row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
  .row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--sp-2)); }
  .col { display: flex; flex-direction: column; gap: var(--gap, var(--sp-3)); }
  .grid { display: grid; gap: var(--gap, var(--sp-5)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .grid-auto { grid-template-columns: repeat(auto-fit, minmax(var(--min, 260px), 1fr)); }
  .spacer { flex: 1 1 auto; }
  .section { padding-block: clamp(3rem, 7vw, 6.5rem); }
  .section-sm { padding-block: clamp(2rem, 4vw, 3.5rem); }
  @media (max-width: 900px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  }
  @media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  }
}

@layer components {
  /* ---------------------------------------------------------- buttons */
  .btn {
    --btn-bg: var(--bg-elevated);
    --btn-fg: var(--text);
    --btn-bd: var(--border-strong);
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    padding: 0 var(--sp-4); height: 36px; border-radius: var(--radius-sm);
    background: var(--btn-bg); color: var(--btn-fg);
    border: 1px solid var(--btn-bd);
    font-size: var(--fs-base); font-weight: 560; white-space: nowrap;
    box-shadow: var(--shadow-xs);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
                transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), opacity var(--dur);
    text-decoration: none; user-select: none;
  }
  .btn:hover { background: var(--bg-hover); text-decoration: none; }
  .btn:active { transform: translateY(.5px) scale(.994); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
  .btn svg { width: 16px; height: 16px; flex: none; }

  .btn-primary {
    --btn-bg: linear-gradient(180deg, var(--brand-500), var(--brand-600));
    --btn-fg: #fff; --btn-bd: var(--brand-700);
    box-shadow: 0 1px 2px rgb(16 24 40 / .1), inset 0 1px 0 rgb(255 255 255 / .18);
  }
  .btn-primary:hover { --btn-bg: linear-gradient(180deg, var(--brand-600), var(--brand-700)); }
  .btn-accent { --btn-bg: linear-gradient(180deg, var(--accent-500), var(--accent-600)); --btn-fg:#fff; --btn-bd: var(--accent-600); }
  .btn-dark { --btn-bg: var(--gray-900); --btn-fg:#fff; --btn-bd: var(--gray-900); }
  [data-theme="dark"] .btn-dark { --btn-bg: var(--gray-100); --btn-fg: var(--gray-900); --btn-bd: var(--gray-100); }
  .btn-danger { --btn-bg: var(--bad-500); --btn-fg:#fff; --btn-bd: var(--bad-600); }
  .btn-success { --btn-bg: var(--ok-500); --btn-fg:#fff; --btn-bd: var(--ok-600); }
  .btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; }
  .btn-ghost:hover { --btn-bg: var(--bg-hover); }
  .btn-outline { --btn-bg: transparent; }
  .btn-link { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--link); box-shadow: none; padding-inline: var(--sp-1); height: auto; }
  .btn-lg { height: 46px; padding-inline: var(--sp-6); font-size: var(--fs-md); border-radius: var(--radius); }
  .btn-xl { height: 54px; padding-inline: var(--sp-8); font-size: var(--fs-lg); border-radius: var(--radius-md); }
  .btn-sm { height: 30px; padding-inline: var(--sp-3); font-size: var(--fs-sm); }
  .btn-xs { height: 25px; padding-inline: var(--sp-2); font-size: var(--fs-xs); gap: var(--sp-1); }
  .btn-icon { width: 34px; padding: 0; }
  .btn-icon.btn-sm { width: 30px; }
  .btn-icon.btn-xs { width: 25px; }
  .btn-block { width: 100%; }
  .btn-group { display: inline-flex; }
  .btn-group > .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
  .btn-group > .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
  .btn-group > .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
  .btn-group > .btn[aria-pressed="true"], .btn-group > .btn.is-active { background: var(--bg-active); border-color: var(--border-strong); z-index: 1; }
  .btn.is-loading { color: transparent !important; position: relative; pointer-events: none; }
  .btn.is-loading::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 15px; height: 15px;
    border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
    color: var(--btn-fg); animation: spin .6s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ----------------------------------------------------------- inputs */
  .field { display: flex; flex-direction: column; gap: 6px; }
  .label { font-size: var(--fs-sm); font-weight: 560; color: var(--text); }
  .label .req { color: var(--bad-500); }
  .hint { font-size: var(--fs-xs); color: var(--text-muted); }
  .err { font-size: var(--fs-xs); color: var(--bad-600); }
  .input, .select, .textarea {
    width: 100%; min-height: 36px; padding: 7px var(--sp-3);
    background: var(--bg-elevated); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--dur), box-shadow var(--dur);
  }
  .input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--brand-500); box-shadow: var(--shadow-glow);
  }
  .input[aria-invalid="true"], .input.has-error { border-color: var(--bad-500); }
  .input:disabled, .select:disabled, .textarea:disabled { background: var(--bg-sunken); color: var(--text-muted); cursor: not-allowed; }
  .textarea { min-height: 90px; resize: vertical; line-height: 1.55; }
  .select {
    appearance: none; padding-right: var(--sp-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5'  stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 9px center; background-size: 17px;
  }
  .input-lg { min-height: 46px; font-size: var(--fs-md); border-radius: var(--radius); }
  .input-sm, .select-sm { min-height: 30px; padding: 4px var(--sp-2); font-size: var(--fs-sm); }
  .select-sm { padding-right: var(--sp-6); }
  .input-group { position: relative; display: flex; align-items: center; }
  .input-group .input { padding-left: 34px; }
  .input-group > svg:first-child { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--text-subtle); pointer-events: none; }
  .input-affix { display: flex; align-items: stretch; }
  .input-affix > .affix {
    display: inline-flex; align-items: center; padding-inline: var(--sp-3);
    background: var(--bg-sunken); border: 1px solid var(--border-strong);
    color: var(--text-muted); font-size: var(--fs-sm);
  }
  .input-affix > .affix:first-child { border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
  .input-affix > .affix:last-child { border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
  .input-affix > .input:not(:first-child) { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
  .input-affix > .input:not(:last-child) { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

  .check { display: inline-flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-base); }
  .check input[type=checkbox], .check input[type=radio] {
    appearance: none; width: 17px; height: 17px; flex: none; margin-top: 2px;
    border: 1.5px solid var(--border-strong); border-radius: var(--radius-xs);
    background: var(--bg-elevated); transition: all var(--dur) var(--ease);
  }
  .check input[type=radio] { border-radius: 50%; }
  .check input:checked { background: var(--brand-600); border-color: var(--brand-600); }
  .check input[type=checkbox]:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.5 8.5 6.3 11.2 12.5 5' stroke='white' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: 100%;
  }
  .check input[type=radio]:checked { box-shadow: inset 0 0 0 3px var(--bg-elevated); }
  .check input:focus-visible { box-shadow: var(--shadow-glow); outline: none; }

  .switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
  .switch input { appearance: none; width: 38px; height: 22px; border-radius: var(--radius-full); background: var(--border-strong); transition: background var(--dur) var(--ease); flex: none; }
  .switch input::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm);
    transition: transform var(--dur) var(--ease-out);
  }
  .switch input:checked { background: var(--brand-600); }
  .switch input:checked::after { transform: translateX(16px); }

  /* ------------------------------------------------------------ cards */
  .card {
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  }
  .card-pad { padding: var(--sp-5); }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
  .card-head h2, .card-head h3 { font-size: var(--fs-md); font-weight: 620; }
  .card-body { padding: var(--sp-5); }
  .card-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-sunken); border-radius: 0 0 var(--radius-md) var(--radius-md); }
  .card-hover { transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), border-color var(--dur); }
  .card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }

  /* ----------------------------------------------------------- badges */
  .badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px; border-radius: var(--radius-full);
    font-size: var(--fs-xs); font-weight: 560; line-height: 1.5;
    background: var(--bg-sunken); color: var(--text-muted);
    border: 1px solid transparent; white-space: nowrap;
  }
  .badge svg { width: 12px; height: 12px; }
  .badge-brand { background: var(--brand-50); color: var(--brand-700); }
  .badge-ok    { background: var(--ok-50); color: var(--ok-600); }
  .badge-warn  { background: var(--warn-50); color: var(--warn-600); }
  .badge-bad   { background: var(--bad-50); color: var(--bad-600); }
  .badge-info  { background: var(--info-50); color: var(--info-600); }
  .badge-solid { background: var(--gray-900); color: #fff; }
  .badge-outline { background: transparent; border-color: var(--border-strong); color: var(--text-muted); }
  [data-theme="dark"] .badge-brand { background: rgb(99 102 241 / .16); color: var(--brand-300); }
  [data-theme="dark"] .badge-ok { background: rgb(16 185 129 / .16); color: var(--ok-400); }
  [data-theme="dark"] .badge-warn { background: rgb(245 158 11 / .16); color: var(--warn-400); }
  [data-theme="dark"] .badge-bad { background: rgb(239 68 68 / .16); color: var(--bad-400); }
  [data-theme="dark"] .badge-info { background: rgb(59 130 246 / .16); color: var(--info-400); }

  .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-subtle); }
  .kbd {
    display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
    padding: 0 5px; border-radius: var(--radius-xs); border: 1px solid var(--border-strong);
    border-bottom-width: 2px; background: var(--bg-elevated); color: var(--text-muted);
    font-size: 11px; font-family: var(--font); font-weight: 560;
  }

  /* ---------------------------------------------------------- avatars */
  .avatar {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: var(--size, 28px); height: var(--size, 28px); flex: none;
    border-radius: 50%; overflow: hidden;
    font-size: calc(var(--size, 28px) * .4); font-weight: 620; letter-spacing: -.02em;
    color: #fff; background: var(--brand-500); user-select: none;
  }
  .avatar img { width: 100%; height: 100%; object-fit: cover; }
  .avatar-sm { --size: 22px; }
  .avatar-lg { --size: 40px; }
  .avatar-xl { --size: 64px; }
  .avatar-stack { display: inline-flex; }
  .avatar-stack .avatar { margin-left: -7px; box-shadow: 0 0 0 2px var(--bg-elevated); }
  .avatar-stack .avatar:first-child { margin-left: 0; }
  .avatar .presence {
    position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px;
    border-radius: 50%; background: var(--ok-500); box-shadow: 0 0 0 2px var(--bg-elevated);
  }

  /* ---------------------------------------------------------- tooltip */
  [data-tip] { position: relative; }
  [data-tip]::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%;
    transform: translateX(-50%) translateY(3px); z-index: var(--z-toast);
    padding: 5px 9px; border-radius: var(--radius-sm);
    background: var(--gray-900); color: #fff; font-size: var(--fs-xs); font-weight: 500;
    white-space: nowrap; pointer-events: none; opacity: 0;
    transition: opacity var(--dur), transform var(--dur) var(--ease-out);
    box-shadow: var(--shadow-md);
  }
  [data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
  [data-tip-pos="right"]::after { bottom: auto; left: calc(100% + 7px); top: 50%; transform: translateY(-50%); }
  [data-tip-pos="right"]:hover::after { transform: translateY(-50%); }

  /* --------------------------------------------------------- dropdown */
  .dropdown { position: relative; }
  .menu {
    position: absolute; z-index: var(--z-dropdown); min-width: 200px; max-height: min(420px, 70vh);
    overflow-y: auto; padding: 5px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    top: calc(100% + 5px); left: 0;
    opacity: 0; transform: translateY(-4px) scale(.985); pointer-events: none;
    transition: opacity var(--dur), transform var(--dur) var(--ease-out);
  }
  .menu[data-align="right"] { left: auto; right: 0; }
  .menu[data-align="top"] { top: auto; bottom: calc(100% + 5px); }
  .menu.is-open { opacity: 1; transform: none; pointer-events: auto; }
  .menu-item {
    display: flex; align-items: center; gap: var(--sp-2); width: 100%;
    padding: 7px 9px; border-radius: var(--radius-sm);
    font-size: var(--fs-base); color: var(--text); text-align: left; text-decoration: none;
  }
  .menu-item:hover, .menu-item.is-focus { background: var(--bg-hover); text-decoration: none; }
  .menu-item svg { width: 16px; height: 16px; color: var(--text-muted); flex: none; }
  .menu-item.is-danger { color: var(--bad-600); }
  .menu-item.is-danger svg { color: var(--bad-500); }
  .menu-item[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--brand-600); font-weight: 700; }
  .menu-sep { height: 1px; margin: 5px 3px; background: var(--border); }
  .menu-label { padding: 7px 9px 4px; font-size: var(--fs-xs); font-weight: 620; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .05em; }
  .menu-kbd { margin-left: auto; }

  /* ------------------------------------------------------------ modal */
  .modal-backdrop {
    position: fixed; inset: 0; z-index: var(--z-modal);
    display: grid; place-items: start center; padding: max(4vh, var(--sp-6)) var(--sp-4);
    background: rgb(16 24 40 / .5); backdrop-filter: blur(3px);
    overflow-y: auto; animation: fade-in .14s var(--ease) both;
  }
  .modal {
    width: 100%; max-width: var(--modal-w, 560px);
    background: var(--bg-elevated); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl); border: 1px solid var(--border);
    animation: modal-in .22s var(--ease-out) both;
  }
  .modal-lg { --modal-w: 780px; }
  .modal-xl { --modal-w: 1040px; }
  .modal-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-3); }
  .modal-head h2 { font-size: var(--fs-xl); }
  .modal-head .close { margin-left: auto; }
  .modal-body { padding: var(--sp-3) var(--sp-5) var(--sp-5); }
  .modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-sunken); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  @keyframes fade-in { from { opacity: 0; } }
  @keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

  /* ----------------------------------------------------------- drawer */
  .drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--z-drawer);
    width: min(var(--drawer-w, 620px), 100vw);
    background: var(--bg-elevated); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-xl); display: flex; flex-direction: column;
    animation: drawer-in .24s var(--ease-out) both;
  }
  @keyframes drawer-in { from { transform: translateX(24px); opacity: .6; } }

  /* ------------------------------------------------------------ toast */
  .toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; }
  .toast {
    display: flex; align-items: flex-start; gap: var(--sp-3); min-width: 260px; max-width: 400px;
    padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
    background: var(--gray-900); color: #fff; box-shadow: var(--shadow-lg);
    font-size: var(--fs-base); pointer-events: auto;
    animation: toast-in .22s var(--ease-out) both;
  }
  .toast.is-out { animation: toast-out .18s var(--ease) both; }
  .toast svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
  .toast-ok svg { color: var(--ok-400); }
  .toast-bad svg { color: var(--bad-400); }
  .toast .undo { margin-left: auto; color: var(--brand-300); font-weight: 600; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
  @keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

  /* ------------------------------------------------------------ table */
  .table { font-size: var(--fs-base); }
  .table th {
    text-align: left; font-weight: 580; font-size: var(--fs-xs); color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em;
    padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); white-space: nowrap;
  }
  .table td { padding: var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
  .table tbody tr:hover { background: var(--bg-hover); }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table-fixed { table-layout: fixed; }
  .table .num { text-align: right; font-variant-numeric: tabular-nums; }
  .table-sticky th { position: sticky; top: 0; z-index: 2; background: var(--bg-elevated); }
  .table-compact td, .table-compact th { padding: 6px var(--sp-2); }

  /* --------------------------------------------------------- progress */
  /* progress_bar() emits a <span>; without display:block the height and the
     overflow clip are both ignored and the track collapses. */
  .bar { display: block; height: 6px; border-radius: var(--radius-full); background: var(--bg-active); overflow: hidden; }
  .bar > i { display: block; height: 100%; border-radius: inherit; background: var(--brand-500); transition: width .4s var(--ease-out); }
  /* No ceiling to fill, so show a neutral hatched track instead of a 0% bar. */
  .bar-unlimited {
    background-image: repeating-linear-gradient(-45deg, var(--bg-active) 0 4px, transparent 4px 8px);
    background-color: transparent; box-shadow: inset 0 0 0 1px var(--border);
  }
  .bar-ok > i { background: var(--ok-500); }
  .bar-warn > i { background: var(--warn-500); }
  .bar-bad > i { background: var(--bad-500); }
  .ring { --p: 0; --sz: 34px; width: var(--sz); height: var(--sz); flex: none; position: relative; }
  .ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
  .ring circle { fill: none; stroke-width: 3.5; }
  .ring .track { stroke: var(--bg-active); }
  .ring .val { stroke: var(--brand-500); stroke-linecap: round; transition: stroke-dashoffset .5s var(--ease-out); }
  .ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 10px; font-weight: 640; }

  /* ------------------------------------------------------------- tabs */
  .tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    display: inline-flex; align-items: center; gap: 6px; padding: 9px var(--sp-3);
    font-size: var(--fs-base); font-weight: 540; color: var(--text-muted);
    border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none;
    transition: color var(--dur), border-color var(--dur);
  }
  .tab:hover { color: var(--text); text-decoration: none; }
  .tab.is-active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
  .tab svg { width: 15px; height: 15px; }
  .tab .count { padding: 0 5px; border-radius: var(--radius-full); background: var(--bg-active); font-size: 11px; }
  .segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--bg-sunken); border-radius: var(--radius-sm); border: 1px solid var(--border); }
  .segmented > * {
    padding: 4px var(--sp-3); border-radius: var(--radius-xs); font-size: var(--fs-sm); font-weight: 540;
    color: var(--text-muted); text-decoration: none;
  }
  .segmented > .is-active { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-xs); }

  /* ------------------------------------------------------- empty state */
  .empty { display: grid; place-items: center; gap: var(--sp-3); padding: var(--sp-12) var(--sp-5); text-align: center; }
  .empty .icon {
    display: grid; place-items: center; width: 52px; height: 52px; border-radius: var(--radius-md);
    background: var(--bg-sunken); color: var(--text-subtle);
  }
  .empty .icon svg { width: 24px; height: 24px; }
  .empty h3 { font-size: var(--fs-lg); }
  .empty p { color: var(--text-muted); max-width: 42ch; }

  /* ----------------------------------------------------------- alerts */
  .alert {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--bg-sunken); font-size: var(--fs-base);
  }
  .alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
  .alert-ok   { background: var(--ok-50);   border-color: rgb(16 185 129 / .3); color: var(--ok-600); }
  .alert-warn { background: var(--warn-50); border-color: rgb(245 158 11 / .3); color: var(--warn-600); }
  .alert-bad  { background: var(--bad-50);  border-color: rgb(239 68 68 / .3);  color: var(--bad-600); }
  .alert-info { background: var(--info-50); border-color: rgb(59 130 246 / .3); color: var(--info-600); }
  .alert strong { color: inherit; }
  [data-theme="dark"] .alert-ok { background: rgb(16 185 129 / .1); }
  [data-theme="dark"] .alert-warn { background: rgb(245 158 11 / .1); }
  [data-theme="dark"] .alert-bad { background: rgb(239 68 68 / .1); }
  [data-theme="dark"] .alert-info { background: rgb(59 130 246 / .1); }

  /* -------------------------------------------------------- skeletons */
  .skel {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--bg-hover) 37%, var(--bg-sunken) 63%);
    background-size: 400% 100%; animation: shimmer 1.3s ease-in-out infinite;
    height: 1em;
  }
  @keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

  /* ----------------------------------------------------------- prose */
  .prose { font-size: var(--fs-md); line-height: 1.72; color: var(--gray-700); max-width: 72ch; }
  [data-theme="dark"] .prose { color: var(--text-muted); }
  .prose > * + * { margin-top: 1.1em; }
  .prose h2 { margin-top: 2.2em; font-size: 1.45em; color: var(--text); letter-spacing: -.02em; }
  .prose h3 { margin-top: 1.8em; font-size: 1.16em; color: var(--text); }
  .prose h4 { margin-top: 1.5em; font-size: 1em; color: var(--text); }
  .prose p strong, .prose li strong { color: var(--text); font-weight: 620; }
  .prose ul, .prose ol { padding-left: 1.35em; }
  .prose ul { list-style: disc; }
  .prose ol { list-style: decimal; }
  .prose li { margin-top: .45em; }
  .prose li::marker { color: var(--text-subtle); }
  .prose a { font-weight: 540; text-decoration: underline; text-decoration-color: var(--brand-300); text-underline-offset: 2px; }
  .prose blockquote {
    padding-left: 1.1em; border-left: 3px solid var(--brand-300);
    font-style: italic; color: var(--text-muted);
  }
  .prose code { padding: .15em .35em; border-radius: var(--radius-xs); background: var(--bg-sunken); color: var(--brand-700); font-size: .875em; }
  .prose pre { padding: var(--sp-4); border-radius: var(--radius); background: var(--gray-900); color: var(--gray-100); overflow-x: auto; }
  .prose pre code { padding: 0; background: none; color: inherit; }
  .prose img { border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
  .prose table { font-size: var(--fs-base); }
  .prose th, .prose td { padding: .55em .7em; border: 1px solid var(--border); text-align: left; }
  .prose th { background: var(--bg-sunken); font-weight: 600; color: var(--text); }
  .prose hr { margin-block: 2.2em; }

  /* -------------------------------------------------------- accordion */
  .accordion { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--bg-elevated); }
  .accordion details + details { border-top: 1px solid var(--border); }
  .accordion summary {
    display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5);
    font-weight: 570; cursor: pointer; list-style: none;
  }
  .accordion summary::-webkit-details-marker { display: none; }
  .accordion summary::after {
    content: ""; margin-left: auto; width: 9px; height: 9px; flex: none;
    border-right: 2px solid var(--text-subtle); border-bottom: 2px solid var(--text-subtle);
    transform: rotate(45deg) translateY(-2px); transition: transform var(--dur) var(--ease);
  }
  .accordion details[open] summary::after { transform: rotate(225deg) translateY(-2px); }
  .accordion details[open] summary { color: var(--brand-700); }
  .accordion .acc-body { padding: 0 var(--sp-5) var(--sp-5); color: var(--text-muted); }
}

@layer utilities {
  .t-xs{font-size:var(--fs-xs)} .t-sm{font-size:var(--fs-sm)} .t-base{font-size:var(--fs-base)}
  .t-md{font-size:var(--fs-md)} .t-lg{font-size:var(--fs-lg)} .t-xl{font-size:var(--fs-xl)}
  .t-2xl{font-size:var(--fs-2xl)} .t-3xl{font-size:var(--fs-3xl)}
  .fw-500{font-weight:500} .fw-6{font-weight:600} .fw-7{font-weight:700}
  .muted{color:var(--text-muted)} .subtle{color:var(--text-subtle)}
  .ok{color:var(--ok-600)} .bad{color:var(--bad-600)} .warn{color:var(--warn-600)} .brand{color:var(--brand-600)}
  .center{text-align:center} .right{text-align:left; text-align:right} .nums{font-variant-numeric:tabular-nums}
  .up{text-transform:uppercase; letter-spacing:.05em}
  .truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
  .clamp-2{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
  .clamp-3{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
  .strike{text-decoration:line-through}
  .mono{font-family:var(--font-mono)}
  .mt-0{margin-top:0} .mt-1{margin-top:var(--sp-1)} .mt-2{margin-top:var(--sp-2)} .mt-3{margin-top:var(--sp-3)}
  .mt-4{margin-top:var(--sp-4)} .mt-5{margin-top:var(--sp-5)} .mt-6{margin-top:var(--sp-6)} .mt-8{margin-top:var(--sp-8)}
  .mb-0{margin-bottom:0} .mb-1{margin-bottom:var(--sp-1)}
  .mb-2{margin-bottom:var(--sp-2)} .mb-3{margin-bottom:var(--sp-3)} .mb-4{margin-bottom:var(--sp-4)}
  .mb-5{margin-bottom:var(--sp-5)} .mb-6{margin-bottom:var(--sp-6)} .mb-8{margin-bottom:var(--sp-8)}
  .ml-auto{margin-left:auto} .mr-auto{margin-right:auto} .mx-auto{margin-inline:auto}
  .p-0{padding:0} .p-3{padding:var(--sp-3)} .p-4{padding:var(--sp-4)} .p-5{padding:var(--sp-5)} .p-6{padding:var(--sp-6)}
  .gap-1{gap:var(--sp-1)} .gap-2{gap:var(--sp-2)} .gap-3{gap:var(--sp-3)} .gap-4{gap:var(--sp-4)}
  .gap-5{gap:var(--sp-5)} .gap-6{gap:var(--sp-6)} .gap-8{gap:var(--sp-8)}
  .w-full{width:100%} .h-full{height:100%} .flex-1{flex:1 1 0%} .flex-none{flex:none}
  .items-start{align-items:flex-start} .items-center{align-items:center} .items-end{align-items:flex-end}
  .justify-center{justify-content:center} .justify-end{justify-content:flex-end} .justify-between{justify-content:space-between}
  .flex{display:flex} .inline-flex{display:inline-flex} .block{display:block} .inline-block{display:inline-block}
  .flex-col{flex-direction:column} .flex-wrap{flex-wrap:wrap}
  .relative{position:relative} .absolute{position:absolute} .sticky{position:sticky}
  .rounded{border-radius:var(--radius)} .rounded-md{border-radius:var(--radius-md)}
  .rounded-lg{border-radius:var(--radius-lg)} .rounded-full{border-radius:var(--radius-full)}
  .border{border:1px solid var(--border)} .border-t{border-top:1px solid var(--border)}
  .border-b{border-bottom:1px solid var(--border)} .border-0{border:0}
  .bg-elevated{background:var(--bg-elevated)} .bg-sunken{background:var(--bg-sunken)}
  .shadow-sm{box-shadow:var(--shadow-sm)} .shadow{box-shadow:var(--shadow)} .shadow-md{box-shadow:var(--shadow-md)}
  .overflow-hidden{overflow:hidden} .overflow-auto{overflow:auto}
  .cursor-pointer{cursor:pointer} .select-none{user-select:none}
  .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
  .skip-link{position:absolute;left:-9999px;z-index:999}
  .skip-link:focus{left:var(--sp-4);top:var(--sp-4);padding:var(--sp-2) var(--sp-4);background:var(--bg-elevated);border-radius:var(--radius-sm);box-shadow:var(--shadow-md)}
  .plain{list-style:none;margin:0;padding:0}
  .link{color:var(--brand-600);font-weight:520;font-size:var(--fs-sm)}
  .link:hover{color:var(--brand-700);text-decoration:underline}
  .card-title{font-size:var(--fs-md);font-weight:620}
  .card-sub{margin-top:2px;font-size:var(--fs-xs);color:var(--text-muted)}
  .skeleton{
    border-radius:var(--radius-sm);
    background:linear-gradient(90deg,var(--bg-sunken) 25%,var(--bg-active) 50%,var(--bg-sunken) 75%);
    background-size:200% 100%;animation:shimmer 1.3s infinite linear;
  }
  @keyframes shimmer{from{background-position:200% 0}to{background-position:-200% 0}}
  @media (prefers-reduced-motion:reduce){ .skeleton{animation:none} }
  @media (max-width:768px){ .hide-mobile{display:none !important} }
  @media (min-width:769px){ .only-mobile{display:none !important} }
  @media (min-width:901px){ .hide-desktop{display:none !important} }
  @media print { .no-print { display: none !important; } body { background: #fff; } }
}
