/* =============================================================================
   FORJA — design system
   Phase 02

   One stylesheet for the whole platform. There is no framework.

   Structure:
     1. Reset
     2. Design tokens
     3. Base elements and typography
     4. Layout primitives
     5. Components
     6. App shell
     7. Utilities
     8. Motion, print, forced colours

   Rules this file follows:
     - Every colour is a token. No hardcoded hex outside the token block.
     - Every interactive element has a visible :focus-visible style.
     - Dark and light themes are equal citizens, not a bolt-on.
     - All motion respects prefers-reduced-motion.
     - Components never rely on a parent for their own appearance, so any
       component can be dropped anywhere without breaking.
   ========================================================================== */

/* -----------------------------------------------------------------------------
   1. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-synthesis-weight: none;
}

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

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

button {
  background: none;
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

ul[class],
ol[class] {
  list-style: none;
  padding: 0;
}

:where(h1, h2, h3, h4, h5, h6) {
  font-weight: 650;
  line-height: 1.2;
  text-wrap: balance;
}

:where(p, li) {
  text-wrap: pretty;
}

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

/* -----------------------------------------------------------------------------
   2. Design tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* --- Brand ------------------------------------------------------------ */
  --brand-50:  #f5f3ff;
  --brand-100: #ede9fe;
  --brand-200: #ddd6fe;
  --brand-300: #c4b5fd;
  --brand-400: #a78bfa;
  --brand-500: #8b5cf6;
  --brand-600: #7c3aed;
  --brand-700: #6d28d9;
  --brand-800: #5b21b6;
  --brand-900: #4c1d95;

  /* --- Status ----------------------------------------------------------- */
  --ok-500:   #10b981;
  --ok-50:    #ecfdf5;
  --info-500: #3b82f6;
  --info-50:  #eff6ff;
  --warn-500: #f59e0b;
  --warn-50:  #fffbeb;
  --bad-500:  #ef4444;
  --bad-50:   #fef2f2;
  --mute-500: #64748b;
  --mute-50:  #f8fafc;

  /* --- Surfaces and text ------------------------------------------------ */
  --bg:            #f7f7fb;
  --bg-alt:        #f1f1f7;
  --surface:       #ffffff;
  --surface-2:     #fafafd;
  --surface-3:     #f4f4f8;
  --surface-inv:   #14141c;
  --overlay:       rgba(10, 10, 18, 0.55);

  --text:          #15131c;
  --text-muted:    #6b6780;
  --text-subtle:   #8e8a9e;
  --text-inv:      #f8f7ff;

  --line:          #e6e5ee;
  --line-strong:   #d3d2e0;
  --line-focus:    var(--brand-500);

  --accent:        var(--brand-600);
  --accent-hover:  var(--brand-700);
  --accent-soft:   var(--brand-50);
  --accent-text:   #ffffff;

  /* --- Typography ------------------------------------------------------- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas,
    "Liberation Mono", monospace;

  --text-2xs: 0.6875rem;  /* 11px */
  --text-xs:  0.75rem;    /* 12px */
  --text-sm:  0.8125rem;  /* 13px */
  --text-md:  0.875rem;   /* 14px */
  --text-base:0.9375rem;  /* 15px */
  --text-lg:  1.0625rem;  /* 17px */
  --text-xl:  1.25rem;    /* 20px */
  --text-2xl: 1.5rem;     /* 24px */
  --text-3xl: 1.875rem;   /* 30px */
  --text-4xl: 2.25rem;    /* 36px */

  --leading-tight: 1.2;
  --leading-snug:  1.35;
  --leading-normal:1.55;

  --tracking-tight: -0.02em;
  --tracking-wide: 0.06em;
  --tracking-wider: 0.1em;

  /* --- Spacing scale (4px base) ----------------------------------------- */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* --- Radius ----------------------------------------------------------- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-2xl: 28px;
  --radius-full: 999px;

  /* --- Elevation -------------------------------------------------------- */
  --shadow-xs: 0 1px 2px rgba(16, 14, 30, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 14, 30, 0.07), 0 1px 2px rgba(16, 14, 30, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 14, 30, 0.08), 0 1px 3px rgba(16, 14, 30, 0.05);
  --shadow-lg: 0 12px 28px rgba(16, 14, 30, 0.11), 0 4px 8px rgba(16, 14, 30, 0.05);
  --shadow-xl: 0 24px 56px rgba(16, 14, 30, 0.15), 0 8px 16px rgba(16, 14, 30, 0.06);
  --shadow-focus: 0 0 0 3px var(--focus-ring);

  --focus-ring: rgba(139, 92, 246, 0.35);

  /* --- Motion ----------------------------------------------------------- */
  --ease-out:  cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in:   cubic-bezier(0.55, 0, 1, 0.45);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);

  --duration-instant: 80ms;
  --duration-fast:    140ms;
  --duration-base:    220ms;
  --duration-slow:    360ms;

  /* --- Density ---------------------------------------------------------- */
  --control-height-sm: 30px;
  --control-height:    38px;
  --control-height-lg: 46px;

  --control-x: var(--space-3);
  --tap-target: 44px;

  /* --- Layout ----------------------------------------------------------- */
  --sidebar-width: 256px;
  --sidebar-width-collapsed: 68px;
  --topbar-height: 60px;
  --content-max: 1440px;
  --z-base: 1;
  --z-sticky: 20;
  --z-drawer: 40;
  --z-modal: 60;
  --z-toast: 80;
  --z-palette: 90;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg:          #08080d;
  --bg-alt:      #0c0c13;
  --surface:     #12121a;
  --surface-2:   #171722;
  --surface-3:   #1e1e2b;
  --surface-inv: #f8f7ff;
  --overlay:     rgba(0, 0, 0, 0.72);

  --text:        #f8f7ff;
  --text-muted:  #a3a0b4;
  --text-subtle: #7d7a8f;
  --text-inv:    #15131c;

  --line:        rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.17);

  --accent:        var(--brand-500);
  --accent-hover:  var(--brand-400);
  --accent-soft:   rgba(139, 92, 246, 0.14);
  --accent-text:   #ffffff;

  --ok-50:   rgba(16, 185, 129, 0.13);
  --info-50: rgba(59, 130, 246, 0.13);
  --warn-50: rgba(245, 158, 11, 0.13);
  --bad-50:  rgba(239, 68, 68, 0.13);
  --mute-50: rgba(148, 163, 184, 0.11);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.6), 0 4px 10px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 28px 64px rgba(0, 0, 0, 0.7), 0 10px 20px rgba(0, 0, 0, 0.5);

  --focus-ring: rgba(167, 139, 250, 0.45);
}

