/* qdrt Gridfinity Studio · projekteigene Regeln
   Setzt tokens.css und base.css (QDRT-Default-Web-Standard-CI v1.0.0) voraus. Tokens nur ergänzen, nie
   umbenennen; Farben nur über Tokens, kein Hex. */

@layer tokens {
  :root {
    /* 3D-Ansicht, aus vorhandenen Tokens abgeleitet. Das Modell ist neutral grau, nicht bunt. */
    --viewer-bg: color-mix(in srgb, var(--surface-2) 70%, var(--bg));
    --viewer-bed: color-mix(in srgb, var(--surface) 80%, var(--line));
    --viewer-grid: color-mix(in srgb, var(--line) 75%, var(--text-3));
    --viewer-model: color-mix(in srgb, var(--surface) 55%, var(--text-3));
    --viewer-edge: color-mix(in srgb, var(--text) 70%, var(--surface));
    --viewer-volume: color-mix(in srgb, var(--text-3) 70%, var(--surface));

    --editor-params-w: 320px;
    --editor-facts-w: 280px;
  }
}

@layer base {
  .skip-link {
    position: absolute; left: 12px; top: -48px; z-index: 50; padding: 8px 12px; border-radius: var(--radius-s);
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); font-weight: 600;
  }
  .skip-link:focus { top: 12px; }
  a:not([class]) { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
}

