/* ==================================================================
   Distill — CCC CI mit Amber‑Akzent (#f59e0b)
   ================================================================== */

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #ebebeb;
  --surface-3: #f7f7f7;
  --border: #d0cfcf;
  --text: #282828;
  --text-muted: #5e5e5e;
  --primary: #f59e0b;
  --primary-hover: #d68309;
  --primary-text: #ffffff;
  --accent: #32373c;
  --brand-red: #DC0021;
  --brand-blue: #1890d7;
  --brand-gray: #4E5456;
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, .12);
  --err: #DC0021;
  --err-bg: rgba(220, 0, 33, .08);
  --ok: #16a34a;
  --shadow-sm: 0 1px 2px rgba(40,40,40,.06), 0 1px 3px rgba(40,40,40,.08);
  --shadow-md: 0 4px 12px rgba(40,40,40,.10), 0 2px 4px rgba(40,40,40,.06);
  --radius: 6px;
  --radius-lg: 10px;
  --topbar-h: 60px;
  --bottombar-h: 28px;
  --font: "Roboto","Helvetica Neue",Helvetica,Arial,sans-serif;
  --mono: "SF Mono",Menlo,Consolas,monospace;
}

[data-theme="dark"] {
  --bg: #1d1f21;
  --surface: #282828;
  --surface-2: #32373c;
  --surface-3: #3a3f44;
  --border: #4E5456;
  --text: #ebebeb;
  --text-muted: #b0b3b5;
  --primary: #f59e0b;
  --primary-hover: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 6px 16px rgba(0,0,0,.45);
}

*,*::before,*::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  display: grid; grid-template-rows: var(--topbar-h) 1fr var(--bottombar-h);
  height: 100vh; overflow: hidden;
}
button { font-family: inherit; font-size: inherit; color: inherit; }
input, textarea, select { font-family: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 38px; width: auto; display: block; }
.brand h1 {
  margin: 0; font-size: 16px; font-weight: 500;
  letter-spacing: -.01em; color: var(--text);
}
.brand-tag {
  margin-left: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500; color: var(--primary);
  background: rgba(245,158,11,.10); border: 1px solid rgba(245,158,11,.4);
  text-transform: uppercase; letter-spacing: .04em;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-pill {
  font-size: 11px; color: var(--text-muted); padding: 4px 10px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  user-select: none; white-space: nowrap; font-size: 13px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-icon { padding: 6px 9px; }
.btn svg { width: 16px; height: 16px; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon svg { width: 18px; height: 18px; }
.theme-icon { display: none; }
[data-theme="light"] .theme-icon-moon { display: inline-block; }
[data-theme="dark"]  .theme-icon-sun  { display: inline-block; }

/* ---------- Main ---------- */
.main {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 88%, var(--primary) 12%) 100%);
}

/* ---------- Dropzone ---------- */
.dropzone {
  position: absolute; inset: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color .15s, background .15s;
}
.dropzone[hidden] { display: none; }
.dropzone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
}
.dz-inner { text-align: center; max-width: 520px; padding: 32px; }
.dz-icon { width: 64px; height: 64px; stroke: var(--text-muted); margin: 0 auto 12px; display: block; }
.dropzone h2 { margin: 0 0 8px; font-size: 22px; font-weight: 500; }
.dropzone p { margin: 4px 0 16px; color: var(--text-muted); }
.dropzone .hint { font-size: 12px; opacity: .7; margin-top: 18px; }

.dz-controls {
  display: flex; gap: 12px; align-items: flex-end; justify-content: center;
  flex-wrap: wrap; margin: 14px 0 8px;
}
.parser-select { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.parser-select .lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.parser-select select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 13px; min-width: 220px;
}
.parser-select select:focus { outline: none; border-color: var(--primary); }