/* Respect the OS preference until the user overrides it with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;

    --bg:          #08080d;
    --bg-alt:      #0c0c13;
    --surface:     #12121a;
    --surface-2:   #171722;
    --surface-3:   #1e1e2b;
    --surface-inv: #f8f7ff;
    --overlay:     rgba(0, 0, 0, 0.72);

    --text:        #f8f7ff;
    --text-muted:  #a3a0b4;
    --text-subtle: #7d7a8f;
    --text-inv:    #15131c;

    --line:        rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.17);

    --accent:      var(--brand-500);
    --accent-hover:var(--brand-400);
    --accent-soft: rgba(139, 92, 246, 0.14);

    --ok-50:   rgba(16, 185, 129, 0.13);
    --info-50: rgba(59, 130, 246, 0.13);
    --warn-50: rgba(245, 158, 11, 0.13);
    --bad-50:  rgba(239, 68, 68, 0.13);
    --mute-50: rgba(148, 163, 184, 0.11);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.6);
    --shadow-xl: 0 28px 64px rgba(0, 0, 0, 0.7);

    --focus-ring: rgba(167, 139, 250, 0.45);
  }
}

/* -----------------------------------------------------------------------------
   3. Base
   -------------------------------------------------------------------------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
}

h1, .h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tight); }
h2, .h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
h3, .h3 { font-size: var(--text-xl); letter-spacing: var(--tracking-tight); }
h4, .h4 { font-size: var(--text-lg); }
h5, .h5 { font-size: var(--text-base); }
h6, .h6 { font-size: var(--text-sm); }

h1, h2, h3, h4, h5, h6 { font-family: var(--font-sans); }

.muted    { color: var(--text-muted); }
.subtle   { color: var(--text-subtle); }
.mono     { font-family: var(--font-mono); font-size: 0.92em; }
.nowrap   { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.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;
}

.lead { font-size: var(--text-lg); color: var(--text-muted); line-height: var(--leading-snug); }
.caption { font-size: var(--text-xs); color: var(--text-subtle); }
.overline {
  font-size: var(--text-2xs);
  font-weight: 650;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.15em 0.4em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  text-align: center;
  font-size: var(--text-2xs);
}

/* Global focus treatment. Never remove it. */
:focus-visible {
  outline: 2px solid var(--line-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Only for browsers without :focus-visible support. */
@supports not selector(:focus-visible) {
  :focus { outline: 2px solid var(--line-focus); outline-offset: 2px; }
}

::selection {
  background: var(--brand-200);
  color: var(--brand-900);
}

[data-theme="dark"] ::selection {
  background: var(--brand-700);
  color: var(--text);
}

::placeholder { color: var(--text-subtle); opacity: 1; }

/* -----------------------------------------------------------------------------
   4. Layout primitives
   -------------------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-6 { display: flex; flex-direction: column; gap: var(--space-6); }
.stack-8 { display: flex; flex-direction: column; gap: var(--space-8); }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.row-2 { display: flex; align-items: center; gap: var(--space-2); }
.row-4 { display: flex; align-items: center; gap: var(--space-4); }
.row-6 { display: flex; align-items: center; gap: var(--space-6); }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-start { align-items: flex-start; }
.row-center { align-items: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--space-4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--space-4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

@media (max-width: 640px) {
  .container { padding-inline: var(--space-4); }
}

/* -----------------------------------------------------------------------------
   5. Components
   -------------------------------------------------------------------------- */

/* --- Button -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--line-strong);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-height);
  padding-inline: var(--control-x);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-md);
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background var(--duration-fast) var(--ease-soft),
              border-color var(--duration-fast) var(--ease-soft),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-soft);
}

.btn:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-text);
  --btn-bd: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn-secondary {
  --btn-bg: var(--accent-soft);
  --btn-fg: var(--accent);
  --btn-bd: transparent;
  box-shadow: none;
}
.btn-secondary:hover:not(:disabled) { background: var(--accent-soft); filter: brightness(1.05); }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }

.btn-danger {
  --btn-bg: var(--bad-500);
  --btn-fg: #fff;
  --btn-bd: transparent;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--bad-500); }

.btn-outline-danger {
  --btn-bg: transparent;
  --btn-fg: var(--bad-500);
  --btn-bd: var(--bad-500);
  box-shadow: none;
}
.btn-outline-danger:hover:not(:disabled) { background: var(--bad-50); }

.btn-sm { height: var(--control-height-sm); padding-inline: var(--space-2); font-size: var(--text-xs); }
.btn-lg { height: var(--control-height-lg); padding-inline: var(--space-5); font-size: var(--text-base); }
.btn-block { width: 100%; }

.btn-icon {
  width: var(--control-height);
  padding-inline: 0;
}
.btn-icon.btn-sm { width: var(--control-height-sm); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }

/* --- Card ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card-interactive {
  transition: border-color var(--duration-fast) var(--ease-soft),
              box-shadow var(--duration-fast) var(--ease-soft),
              transform var(--duration-fast) var(--ease-out);
}

.card-interactive:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}

.card-title { font-size: var(--text-lg); font-weight: 650; letter-spacing: var(--tracking-tight); }
.card-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.card-body { padding: var(--space-5); }
.card-body-tight { padding: var(--space-4); }
.card-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --- Stat tile ----------------------------------------------------------- */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.stat-label {
  font-size: var(--text-2xs);
  font-weight: 650;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
}

.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}

.stat-meta { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); }
.trend-up   { color: var(--ok-500); }
.trend-down { color: var(--bad-500); }