@layer components {
  /* Kopfleiste */
  .topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
  .who { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text-2); font-weight: 550; }
  @media (max-width: 640px) { .hide-sm { display: none; } }

  .btn-block { width: 100%; }
  .card-head.pad { padding: 20px 20px 0; }
  .meter-wide { max-width: 320px; width: 100%; margin-inline: auto; }
  .crumbs { font-size: 13px; color: var(--text-3); margin-bottom: 4px; }
  .crumbs a:hover { color: var(--text); }
  .switch a[role="tab"] { display: inline-flex; align-items: center; gap: 6px; }

  /* Anmeldung */
  .auth {
    min-height: 100dvh;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
    padding: 24px 16px;
    background:
      radial-gradient(1200px 600px at 50% -10%, color-mix(in oklab, var(--text) 6%, transparent), transparent 70%),
      var(--bg);
  }
  .auth-card {
    width: min(100%, 400px);
    display: flex; flex-direction: column; gap: 20px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-3);
  }
  .auth-brand { color: var(--text); }
  .auth-logo { width: 96px; height: auto; }
  .auth-card .lead { color: var(--text-2); margin-top: 4px; font-size: 14.5px; }
  .auth-error {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13.5px; font-weight: 550;
    color: var(--danger);
    background: color-mix(in oklab, var(--danger) 10%, transparent);
  }
  .auth-error .icon { margin-top: 2px; }
  .auth-foot { font-size: 12.5px; color: var(--text-3); }

  /* Ablage: Baum links, Modelle rechts */
  .storage { display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); gap: 16px; align-items: start; }
  @media (max-width: 820px) { .storage { grid-template-columns: minmax(0, 1fr); } }

  /* Bibliothek: Vorlagenkarten */
  .template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
  .template-card { display: flex; flex-direction: column; gap: 12px; padding: 0; overflow: hidden; transition: box-shadow var(--dur-2); }
  .template-card:hover { box-shadow: var(--shadow-2); }
  .template-thumb { aspect-ratio: 4 / 3; background: var(--viewer-bg); display: grid; place-items: center; border-bottom: 1px solid var(--line); }
  .template-thumb img { width: 100%; height: 100%; object-fit: cover; }
  .template-thumb-empty { color: var(--text-3); }
  .template-thumb-empty .icon { width: 40px; height: 40px; stroke-width: 1.25; }
  .template-body { display: flex; flex-direction: column; gap: 6px; padding: 0 16px; align-items: flex-start; }
  .template-body p { color: var(--text-2); font-size: 14px; }
  .template-foot { margin-top: auto; padding: 0 16px 16px; display: flex; justify-content: flex-end; }

  /* Editor: Parameter 320 px · Ansicht flexibel · Kennwerte 280 px */
  .editor-main { width: 100%; max-width: none; }
  .editor-head .sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .editor {
    display: grid; gap: 16px; align-items: start;
    grid-template-columns: var(--editor-params-w) minmax(0, 1fr) var(--editor-facts-w);
    grid-template-areas: "params stage facts";
  }
  .editor-params { grid-area: params; display: flex; flex-direction: column; gap: 12px; }
  .editor-stage { grid-area: stage; display: flex; flex-direction: column; position: sticky; top: calc(var(--topbar-h) + 8px); }
  .editor-facts { grid-area: facts; position: sticky; top: calc(var(--topbar-h) + 8px); }
  @media (max-width: 1100px) {
    .editor { grid-template-columns: var(--editor-params-w) minmax(0, 1fr); grid-template-areas: "params stage" "params facts"; }
    .editor-facts { position: static; }
  }
  @media (max-width: 820px) {
    .editor { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "facts" "params"; }
    .editor-stage { position: static; }
  }

  .param-card { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
  .param-card > h2 { font-size: 14px; }
  .param-card > .btn { align-self: flex-start; }
  .param-field .switch { align-self: flex-start; }
  .param-field [aria-invalid] { border-color: var(--danger); }
  .param-field .switch[aria-invalid] { box-shadow: 0 0 0 1px var(--danger); }
  .stepper { display: flex; align-items: center; gap: 6px; }
  .stepper .input { width: 84px; text-align: center; }
  .stepper .btn { width: 34px; padding: 0; }
  .stepper .unit { font-size: 13px; font-weight: 500; color: var(--text-3); }

  .stage-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .stage-quality { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--text-3); }
  .stage-quality.is-busy { color: var(--info); }
  .stage-notice { margin: 12px; }
  .viewer { position: relative; height: min(68dvh, 720px); min-height: 360px; background: var(--viewer-bg); overflow: hidden; touch-action: none; }
  .viewer-canvas { display: block; width: 100%; height: 100%; }
  .viewer-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--info); }
  .viewer-overlay {
    position: absolute; inset: 0; display: grid; place-items: center; z-index: 2;
    background: color-mix(in oklab, var(--viewer-bg) 88%, transparent);
  }
  .viewer-labels { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
  .viewer-label {
    position: absolute; left: 0; top: 0; padding: 1px 7px; border-radius: var(--radius-pill);
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
    color: var(--text-2); background: color-mix(in oklab, var(--surface) 88%, transparent); border: 1px solid var(--line);
  }
  .viewer-label.is-danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, transparent); }
  .section-slider {
    position: absolute; left: 50%; bottom: 14px; translate: -50% 0; z-index: 2; width: min(320px, 70%);
    padding: 8px 14px; border-radius: var(--radius-pill); background: color-mix(in oklab, var(--surface) 92%, transparent);
    border: 1px solid var(--line); box-shadow: var(--shadow-1);
  }
  .section-slider input { width: 100%; accent-color: var(--text-2); }
  @media (max-width: 820px) { .viewer { height: 60dvh; min-height: 300px; } }

  .kv-facts { grid-template-columns: minmax(96px, 40%) minmax(0, 1fr); font-size: 13.5px; }
  .log { margin-top: 16px; font-size: 13px; }
  .log summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
  .log pre {
    margin-top: 8px; max-height: 260px; overflow: auto; padding: 10px; border-radius: var(--radius-s);
    background: var(--surface-2); font-family: var(--font-mono); font-size: 11.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
  }
}

@layer motion {
  .auth-card { animation: rise var(--dur-3) var(--ease-out) both; }
  .template-grid > * { animation: rise var(--dur-3) var(--ease-out) both; }
}
