/* QDRT-Default-Web-Standard-CI · Grundbausteine · v1.0.0
   Setzt tokens.css voraus. Handgeschrieben, ohne Framework, ohne Build-Schritt.
   Referenz: Register-Watch (register.dev01.qdrtcloud.de). */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-height: 100dvh; }
  img, svg { display: block; max-width: 100%; }
  input, button, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: 0; padding: 0; }
  a { color: inherit; text-decoration: none; }
  ul, ol { list-style: none; padding: 0; }
  h1, h2, h3 { font-size: inherit; font-weight: inherit; }
  [hidden] { display: none !important; }
}

@layer base {
  html { background: var(--bg); color: var(--text); }
  body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    background: var(--bg);
  }
  h1 { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
  h2 { font-size: 16px; font-weight: 620; letter-spacing: -.01em; }
  h3 { font-size: 14px; font-weight: 600; }
  p { text-wrap: pretty; }
  :focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-s); }
  code, .mono { font-family: var(--font-mono); font-size: .9em; }
  .num { font-variant-numeric: tabular-nums; }  /* nur in Spalten, nicht bei großen Einzelwerten */
}

/* ---------- Rahmen: Seitenleiste, Kopfleiste, Inhalt ---------- */
@layer layout {
  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "side top" "side main";
    min-height: 100dvh;
  }
  .shell-sidebar {
    grid-area: side; position: sticky; top: 0; height: 100dvh;
    display: flex; flex-direction: column; gap: 28px; padding: 22px 14px 18px;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .shell-topbar {
    grid-area: top; position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 32px;
    background: color-mix(in oklab, var(--bg) 80%, transparent);
    backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  }
  .shell-main { grid-area: main; width: min(100%, var(--content-max)); padding: 12px 32px 28px; display: flex; flex-direction: column; gap: 22px; }
  .shell-footer {
    margin-top: auto; padding-top: 22px; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between;
    font-size: 12px; color: var(--text-3); border-top: 1px solid var(--line);
  }
  .page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
  .page-head p { color: var(--text-2); margin-top: 4px; }
  .page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

  .grid { display: grid; gap: 16px; }
  .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(208px, 1fr)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .grid-detail { grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); align-items: start; }
  .stack { display: flex; flex-direction: column; gap: 14px; }

  @media (max-width: 1100px) { .grid-2, .grid-detail { grid-template-columns: minmax(0, 1fr); } }
  @media (max-width: 820px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "side" "top" "main"; }
    .shell-sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
    .shell-topbar { position: static; padding: 0 16px; height: 52px; }
    .shell-main { padding: 8px 16px 24px; }
  }
  @media (max-width: 640px) { .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
}