/* --- Form controls ------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }

.label {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text);
}

.hint { font-size: var(--text-xs); color: var(--text-muted); }

.error-text {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--bad-500);
  font-weight: 500;
}

.required-mark { color: var(--bad-500); margin-left: 2px; }

.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-height);
  padding: 0 var(--control-x);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  transition: border-color var(--duration-fast) var(--ease-soft),
              box-shadow var(--duration-fast) var(--ease-soft);
}

.textarea {
  height: auto;
  min-height: calc(var(--control-height) * 2.5);
  padding: var(--space-3) var(--control-x);
  line-height: var(--leading-normal);
  resize: vertical;
}

.input:hover:not(:disabled),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) { border-color: var(--text-subtle); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--surface-3);
  color: var(--text-subtle);
  cursor: not-allowed;
}

.input.is-error,
.select.is-error,
.textarea.is-error { border-color: var(--bad-500); }
.input.is-error:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.28); }

.select {
  appearance: none;
  padding-right: calc(var(--space-3) + 1.4em);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1.05em center, right 0.75em center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input-lg, .select-lg { height: var(--control-height-lg); font-size: var(--text-base); }
.input-sm, .select-sm { height: var(--control-height-sm); font-size: var(--text-xs); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: calc(var(--space-3) + 1.4em); }
.input-group-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-subtle);
  pointer-events: none;
  font-size: var(--text-sm);
}

.checkbox, .radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-md);
  line-height: 1.45;
}

.checkbox input, .radio input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox input:focus-visible,
.radio input:focus-visible { outline: 2px solid var(--line-focus); outline-offset: 2px; }

.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 23px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background var(--duration-base) var(--ease-soft),
              border-color var(--duration-base) var(--ease-soft);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-out);
}

.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--shadow-focus); }

/* --- Badge --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-2xs);
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.5;
  white-space: nowrap;
  background: var(--mute-50);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.badge-ok   { background: var(--ok-50);   color: var(--ok-500); }
.badge-info { background: var(--info-50); color: var(--info-500); }
.badge-warn { background: var(--warn-50); color: var(--warn-500); }
.badge-bad  { background: var(--bad-50);  color: var(--bad-500); }
.badge-muted{ background: var(--mute-50); color: var(--text-subtle); }

.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* --- Alert --------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  font-size: var(--text-md);
}

.alert-ok   { background: var(--ok-50);   border-left-color: var(--ok-500); }
.alert-info { background: var(--info-50); border-left-color: var(--info-500); }
.alert-warn { background: var(--warn-50); border-left-color: var(--warn-500); }
.alert-bad  { background: var(--bad-50);  border-left-color: var(--bad-500); }

.alert-title { font-weight: 650; margin-bottom: 2px; }

/* --- Table --------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  -webkit-overflow-scrolling: touch;
}

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

.table th {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: var(--text-2xs);
  font-weight: 650;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--duration-fast) var(--ease-soft); }
.table tbody tr:hover { background: var(--surface-2); }

.table-clickable tbody tr { cursor: pointer; }
.table-compact td, .table-compact th { padding: var(--space-2) var(--space-3); }

.table-numeric td.num, .table-numeric th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Avatar -------------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
  user-select: none;
}

.avatar-sm { width: 28px; height: 28px; font-size: var(--text-2xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-base); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* --- Tabs ---------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-md);
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--duration-fast) var(--ease-soft),
              border-color var(--duration-fast) var(--ease-soft);
}

.tab:hover { color: var(--text); }

.tab[aria-selected="true"], .tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab:focus-visible { outline: 2px solid var(--line-focus); outline-offset: -2px; border-radius: 0; }

/* --- Progress ------------------------------------------------------------ */
.progress {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
  transition: width var(--duration-slow) var(--ease-out);
}

