@layer reset, base, layout, components, chart, utils;

/* ============================================================= FONTS */
/* Self-hosted (DSGVO-konform, kein CDN). Variable-Fonts: ein File, alle Gewichte. */
@font-face {
  font-family: 'Schibsted Grotesk';
  src: url('/fonts/schibsted-grotesk.woff2') format('woff2');
  font-weight: 300 900; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'Hanken Grotesk';
  src: url('/fonts/hanken-grotesk.woff2') format('woff2');
  font-weight: 300 900; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/geist-mono.woff2') format('woff2');
  font-weight: 300 700; font-display: swap; font-style: normal;
}

/* ============================================================= TOKENS */
:root {
  --font-display: 'Schibsted Grotesk', system-ui, sans-serif;
  --font-body: 'Hanken Grotesk', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, monospace;

  /* Neutrals — leicht warm-kühler Slate */
  /* Neutrals — warm/sand (harmoniert mit Actimento-Gold) */
  --bg: #faf8f4;
  --bg-tint: #f2efe8;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --ink: #17130b;
  --ink-2: #3f382c;
  --muted: #7a715f;
  --faint: #a89e8a;
  --line: #ebe6db;
  --line-strong: #ddd6c7;

  /* Brand — Actimento-Gold #F9A704 */
  --brand: #f9a704;
  --brand-strong: #e09204;
  --brand-ink: #8a5a00;
  --brand-soft: #fdf1d6;
  --brand-glow: #f9a70428;

  /* Datenrollen: Peers = warmes Graphit, eigener Betrieb = Marken-Gold */
  --c-ist: #2f2a20;      /* Ist-Wert (Peers) */
  --c-ist-2: #524a39;    /* Verlauf-Gradient hell */
  --c-self: #f9a704;     /* eigener Betrieb — Marke */
  --c-self-2: #fdbe3d;
  --c-vj: #cfc7b4;       /* Vorjahr */
  --c-avg: #b0472a;      /* Durchschnittslinie (warmes Rost, kontrastiert Gold+Graphit) */

  /* Status */
  --ok: #16a34a; --warn: #b45309; --err: #be123c; --pending: #8a6d3b;

  --radius-xs: 6px; --radius-sm: 10px; --radius: 14px; --radius-lg: 20px; --radius-pill: 999px;
  --shadow-sm: 0 1px 2px #0f181505, 0 1px 3px #0f181510;
  --shadow: 0 2px 4px #0f181508, 0 8px 24px -8px #0f181518;
  --shadow-lg: 0 12px 40px -12px #0f181530;
  --ring: 0 0 0 3px var(--brand-glow);

  --sidebar-w: 248px;
  --ease: cubic-bezier(.22,.61,.36,1);
}

:root[data-theme="dark"] {
  --bg: #14110a;
  --bg-tint: #1a160d;
  --surface: #1e1a10;
  --surface-2: #221d12;
  --ink: #f4efe2;
  --ink-2: #cfc7b4;
  --muted: #9c927c;
  --faint: #6f6650;
  --line: #322b1b;
  --line-strong: #3f3724;

  --brand: #ffb01a;
  --brand-strong: #ffc247;
  --brand-ink: #ffcf6b;
  --brand-soft: #2a2110;
  --brand-glow: #f9a70433;

  /* Peers hell-neutral, eigener Betrieb Gold */
  --c-ist: #cbc3b0; --c-ist-2: #e7deca;
  --c-self: #ffb01a; --c-self-2: #ffc95c;
  --c-vj: #574f3b;
  --c-avg: #f0774e;
  --ok: #34d399;

  --shadow-sm: 0 1px 2px #00000030;
  --shadow: 0 2px 4px #00000030, 0 10px 30px -10px #00000060;
  --shadow-lg: 0 16px 50px -16px #00000080;
}

/* ============================================================= RESET */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; }
  html { -webkit-text-size-adjust: 100%; }
  body { min-height: 100dvh; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: none; }
  a { color: inherit; text-decoration: none; }
  svg { display: block; }
  ::selection { background: var(--brand); color: #fff; }
}