/* ---------- Bausteine ---------- */
@layer components {
  /* Lucide-Icons als Sprite: <svg class="icon"><use href="icons/lucide.svg#name"/></svg> */
  .icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
  .icon-sm { width: 15px; height: 15px; }

  /* Marke und Navigation */
  .brand { display: flex; flex-direction: column; gap: 8px; padding: 2px 10px; color: var(--text); }
  .brand-logo { width: 88px; height: auto; }
  .brand-app { font-size: 11.5px; font-weight: 650; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); }
  .nav { display: flex; flex-direction: column; gap: 2px; }
  .nav-item {
    display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-s);
    color: var(--text-2); font-weight: 520; font-size: 14.5px; white-space: nowrap;
    transition: background var(--dur-1), color var(--dur-1);
  }
  .nav-item:hover { background: var(--surface-2); color: var(--text); }
  .nav-item[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
  @media (max-width: 820px) {
    .brand-app { display: none; }
    .brand-logo { width: 64px; }
    .nav { flex-direction: row; overflow-x: auto; }
  }

  /* Karten */
  .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); box-shadow: var(--shadow-1); padding: 20px; }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
  .card-flush { padding: 0; overflow: hidden; }
  .sub-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 18px 0 8px; }

  /* Kennzahl-Kachel */
  .kpi { display: flex; flex-direction: column; gap: 6px; min-height: 132px; transition: box-shadow var(--dur-2); }
  .kpi:hover { box-shadow: var(--shadow-2); }
  .kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
  .kpi-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
  .kpi-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--surface-2); color: var(--text-2); }
  .kpi-value { font-size: 38px; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; margin-top: auto; }
  .kpi-sub { font-size: 12.5px; color: var(--text-3); }
  .kpi.tone-info .kpi-value, .kpi.tone-info .kpi-icon { color: var(--info); }
  .kpi.tone-warn .kpi-value, .kpi.tone-warn .kpi-icon { color: var(--warn); }
  .kpi.tone-danger .kpi-value, .kpi.tone-danger .kpi-icon { color: var(--danger); }
  @media (max-width: 640px) { .kpi { min-height: 0; padding: 14px; } .kpi-value { font-size: 30px; } }

  /* Knöpfe: eine Hauptaktion (btn-primary) je Bereich */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
    border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 600; transition: background var(--dur-1), border-color var(--dur-1), transform var(--dur-1);
  }
  .btn:active { transform: translateY(1px); }
  .btn:disabled { opacity: .5; cursor: not-allowed; }
  .btn-primary { background: var(--brand); border-color: transparent; color: var(--on-brand); }
  .btn-primary:hover { background: color-mix(in oklab, var(--brand) 88%, var(--bg)); }
  .btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
  .btn-ghost:hover { background: var(--surface-2); color: var(--text); }
  .btn-danger { background: transparent; border-color: transparent; color: var(--danger); }
  .btn-danger:hover { background: color-mix(in oklab, var(--danger) 10%, transparent); }
  .btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
  .btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; border-radius: 12px; }

  /* Umschalter (Segmente) */
  .switch { display: flex; gap: 2px; padding: 3px; max-width: 100%; background: var(--surface-2); border-radius: 10px; overflow-x: auto; scrollbar-width: none; }
  .switch [role="tab"], .switch button { flex: none; height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
  .switch [aria-selected="true"], .switch [aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

  /* Formulare */
  .field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
  .field-hint { font-size: 12.5px; font-weight: 450; color: var(--text-3); }
  .field-error { font-size: 12.5px; font-weight: 600; color: var(--danger); }
  .input {
    height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
    font-size: 15px; font-weight: 450; transition: border-color var(--dur-1), box-shadow var(--dur-1);
  }
  .input:focus { outline: none; border-color: var(--text-3); box-shadow: var(--focus); }
  .input-sm { height: 34px; font-size: 14px; }
  .textarea { width: 100%; height: auto; min-height: 84px; padding: 10px 12px; line-height: 1.45; resize: vertical; }
  select.input {
    appearance: none; -webkit-appearance: none; padding-right: 34px;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
    background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  }

  /* Zustands-Chips: Farbe trägt den Zustand, der Text sagt ihn */
  .chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
  .chip {
    --c: var(--text-3);
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: var(--radius-pill);
    font-size: 12.5px; font-weight: 600; white-space: nowrap;
    color: color-mix(in oklab, var(--c) 88%, var(--text)); background: color-mix(in oklab, var(--c) 12%, transparent);
  }
  .chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
  .chip.tone-info { --c: var(--info); }
  .chip.tone-warn { --c: var(--warn); }
  .chip.tone-danger { --c: var(--danger); }
  .chip.tone-ok { --c: var(--ok); }

  /* Hinweise */
  .notice {
    --c: var(--info);
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 14px;
    color: color-mix(in oklab, var(--c) 70%, var(--text)); background: color-mix(in oklab, var(--c) 9%, transparent);
    border: 1px solid color-mix(in oklab, var(--c) 22%, transparent);
  }
  .notice > .icon { margin-top: 2px; color: var(--c); }
  .notice.tone-warn { --c: var(--warn); }
  .notice.tone-danger { --c: var(--danger); }
  .notice.tone-ok { --c: var(--ok); }

  /* Tabellen */
  .table-wrap { overflow-x: auto; position: relative; }
  .table { width: 100%; border-collapse: collapse; font-size: 14px; }
  .table th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--text-2); padding: 8px 12px; border-bottom: 1px solid var(--line); }
  .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
  .table tr:last-child td { border-bottom: 0; }
  .row-link { font-weight: 600; }
  .row-link:hover { text-decoration: underline; text-underline-offset: 3px; }

  /* Schlüssel-Wert-Liste */
  .kv { display: grid; grid-template-columns: minmax(130px, 38%) minmax(0, 1fr); gap: 10px 16px; font-size: 14px; }
  .kv dt { color: var(--text-2); }
  .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

  /* Fortschritt / Kontingent */
  .meter { height: 6px; margin-top: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; max-width: 260px; }
  .meter > span { display: block; height: 100%; background: var(--text-2); transform-origin: left; transform: scaleX(var(--p)); transition: --p var(--dur-3) var(--ease-out); }

  /* Leerer Zustand */
  .empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 36px 16px; }
  .empty-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); color: var(--text-3); margin-bottom: 4px; }
  .empty p { max-width: 46ch; color: var(--text-2); font-size: 14px; }

  /* Etiketten */
  .tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
  .tag { display: inline-flex; align-items: center; gap: 2px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 550; background: var(--surface-2); }

}

@layer motion {
  @keyframes rise { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
  .grid-kpi > * { animation: rise var(--dur-3) var(--ease-out) both; }
  @media (prefers-reduced-motion: reduce) {
    *, ::view-transition-group(*) { animation-duration: 1ms !important; animation-delay: 0s !important; transition-duration: 1ms !important; }
  }
}

@layer utilities {
  /* Hilfsklassen in der letzten Ebene: schlagen Bausteine wie .table th */
  .muted { color: var(--text-3); }
  .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
  .small { font-size: 12.5px; }
  .right { text-align: right; }
  .nowrap { white-space: nowrap; }
  .text-danger { color: var(--danger); }
  .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; }
}