.progress-ok   .progress-bar { background: var(--ok-500); }
.progress-warn .progress-bar { background: var(--warn-500); }
.progress-bad  .progress-bar { background: var(--bad-500); }

.progress-sm { height: 5px; }

/* --- Stepper ------------------------------------------------------------- */
.stepper { display: flex; align-items: center; gap: var(--space-2); }

.step { display: flex; align-items: center; gap: var(--space-2); }

.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-subtle);
  flex: 0 0 auto;
}

.step.is-done .step-dot { background: var(--ok-500); border-color: var(--ok-500); color: #fff; }
.step.is-current .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-label { font-size: var(--text-sm); color: var(--text-muted); }
.step.is-current .step-label { color: var(--text); font-weight: 600; }

.step-line { width: 26px; height: 1px; background: var(--line-strong); }

/* --- Modal / Drawer ------------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--duration-fast) var(--ease-out);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: pop-in var(--duration-base) var(--ease-out);
  overflow: hidden;
}

.modal-md { max-width: 720px; }
.modal-lg { max-width: 960px; }
.modal-xl { max-width: 1200px; }
.modal-full { max-width: min(1400px, 96vw); }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5);
  border-bottom: 1px solid var(--line);
}

.modal-title { font-size: var(--text-lg); font-weight: 650; }
.modal-body { padding: var(--space-5); overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--overlay);
  animation: fade-in var(--duration-fast) var(--ease-out);
}
.drawer-backdrop[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: calc(var(--z-drawer) + 1);
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-xl);
  animation: slide-in-right var(--duration-base) var(--ease-out);
}

.drawer-start { left: 0; right: auto; border-left: 0; border-right: 1px solid var(--line); animation-name: slide-in-left; }

@media (max-width: 640px) {
  .drawer { width: 100vw; }
}

/* --- Toast --------------------------------------------------------------- */
.toast-region {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(380px, calc(100vw - var(--space-8)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-md);
  pointer-events: auto;
  animation: toast-in var(--duration-base) var(--ease-out);
}

.toast-ok   { border-left-color: var(--ok-500); }
.toast-bad  { border-left-color: var(--bad-500); }
.toast-warn { border-left-color: var(--warn-500); }

.toast-close { margin-left: auto; color: var(--text-subtle); padding: 2px; border-radius: var(--radius-xs); }
.toast-close:hover { color: var(--text); background: var(--surface-3); }

@media (max-width: 640px) {
  .toast-region { right: var(--space-3); left: var(--space-3); bottom: var(--space-3); width: auto; }
}

/* --- Tooltip ------------------------------------------------------------- */
.tooltip-wrap { position: relative; display: inline-flex; }

.tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-inv);
  color: var(--text-inv);
  font-size: var(--text-2xs);
  font-weight: 550;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-fast) var(--ease-soft),
              visibility var(--duration-fast) var(--ease-soft);
  pointer-events: none;
  z-index: var(--z-sticky);
}