/* ============================================================= BASE */
@layer base {
  body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    font-size: 14px; line-height: 1.5;
    font-variant-numeric: tabular-nums lining-nums;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background .4s var(--ease), color .4s var(--ease);
    /* subtile Atmosphäre: sanfte Radial-Aura oben links */
    background-image:
      radial-gradient(1200px 600px at -5% -10%, var(--brand-glow), transparent 60%);
    background-attachment: fixed;
  }
  h1, h2, h3 { font-family: var(--font-display); font-weight: 620; letter-spacing: -.015em; line-height: 1.15; }
  .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
}

/* ============================================================= LAYOUT */
@layer layout {
  .app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }

  .sidebar {
    position: sticky; top: 0; height: 100dvh;
    display: flex; flex-direction: column; gap: 4px;
    padding: 22px 16px;
    background: color-mix(in oklab, var(--surface) 70%, var(--bg));
    border-right: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }
  .brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 20px; }
  .brand .glyph {
    width: 38px; height: 38px; border-radius: 11px; flex: none;
    background: linear-gradient(135deg, var(--brand), var(--c-self-2));
    display: grid; place-items: center; color: #1a1205; box-shadow: var(--shadow-sm), inset 0 1px 0 #ffffff40;
  }
  .brand .glyph svg { width: 20px; height: 20px; }
  .brand .name { font-family: var(--font-display); font-weight: 680; font-size: 15px; letter-spacing: -.02em; }
  .brand .name small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .01em; }

  .nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
  .nav .group-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 14px 10px 6px; }
  .nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; border-radius: var(--radius-sm);
    color: var(--ink-2); font-weight: 500; font-size: 13.5px;
    transition: background .18s, color .18s;
  }
  .nav a svg { width: 17px; height: 17px; opacity: .8; flex: none; }
  .nav a:hover { background: var(--bg-tint); color: var(--ink); }
  .nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 620; }
  .nav a.soon { opacity: .5; cursor: default; pointer-events: none; }
  .nav a .tag { margin-left: auto; font-size: 9.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); border: 1px solid var(--line-strong); padding: 1px 6px; border-radius: var(--radius-pill); }

  .sidebar .foot { margin-top: auto; padding: 12px 10px 2px; border-top: 1px solid var(--line); }
  .role-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
  .role-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ok) 22%, transparent); }

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

  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 16px;
    padding: 14px 26px;
    background: color-mix(in oklab, var(--bg) 78%, transparent);
    backdrop-filter: blur(12px) saturate(1.4);
    border-bottom: 1px solid var(--line);
  }
  .topbar .crumb { display: flex; flex-direction: column; }
  .topbar .crumb .eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
  .topbar .crumb h1 { font-size: 19px; }
  .topbar .spacer { flex: 1; }

  .content { padding: 24px 26px 64px; max-width: 1240px; width: 100%; }
  section + section { margin-top: 30px; }
  .section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
  .section-head h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
  .section-head .hint { font-size: 12px; color: var(--faint); }
}

