  :root {
    --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7385; --border: #dde1e8;
    --accent: #2f6fdf; --accent-weak: #e6eefc; --sel: #fff6d6; --danger: #c33;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #14171c; --panel: #1c2027; --text: #e4e7ec; --muted: #949bab; --border: #2e343e;
      --accent: #6b9cf5; --accent-weak: #22324f; --sel: #3a3420; --danger: #ff7b72;
    }
  }
  * { box-sizing: border-box; }
  /* Die Seite füllt genau die Fensterhöhe; gescrollt wird nur in Tabelle und JSON-Anzeige */
  body { margin: 0; font: 14px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--text);
         height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  header { flex: none; }
  header { padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
           display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
  header h1 { font-size: 17px; margin: 0; }
  header .info { color: var(--muted); }
  /* overflow: auto nur als Notlösung für sehr kleine Fenster (Mindesthöhen unten) */
  main { flex: 1; min-height: 0; padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; overflow: auto; }
  main > section { flex: none; }
  /* Tabelle und Auswahl teilen sich die restliche Höhe; das Verhältnis setzt der Trenngriff (flex-grow) */
  /* min-height 0: sonst richtet sich die Mindesthöhe nach dem ganzen JSON-Inhalt (Hauptfenster setzt eigene Werte) */
  main > section.fill { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
  /* ×1000: wächst ein Panel allein, muss die Summe ≥ 1 sein, sonst nutzt es nur seinen Anteil des Platzes */
  #tableSection.fill { flex-grow: calc(var(--split, .6) * 1000); min-height: 200px; }
  #exportSection.fill { flex-grow: calc((1 - var(--split, .6)) * 1000); min-height: 130px; }
  /* Fehlliste aufgeklappt: Panel braucht Platz für Liste und JSON, notfalls auf Kosten der Tabelle */
  #exportSection.fill:has(.missing.open) { min-height: 330px; }
  .fill .tableWrap, .fill #preview { flex: 1; min-height: 60px; max-height: none; }
  section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
  section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
  button, select, input[type=text], input[type=search] {
    font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--border);
    border-radius: 6px; padding: 5px 10px;
  }
  button { cursor: pointer; }
  button:hover:not(:disabled) { border-color: var(--accent); }
  button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  button:disabled { opacity: .5; cursor: default; }
  .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .spacer { flex: 1; }
  .muted { color: var(--muted); }

  #drop { border: 2px dashed var(--border); border-radius: 8px; padding: 28px; text-align: center; cursor: pointer; }
  #drop.over, body.dragging #drop { border-color: var(--accent); background: var(--accent-weak); }
  .loaded #drop { padding: 10px; }

  #keyList { display: flex; flex-wrap: wrap; gap: 6px; max-height: 180px; overflow: auto; }
  .chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 6px; border: 1px solid var(--border);
          border-radius: 999px; cursor: pointer; user-select: none; }
  .chip.on { background: var(--accent-weak); border-color: var(--accent); }
  .chip .n { color: var(--muted); font-size: 12px; }
  .chip .ord { font-size: 11px; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; }

  .tableWrap { overflow: auto; max-height: 60vh; border: 1px solid var(--border); border-radius: 6px; }
  /* separate statt collapse: die Rahmen gehören zur Zelle und decken beim Scrollen mit ab */
  table { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
  th, td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
  /* Der ganze Kopf klebt als Block, so kann sich die Filterzeile nie über andere Zeilen schieben */
  thead { position: sticky; top: 0; z-index: 2; }
  thead th { position: relative; background: var(--panel); overflow: hidden; text-overflow: ellipsis; }
  thead tr.h th { cursor: pointer; user-select: none; }
  thead tr.h th { border-bottom: 0; }
  thead tr.f th { padding-top: 0; border-bottom: 2px solid var(--border); }
  thead tr.f input { width: 100%; min-width: 0; padding: 3px 6px; font-size: 13px; }
  .rz { position: absolute; top: 0; right: 0; width: 7px; height: 100%; cursor: col-resize; touch-action: none; }
  .rz:hover, .rz.active { background: var(--accent); opacity: .5; }
  th .arrow { color: var(--accent); margin-left: 4px; }
  td { overflow: hidden; text-overflow: ellipsis; }
  td.obj { font-family: var(--mono); font-size: 12px; color: var(--muted); }
  tbody tr:hover { background: var(--accent-weak); }
  tbody tr.sel { background: var(--sel); }

  #preview { font-family: var(--mono); font-size: 12px; white-space: pre; overflow: auto; max-height: 50vh;
             background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 10px 0 0; }
  .hidden { display: none !important; }
  .err { color: var(--danger); }
  #toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 8px 14px;
           border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; }
  #toast.show { opacity: .95; }

  .mt { margin-top: 10px; }
  .mb { margin-bottom: 10px; }
  .mb8 { margin-bottom: 8px; }
  .hint { font-size: 12px; }
  .wide { min-width: 260px; }
  .exportGroup { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
  .fnameLabel { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); max-width: 100%; }
  /* Eingabefeld deutlich vom Knopf abheben: Hintergrund der Seite, Rahmen innen, Textcursor */
  /* Textfeld statt input, damit lange Namen umbrechen; Höhe passt fitFilename() (common.js) an */
  textarea.fname { width: 300px; max-width: 100%; font: inherit; line-height: 1.4; padding: 5px 10px; resize: none; overflow: hidden;
                   border: 1px solid var(--border); border-radius: 6px; vertical-align: middle; overflow-wrap: anywhere;
                   background: var(--bg); box-shadow: inset 0 1px 2px rgba(0,0,0,.08); color: var(--text); }
  textarea.fname:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
  .ord.ghost { visibility: hidden; }
  th.cb, td.cb { text-align: left; text-overflow: clip; }
  .bomTag { font-size: 10px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 4px;
            padding: 0 4px; margin-left: 4px; vertical-align: middle; }
  .warn { margin-top: 10px; color: var(--danger); font-size: 13px; }
  /* Ziehgriff unter Tabelle und JSON-Anzeige */
  .vResize { flex: none; height: 12px; margin: -14px 0; cursor: row-resize; touch-action: none; border-radius: 6px;
             display: flex; align-items: center; justify-content: center; }
  .vResize::before { content: ""; width: 48px; height: 4px; border-radius: 2px; background: var(--border); }
  .vResize:hover::before, .vResize.active::before { background: var(--accent); }
  /* Fehlende BOM-Produkte */
  /* aufgeklappt teilt sie sich den Platz mit der JSON-Anzeige und scrollt in sich */
  .missing { flex: none; display: flex; flex-direction: column; overflow: hidden; margin-top: 10px; border: 1px solid var(--danger); border-radius: 6px; font-size: 13px; }
  .missSum { flex: none; display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: none;
             padding: 6px 10px; color: var(--danger); font-weight: 600; }
  .missSum::before { content: "▸ "; }
  .missing.open .missSum::before { content: "▾ "; }
  .missing:not(.open) .missWrap { display: none; }
  /* so hoch wie der Inhalt (höchstens 35 %), bei Platzmangel schrumpfbar, aber nie unter Überschrift + 1 Zeile */
  .missing.open { flex: 0 1 auto; min-height: 96px; max-height: 35vh; }
  .missWrap { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--border); }
  .missTable { width: 100%; table-layout: auto; }
  .missTable th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--muted); }
  .missTable td { white-space: normal; vertical-align: top; overflow-wrap: anywhere; }
  .missTable td.obj { max-width: 360px; }
  .missTable td:nth-child(-n+2) { white-space: nowrap; overflow-wrap: normal; } /* type und id nie umbrechen */
  /* BOM-Eintrag, dessen Produkt in der Datei fehlt (JSON-Anzeige) */
  .missRef { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); border-radius: 3px; }