.tooltip-wrap:hover > .tooltip,
.tooltip-wrap:focus-within > .tooltip { opacity: 1; visibility: visible; }

/* --- Menu ---------------------------------------------------------------- */
.menu {
  min-width: 200px;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-soft);
}

.menu-item:hover { background: var(--surface-3); }
.menu-item[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.menu-item-danger { color: var(--bad-500); }
.menu-divider { height: 1px; margin: var(--space-1) 0; background: var(--line); }
.menu-label { padding: var(--space-2) var(--space-3); font-size: var(--text-2xs); font-weight: 650; letter-spacing: var(--tracking-wider); text-transform: uppercase; color: var(--text-subtle); }

/* --- Breadcrumb ---------------------------------------------------------- */
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); font-size: var(--text-sm); color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); text-decoration: underline; }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: 550; }
.breadcrumb-sep { color: var(--text-subtle); user-select: none; }

/* --- Pagination ---------------------------------------------------------- */
.pagination { display: flex; align-items: center; gap: var(--space-1); }

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-height-sm);
  height: var(--control-height-sm);
  padding-inline: var(--space-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-soft);
}

.page-link:hover { background: var(--surface-3); }
.page-link[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 650; }
.page-link[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

/* --- Skeleton ------------------------------------------------------------ */
.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-text { height: 0.85em; margin-block: 0.25em; }
.skeleton-title { height: 1.3em; width: 55%; margin-bottom: var(--space-3); }
.skeleton-block { height: 100%; min-height: 120px; border-radius: var(--radius-md); }

/* --- Empty state --------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: var(--surface-3);
  color: var(--text-subtle);
  font-size: 24px;
}

.empty-title { font-size: var(--text-lg); font-weight: 650; color: var(--text); }
.empty-text { max-width: 42ch; font-size: var(--text-md); }

/* --- Error state --------------------------------------------------------- */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
}