/* ============================================================= COMPONENTS */
@layer components {
  .card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }

  /* Controls-Leiste */
  .controlbar {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px;
    padding: 16px 18px; margin-bottom: 24px;
  }
  .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .field > label { font-size: 11px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
  .select {
    position: relative; display: inline-flex; align-items: center;
  }
  .select select {
    appearance: none; -webkit-appearance: none;
    padding: 9px 34px 9px 13px; min-width: 210px;
    background: var(--surface-2); border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); font-weight: 500; font-size: 13.5px;
    transition: border-color .18s, box-shadow .18s;
  }
  .select::after {
    content: ""; position: absolute; right: 13px; width: 9px; height: 9px; pointer-events: none;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: translateY(-2px) rotate(45deg);
  }
  .select select:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
  .field.grow { flex: 1; }

  .btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 15px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 13.5px; letter-spacing: -.005em;
    border: 1px solid transparent; transition: transform .12s, background .18s, box-shadow .18s, border-color .18s;
    white-space: nowrap;
  }
  .btn svg { width: 16px; height: 16px; }
  .btn:active { transform: translateY(1px); }
  .btn-primary { background: var(--brand); color: #1a1205; box-shadow: var(--shadow-sm), inset 0 1px 0 #ffffff50; }
  .btn-primary:hover { background: var(--brand-strong); }
  .btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
  .btn-ghost:hover { border-color: var(--brand); color: var(--brand-ink); }
  .icon-btn {
    width: 38px; height: 38px; border-radius: var(--radius-sm); display: grid; place-items: center;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
    transition: background .18s, color .18s, border-color .18s;
  }
  .icon-btn:hover { color: var(--brand-ink); border-color: var(--brand); }
  .icon-btn svg { width: 18px; height: 18px; }
  .theme-toggle .moon { display: none; }
  :root[data-theme="dark"] .theme-toggle .sun { display: none; }
  :root[data-theme="dark"] .theme-toggle .moon { display: block; }

  /* KPI-Kacheln */
  .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
  .kpi {
    position: relative; overflow: hidden;
    padding: 16px 17px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  }
  .kpi::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
    background: linear-gradient(var(--brand), var(--brand-strong));
  }
  .kpi .k-label { font-size: 11.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
  .kpi .k-value { font-family: var(--font-mono); font-size: 25px; font-weight: 540; letter-spacing: -.02em; margin-top: 7px; color: var(--ink); }
  .kpi .k-sub { font-size: 11.5px; color: var(--faint); margin-top: 3px; }
  .kpi.accent::before { background: linear-gradient(var(--c-self), var(--c-self-2)); }
  .kpi.accent .k-value { color: var(--brand-ink); }

  /* Metrik-Karten / Charts */
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
  .metric {
    padding: 16px 18px 14px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
    transition: box-shadow .25s var(--ease), border-color .25s, transform .25s var(--ease);
  }
  .metric:hover { box-shadow: var(--shadow); border-color: var(--line-strong); transform: translateY(-2px); }
  .metric .m-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
  .kchip {
    font-family: var(--font-mono); font-size: 11px; font-weight: 550; letter-spacing: .01em;
    color: var(--brand-ink); background: var(--brand-soft);
    padding: 3px 8px; border-radius: var(--radius-pill); white-space: nowrap;
  }
  .metric .m-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
  .metric .m-cat { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
  .metric .m-stats { display: flex; gap: 16px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
  .metric .m-stats .s { display: flex; flex-direction: column; gap: 1px; }
  .metric .m-stats .s .lab { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .metric .m-stats .s .val { font-family: var(--font-mono); font-size: 14px; font-weight: 520; }
  .metric .m-stats .s.avg .val { color: var(--c-avg); }

  .empty {
    display: grid; place-items: center; text-align: center; gap: 14px;
    padding: 70px 24px; color: var(--muted);
  }
  .empty .art { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center;
    background: var(--brand-soft); color: var(--brand); box-shadow: var(--shadow-sm); }
  .empty .art svg { width: 34px; height: 34px; }
  .empty h3 { font-size: 18px; color: var(--ink); }
  .empty p { max-width: 380px; }

  /* Legende */
  .legend { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-top: 26px; padding: 14px 18px; color: var(--muted); font-size: 12.5px; }
  .legend .lg { display: inline-flex; align-items: center; gap: 7px; }
  .legend .sw { width: 15px; height: 11px; border-radius: 3px; }
  .sw.ist { background: var(--c-ist); } .sw.self { background: var(--c-self); }
  .sw.vj { background: var(--c-vj); }
  .sw.avg { width: 18px; height: 0; border-top: 2px dashed var(--c-avg); border-radius: 0; }

  /* Toast */
  .toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
  .toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 15px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 500;
    animation: toast-in .3s var(--ease);
  }
  .toast.err { border-color: color-mix(in oklab, var(--err) 45%, var(--line)); }
  .toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
  .toast.err .dot { background: var(--err); }
}

/* ============================================================= CHART */
@layer chart {
  .chart-wrap { margin-top: 12px; position: relative; }
  .chart-wrap svg { width: 100%; height: auto; overflow: visible; }
  .axis { stroke: var(--line); stroke-width: 1; }
  .gridline { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; opacity: .7; }
  .bar { transform-origin: bottom; animation: grow .6s var(--ease) backwards; }
  .bar-ist { fill: url(#gIst); }
  .bar-self { fill: url(#gSelf); }
  .bar-vj { fill: var(--c-vj); opacity: .9; }
  .bar:hover { filter: brightness(1.06); }
  .avg-line { stroke: var(--c-avg); stroke-width: 1.6; stroke-dasharray: 5 4; }
  .avg-cap { fill: var(--c-avg); }
  .p-label { fill: var(--muted); font-size: 10.5px; font-family: var(--font-body); font-weight: 500; }
  .p-label.self { fill: var(--brand-ink); font-weight: 700; }
  .avg-tag { fill: var(--c-avg); font-size: 10px; font-weight: 700; font-family: var(--font-mono); }
  .trend-line { stroke: var(--brand); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
  .trend-avg { stroke: var(--c-avg); stroke-width: 1.4; stroke-dasharray: 5 4; opacity: .8; }
  .trend-dot { fill: var(--brand); stroke: var(--surface); stroke-width: 1.5; animation: reveal .4s var(--ease) backwards; }

  .tooltip {
    position: fixed; z-index: 60; pointer-events: none; opacity: 0;
    transform: translate(-50%, -118%); transition: opacity .12s;
    background: var(--ink); color: var(--surface);
    padding: 7px 10px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow-lg);
    white-space: nowrap;
  }
  .tooltip .tt-lab { font-weight: 700; }
  .tooltip .tt-row { display: flex; gap: 8px; justify-content: space-between; font-family: var(--font-mono); }
  .tooltip.show { opacity: 1; }
}

/* ============================================================= UTILS + MOTION */
@layer utils {
  .reveal { animation: reveal .5s var(--ease) backwards; }
  @keyframes reveal { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  @keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
  @keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  }
}

/* ============================================================= ADMIN COMPONENTS */
@layer components {
  .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
  .page-head .lead h2 { font-family: var(--font-display); font-size: 22px; font-weight: 640; letter-spacing: -.02em; text-transform: none; color: var(--ink); }
  .page-head .lead p { color: var(--muted); font-size: 13.5px; margin-top: 3px; max-width: 60ch; }
  .page-head .actions { display: flex; gap: 10px; }
  .btn-danger { background: var(--surface); border: 1px solid color-mix(in oklab, var(--err) 40%, var(--line-strong)); color: var(--err); }
  .btn-danger:hover { background: color-mix(in oklab, var(--err) 10%, var(--surface)); }
  .btn-sm { padding: 6px 11px; font-size: 12.5px; }
  .btn:disabled { opacity: .5; pointer-events: none; }

  /* Panels / Grid */
  .cols { display: grid; gap: 18px; }
  .cols.two { grid-template-columns: 1.4fr 1fr; }
  @media (max-width: 960px) { .cols.two { grid-template-columns: 1fr; } }
  .panel { padding: 18px 20px; }
  .panel > h3 { font-family: var(--font-display); font-size: 15px; font-weight: 620; margin-bottom: 2px; }
  .panel > .desc { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }

  /* Tabellen */
  .table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); }
  table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
  table.tbl th { text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
  table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
  table.tbl tr:last-child td { border-bottom: none; }
  table.tbl tbody tr { transition: background .12s; }
  table.tbl tbody tr:hover { background: var(--bg-tint); }
  table.tbl td.num { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
  table.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
  .cell-strong { font-weight: 600; }
  .cell-sub { color: var(--muted); font-size: 12px; }
  .mono-chip { font-family: var(--font-mono); font-size: 11.5px; background: var(--bg-tint); padding: 2px 7px; border-radius: var(--radius-xs); }

  /* Status-Badges */
  .badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-pill); border: 1px solid transparent; white-space: nowrap; }
  .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .badge.pending  { color: var(--pending); background: color-mix(in oklab, var(--pending) 12%, transparent); }
  .badge.mapped   { color: #2563eb; background: #2563eb18; }
  .badge.validated{ color: var(--ok); background: color-mix(in oklab, var(--ok) 14%, transparent); }
  .badge.error    { color: var(--err); background: color-mix(in oklab, var(--err) 12%, transparent); }
  .badge.neutral  { color: var(--muted); background: var(--bg-tint); }

  /* Formulare */
  .form { display: flex; flex-direction: column; gap: 14px; }
  .form .row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
  @media (max-width: 620px) { .form .row { grid-template-columns: 1fr; } }
  .form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
  .form label .req { color: var(--err); }
  .input, .textarea, .form select {
    appearance: none; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface-2); font-size: 14px; font-weight: 450; color: var(--ink); width: 100%;
    transition: border-color .16s, box-shadow .16s; font-family: inherit;
  }
  .input:focus, .textarea:focus, .form select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
  .textarea { min-height: 120px; resize: vertical; font-family: var(--font-mono); font-size: 13px; line-height: 1.55; }
  .form .hint { font-size: 11.5px; color: var(--faint); font-weight: 450; }
  .form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

  /* Dropzone */
  .dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); background: var(--surface-2); transition: border-color .16s, background .16s; cursor: pointer; }
  .dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
  .dropzone svg { width: 28px; height: 28px; margin-bottom: 8px; opacity: .7; }
  .dropzone b { color: var(--ink-2); }

  /* Modal */
  .modal-back { position: fixed; inset: 0; z-index: 80; background: #0a0a0acc; backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; animation: reveal .2s var(--ease); }
  .modal { width: min(560px, 96vw); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: modal-pop .28s var(--ease); }
  @keyframes modal-pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
  .modal .m-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
  .modal .m-top h3 { font-family: var(--font-display); font-size: 17px; }
  .modal .m-body { padding: 20px; }
  .modal .close { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
  .modal .close:hover { background: var(--bg-tint); color: var(--ink); }

  /* Tabs */
  .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
  .tabs button { padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
  .tabs button:hover { color: var(--ink); }
  .tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

  /* KV list / detail */
  .kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: 13.5px; }
  .kv dt { color: var(--muted); font-weight: 500; }
  .kv dd { font-weight: 550; }

  .inline-empty { padding: 34px 20px; text-align: center; color: var(--muted); font-size: 13.5px; }
  .stat-inline { display: inline-flex; gap: 5px; align-items: baseline; }
  .stat-inline b { font-family: var(--font-mono); }
  .backlink { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; margin-bottom: 14px; }
  .backlink:hover { color: var(--brand-ink); }
  .backlink svg { width: 15px; height: 15px; }
}

/* ============================================================= AUTH + FOOT */
@layer components {
  .auth-screen {
    position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px;
    background: var(--bg);
    background-image: radial-gradient(900px 500px at 80% -10%, var(--brand-glow), transparent 60%),
                      radial-gradient(700px 500px at 0% 110%, var(--brand-glow), transparent 60%);
  }
  .auth-card {
    width: min(400px, 94vw); background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px; display: flex; flex-direction: column; gap: 13px;
    animation: modal-pop .3s var(--ease);
  }
  .auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 6px; }
  .auth-brand .glyph { width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--c-self-2)); color: #1a1205; box-shadow: var(--shadow-sm); }
  .auth-brand .glyph svg { width: 21px; height: 21px; }
  .auth-brand strong { font-family: var(--font-display); font-size: 15px; letter-spacing: -.01em; }
  .auth-brand span { display: block; font-size: 11.5px; color: var(--muted); }
  .auth-card h1 { font-family: var(--font-display); font-size: 23px; margin-top: 4px; }
  .auth-sub { color: var(--muted); font-size: 13px; margin-top: -8px; margin-bottom: 4px; }
  .auth-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }

  .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .user-box { min-width: 0; }
  .role-pill span { display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; vertical-align: bottom; }
  .role-sub { display: block; font-size: 11px; color: var(--faint); padding-left: 15px; margin-top: 1px; }
  .logout { width: 34px; height: 34px; border-radius: 8px; flex: none; display: grid; place-items: center; color: var(--muted); border: 1px solid var(--line); transition: color .15s, border-color .15s, background .15s; }
  .logout:hover { color: var(--err); border-color: color-mix(in oklab, var(--err) 40%, var(--line)); }
  .logout svg { width: 17px; height: 17px; }
}

/* ============================================================= RESPONSIVE */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar .nav, .sidebar .foot { display: none; }
  .content { padding: 18px 16px 48px; }
  .topbar { padding: 12px 16px; }
}