/* ---------- Result ---------- */
.result { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.result[hidden] { display: none; }

/* ---------- KI-Banner ---------- */
.ai-banner {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px; background: rgba(245,158,11,.10);
  border-bottom: 1px solid rgba(245,158,11,.35);
  flex-wrap: wrap;
}
.ai-banner[hidden] { display: none; }
.ai-banner-text { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 2px; }
.ai-banner-text strong { font-size: 13px; color: var(--primary); }
.ai-banner-text span { font-size: 12px; color: var(--text-muted); }
.ai-banner-actions { display: flex; gap: 8px; }
.ai-warnings {
  margin: 6px 0 0; padding: 0 0 0 18px;
  font-size: 12px; color: var(--err);
  list-style: disc;
}
.ai-warnings[hidden] { display: none; }
.ai-warnings li { margin-top: 2px; }

.info-bar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 18px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.info-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.info-block .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.info-block strong { font-size: 13px; font-weight: 500; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-block.stats .lbl { margin-bottom: 2px; }
.stats-row { display: flex; gap: 8px; }
.stat {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.stat b { font-weight: 600; }
.stat.ok   b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.err  b { color: var(--err); }
.info-spacer { flex: 1; }

/* ---------- Table ---------- */
.table-wrap { flex: 1; overflow: auto; background: var(--surface); }
.positions-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.positions-table th, .positions-table td {
  padding: 5px 8px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: middle;
}
.positions-table thead th {
  position: sticky; top: 0; background: var(--surface-3);
  font-weight: 500; color: var(--text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  z-index: 2; border-bottom: 2px solid var(--border);
}
.positions-table tbody tr:hover { background: var(--surface-3); }
.positions-table tbody tr.has-error   { background: var(--err-bg); }
.positions-table tbody tr.has-warning { background: var(--warn-bg); }
.positions-table tbody tr.is-ignored td:not(.col-ignore) { opacity: 0.4; text-decoration: line-through; }

.positions-table .col-row    { width: 36px; color: var(--text-muted); text-align: right; }
.positions-table .col-page   { width: 36px; color: var(--text-muted); text-align: center; }
.positions-table .col-ignore { width: 36px; text-align: center; }
.positions-table .col-issues { width: 220px; }
.positions-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Datei-Spalte: nur bei Multi-Upload (Tabelle .multi) sichtbar */
.positions-table .col-src {
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text-muted); font-size: 11px;
}
.positions-table:not(.multi) .col-src { display: none; }

.positions-table .cell {
  display: block; min-width: 50px; padding: 2px 4px;
  border-radius: 3px; cursor: text; outline: none;
}
.positions-table .cell:hover { background: var(--surface-2); }
.positions-table .cell:focus {
  background: var(--surface);
  outline: 2px solid var(--primary); outline-offset: -2px;
}
.positions-table .cell.empty-required {
  outline: 1px dashed var(--err); outline-offset: -1px; color: var(--err);
}
.positions-table .cell.warn-cell {
  background: var(--warn-bg); outline: 1px solid rgba(245,158,11,.4); outline-offset: -1px;
}

.issues-list { display: flex; flex-direction: column; gap: 2px; }
.issue {
  font-size: 11px; padding: 1px 6px; border-radius: 3px;
  display: inline-block; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.issue.error   { background: var(--err-bg);   color: var(--err); }
.issue.warning { background: var(--warn-bg);  color: var(--warn); }

/* ---------- Busy ---------- */
.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: rgba(245,245,245,0.85); backdrop-filter: blur(2px); z-index: 50;
}
.busy[hidden] { display: none; }
[data-theme="dark"] .busy { background: rgba(29,31,33,0.85); }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottombar ---------- */
.bottombar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--surface);
  border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted);
}
#serverStatus { color: var(--ok); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-md); font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .info-bar .info-block { min-width: 0; }
  .info-block strong { max-width: 140px; }
}

/* ---------- Dialog ---------- */
.dlg {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-md); padding: 0;
  width: min(560px, 92vw); max-height: 86vh;
  overflow: hidden;
}
.dlg::backdrop { background: rgba(15,23,42,.4); backdrop-filter: blur(2px); }
.dlg.dlg-large { width: min(900px, 96vw); }
.dlg-h {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-3);
}
.dlg-h h3 { margin: 0; font-size: 15px; font-weight: 500; }
.dlg-hint { font-size: 12px; color: var(--text-muted); flex: 1; }
.dlg-h .btn-icon { margin-left: auto; }
.dlg-body { padding: 16px 18px; overflow: auto; max-height: calc(86vh - 120px); display: flex; flex-direction: column; gap: 12px; }
.dlg-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-3);
}
.dlg-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.dlg-body .lbl { color: var(--text-muted); font-weight: 500; }
.dlg-body input, .dlg-body textarea, .dlg-body select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); font-size: 13px;
}
.dlg-body textarea { font-family: var(--mono); font-size: 11px; line-height: 1.4; min-height: 240px; }
.dlg-body input:focus, .dlg-body textarea:focus, .dlg-body select:focus { outline: none; border-color: var(--primary); }
.dlg-body .hint { font-size: 11px; color: var(--text-muted); margin: 2px 0 0; line-height: 1.4; }
.dlg-body code { font-family: var(--mono); font-size: 11px; padding: 1px 4px; background: var(--surface-2); border-radius: 3px; }

/* Bezeichnungen-Tabelle */
.lbl-head, .lbl-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; padding: 2px 0;
}
.lbl-head { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.lbl-default { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbl-input {
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); font-size: 13px; width: 100%;
}
.lbl-input:focus { outline: none; border-color: var(--primary); }

/* Mapping-Tabelle */
.map-selectors { display: flex; gap: 12px; }
.map-selectors label { flex: 1; }
.map-table { display: flex; flex-direction: column; gap: 6px; }
.map-head, .map-row {
  display: grid; grid-template-columns: 1fr 24px 1fr 32px; gap: 8px; align-items: center;
}
.map-head { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; padding: 0 2px; }
.map-row input {
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); font-size: 13px; width: 100%;
}
.map-row input:focus { outline: none; border-color: var(--primary); }
.map-arrow { text-align: center; color: var(--text-muted); }
.map-row .del { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 4px 8px; border-radius: 4px; font-size: 16px; }
.map-row .del:hover { color: var(--err); background: var(--surface-2); }
#mapAddRow { align-self: flex-start; margin-top: 4px; }

/* ZIP-Diagnose */
.zip-report-summary {
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--surface-2); border-radius: 6px;
  color: var(--text); font-size: 13px; line-height: 1.5;
}
.zip-report-summary strong { color: var(--text); }
.zip-report-table { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
.zip-report-head, .zip-report-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: baseline;
  padding: 6px 8px;
}
.zip-report-head { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.zip-report-row { font-size: 12px; border-bottom: 1px solid var(--border); }
.zip-report-row:last-child { border-bottom: none; }
.zip-report-row .fn { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); word-break: break-all; }
.zip-report-row .rn { color: var(--text-muted); }
.zip-report-row.err .rn { color: var(--err); }

/* Vorlagen-Liste */
.tpl-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.tpl-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.tpl-list .tpl-name { font-weight: 500; }
.tpl-list .tpl-mode { font-size: 11px; padding: 2px 8px; background: var(--surface-2); border-radius: 999px; color: var(--text-muted); }
.tpl-list .tpl-markers { font-size: 11px; color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-list .del { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.tpl-list .del:hover { color: var(--err); background: var(--surface-2); }