.error-ref {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  padding: 3px var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* --- Code block ---------------------------------------------------------- */
.code-block {
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

/* --- Divider ------------------------------------------------------------- */
.divider { height: 1px; background: var(--line); }
.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
}
.divider-label::before, .divider-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* -----------------------------------------------------------------------------
   6. App shell
   -------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr); }

.app-main { display: flex; flex-direction: column; min-width: 0; }

/* --- Sidebar ------------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: var(--z-sticky);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding-inline: var(--space-4);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: var(--text-lg);
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  font-size: var(--text-md);
  font-weight: 800;
  box-shadow: var(--shadow-sm);
}

.brand-sub {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--text-subtle);
  text-transform: uppercase;
}

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: var(--space-4) var(--space-3); }
.sidebar-foot { flex: 0 0 auto; padding: var(--space-3); border-top: 1px solid var(--line); }

.nav-group + .nav-group { margin-top: var(--space-5); }
.nav-group-label {
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--text-2xs);
  font-weight: 650;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-md);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-soft),
              color var(--duration-fast) var(--ease-soft);
}

.nav-item:hover { background: var(--surface-3); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: calc(var(--space-3) * -1 - 2px);
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  background: var(--accent);
}

.nav-icon {
  flex: 0 0 auto;
  width: 20px;
  text-align: center;
  font-size: var(--text-lg);
  line-height: 1;
}

.nav-badge {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--bad-500);
  color: #fff;
  font-size: var(--text-2xs);
  font-weight: 700;
}

/* Collapsed sidebar: hide labels, keep icons, expose meaning via tooltip. */
.app[data-sidebar="collapsed"] .nav-label,
.app[data-sidebar="collapsed"] .nav-group-label,
.app[data-sidebar="collapsed"] .brand-text,
.app[data-sidebar="collapsed"] .brand-sub { display: none; }

.app[data-sidebar="collapsed"] .nav-item { justify-content: center; padding-inline: 0; }
.app[data-sidebar="collapsed"] .nav-badge {
  position: absolute;
  top: 2px;
  right: 6px;
  margin: 0;
  padding: 0 4px;
}

.app[data-sidebar="collapsed"] .sidebar-head { justify-content: center; padding-inline: 0; }
.app[data-sidebar="collapsed"] .nav-group + .nav-group { margin-top: var(--space-3); }

/* --- Topbar -------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding-inline: var(--space-5);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.topbar-title { font-size: var(--text-lg); font-weight: 650; letter-spacing: var(--tracking-tight); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--control-height-sm);
  height: var(--control-height-sm);
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background var(--duration-fast) var(--ease-soft), color var(--duration-fast) var(--ease-soft);
}

.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* --- Page content -------------------------------------------------------- */
.page { padding: var(--space-6) 0 var(--space-12); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-title { font-size: var(--text-2xl); font-weight: 700; letter-spacing: var(--tracking-tight); }
.page-subtitle { font-size: var(--text-md); color: var(--text-muted); margin-top: 2px; }

/* --- Command palette ----------------------------------------------------- */
.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-palette);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--space-4) var(--space-4);
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in var(--duration-fast) var(--ease-out);
}

.palette-backdrop[hidden] { display: none; }

.palette {
  width: 100%;
  max-width: 620px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: pop-in var(--duration-base) var(--ease-out);
}

.palette-input {
  width: 100%;
  height: 56px;
  padding: 0 var(--space-5);
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: var(--text-lg);
}

.palette-input:focus { outline: none; }

.palette-list { flex: 1 1 auto; overflow-y: auto; padding: var(--space-2); }
.palette-group-label { padding: var(--space-2) var(--space-3); font-size: var(--text-2xs); font-weight: 650; letter-spacing: var(--tracking-wider); text-transform: uppercase; color: var(--text-subtle); }

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  text-align: left;
}

.palette-item:hover,
.palette-item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.palette-item[aria-selected="true"] .palette-hint { color: var(--accent); opacity: 0.7; }
.palette-hint { margin-left: auto; font-size: var(--text-xs); color: var(--text-subtle); }

.palette-foot {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: var(--text-2xs);
  color: var(--text-subtle);
}

.palette-empty { padding: var(--space-8); text-align: center; color: var(--text-subtle); font-size: var(--text-md); }

/* --- Mobile navigation --------------------------------------------------- */
.topbar-toggle { display: none; }

@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }

  .app[data-drawer="open"] .sidebar { transform: translateX(0); }

  .topbar-toggle { display: inline-grid; }
  .topbar { padding-inline: var(--space-4); }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sticky) - 1);
    background: var(--overlay);
    animation: fade-in var(--duration-fast) var(--ease-out);
  }

  .scrim[hidden] { display: none; }
}

@media (min-width: 1025px) {
  .scrim { display: none !important; }
}

/* -----------------------------------------------------------------------------
   7. Utilities
   -------------------------------------------------------------------------- */
.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;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 200;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform var(--duration-fast) var(--ease-out);
}

.skip-link:focus { transform: translateY(0); }

.hidden, [hidden] { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.full-width { width: 100%; }
.relative { position: relative; }

.w-full { width: 100%; }
.h-full { height: 100%; }

/* -----------------------------------------------------------------------------
   8. Motion, print, forced colours
   -------------------------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-8px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes slide-in-right { from { transform: translateX(100%); } to { transform: none; } }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

.spinner-on-accent { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }

/* Accessibility: honour the OS "reduce motion" setting everywhere. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton { background: var(--surface-3); }
}

/* High contrast / forced colours mode: let the OS palette win. */
@media (forced-colors: active) {
  .btn, .card, .input, .select, .textarea, .modal, .drawer, .toast, .badge {
    border: 1px solid CanvasText;
  }

  .nav-item.is-active { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  :focus-visible { outline: 2px solid CanvasText; }
}

@media print {
  .sidebar, .topbar, .toast-region, .palette-backdrop, .modal-backdrop, .drawer-backdrop, .scrim { display: none !important; }

  .app { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
  .card, .stat, .table-wrap { box-shadow: none; border-color: #ccc; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
}

/* ==========================================================================
   FORJA PREMIUM UI — final visual layer
   Additive visual polish; no route/data contracts changed.
   ========================================================================== */

:root {
  --premium-glow: rgba(139, 92, 246, 0.16);
  --premium-glow-strong: rgba(139, 92, 246, 0.24);
  --premium-grid: rgba(124, 58, 237, 0.055);
  --premium-card-highlight: rgba(255, 255, 255, 0.72);
}
[data-theme="dark"] {
  --premium-glow: rgba(139, 92, 246, 0.18);
  --premium-glow-strong: rgba(167, 139, 250, 0.28);
  --premium-grid: rgba(167, 139, 250, 0.055);
  --premium-card-highlight: rgba(255, 255, 255, 0.035);
}

.forja-premium {
  background:
    radial-gradient(circle at 0% 0%, var(--premium-glow), transparent 28rem),
    radial-gradient(circle at 100% 8%, var(--premium-glow), transparent 24rem),
    var(--bg);
}
.forja-premium .app-main {
  background:
    linear-gradient(var(--premium-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--premium-grid) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: center top;
}
.forja-premium .sidebar {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(125%);
  -webkit-backdrop-filter: blur(18px) saturate(125%);
  box-shadow: 10px 0 40px rgba(20, 15, 45, 0.045);
}
.forja-premium .sidebar-head {
  background: linear-gradient(180deg, var(--premium-card-highlight), transparent);
}
.forja-premium .brand-mark {
  box-shadow: 0 8px 24px var(--premium-glow-strong);
}
.forja-premium .nav-item {
  transition: transform var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-soft),
              color var(--duration-fast) var(--ease-soft),
              box-shadow var(--duration-fast) var(--ease-soft);
}
.forja-premium .nav-item:hover { transform: translateX(2px); }
.forja-premium .nav-item.active {
  box-shadow: inset 3px 0 0 var(--accent), 0 4px 18px var(--premium-glow);
}
.forja-premium .topbar {
  background: color-mix(in srgb, var(--bg) 76%, transparent);
  box-shadow: 0 1px 0 var(--line), 0 10px 30px rgba(20, 15, 45, 0.035);
}
.forja-premium .page { padding-top: clamp(1.25rem, 2vw, 2rem); }
.forja-premium .page-head {
  padding: clamp(1rem, 2vw, 1.5rem);
  margin-inline: -0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 100% 0%, var(--premium-glow), transparent 20rem),
    color-mix(in srgb, var(--surface) 84%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.forja-premium .page-title {
  font-size: clamp(1.5rem, 2.4vw, 2.15rem);
  letter-spacing: -0.035em;
}
.forja-premium .card,
.forja-premium .stat,
.forja-premium .table-wrap,
.forja-premium .palette,
.forja-premium .form-card {
  border-color: color-mix(in srgb, var(--line-strong) 72%, transparent);
  background:
    linear-gradient(145deg, var(--premium-card-highlight), transparent 42%),
    var(--surface);
  box-shadow: var(--shadow-sm);
}
.forja-premium .card-interactive {
  position: relative;
  overflow: hidden;
}
.forja-premium .card-interactive::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, var(--premium-glow) 52%, transparent 70%);
  transform: translateX(-120%);
  transition: transform 700ms var(--ease-out);
}
.forja-premium .card-interactive:hover::before { transform: translateX(120%); }
.forja-premium .card-interactive:hover {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
  box-shadow: 0 18px 44px var(--premium-glow);
}
.forja-premium .stat {
  transition: transform var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-soft);
}
.forja-premium .stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.forja-premium .btn-primary {
  box-shadow: 0 8px 24px var(--premium-glow-strong), var(--shadow-sm);
}
.forja-premium .btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px var(--premium-glow-strong), var(--shadow-md);
}
.forja-premium input,
.forja-premium select,
.forja-premium textarea {
  transition: border-color var(--duration-fast) var(--ease-soft),
              box-shadow var(--duration-fast) var(--ease-soft),
              background var(--duration-fast) var(--ease-soft);
}
.forja-premium input:focus,
.forja-premium select:focus,
.forja-premium textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
}
.forja-premium .table-wrap { overflow: hidden; }
.forja-premium .table tbody tr:hover {
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface-2));
}
.forja-public { min-height: 100vh; }
.forja-public main {
  position: relative;
  overflow: hidden;
}
.forja-public main::before {
  content: "";
  position: absolute;
  width: 34rem;
  height: 34rem;
  top: -14rem;
  right: -12rem;
  border-radius: 50%;
  background: var(--premium-glow);
  filter: blur(8px);
  pointer-events: none;
}
.forja-public .container {
  position: relative;
  z-index: 1;
}
@media (max-width: 760px) {
  .forja-premium .page-head { margin-inline: 0; padding: 1rem; }
  .forja-premium .page-title { font-size: 1.5rem; }
  .forja-premium .card-body { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .forja-premium *,
  .forja-premium *::before,
  .forja-premium *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
/* Final SaaS/Motion layer */
.motion-studio{overflow:hidden}.motion-toolbar{display:flex;align-items:end;gap:12px;flex-wrap:wrap;margin-bottom:18px}.motion-toolbar .field{min-width:240px;flex:1}.motion-preview-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(320px,1fr);gap:18px}.motion-preview,.motion-canvas{width:100%;aspect-ratio:16/9;border-radius:18px;background:#0b1020;border:1px solid var(--line);overflow:hidden}.motion-preview svg{width:100%;height:100%;object-fit:contain}.motion-empty{display:grid;place-items:center;height:100%;color:#9aa4bd}.admin-management-grid{display:grid;grid-template-columns:minmax(0,1.2fr) minmax(0,1fr);gap:18px}.admin-action-stack{display:flex;gap:6px;flex-wrap:wrap}.admin-plan-form{display:flex;gap:6px;align-items:center;margin-top:7px}.admin-plan-editor{padding:16px;border:1px solid var(--line);border-radius:16px;background:var(--surface-2)}.admin-plan-editor+.admin-plan-editor{margin-top:12px}@media(max-width:1000px){.admin-management-grid,.motion-preview-grid{grid-template-columns:1fr}}@media(max-width:680px){.motion-toolbar .btn,.motion-toolbar .select{width:100%}.admin-plan-form{flex-direction:column;align-items:stretch}.admin-action-stack .btn{flex:1 1 45%}}
