/* ================================================================
   Data Extractor — Main Stylesheet
   Sidebar-first layout. Pure CSS, zero external dependencies.
   ================================================================ */

/* ── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg: #f1f5f9;
  --c-surface: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #1e293b;
  --c-text-muted: #64748b;
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-danger: #dc2626;
  --c-danger-hover: #b91c1c;
  --c-success: #16a34a;
  --c-success-hover: #15803d;
  --c-warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --sb-w: 240px;
  --sb-bg: #111827;
  --sb-text: rgba(255,255,255,.75);
  --sb-text-active: #ffffff;
  --sb-active-bg: rgba(255,255,255,.1);
  --sb-hover-bg: rgba(255,255,255,.06);
  --topbar-h: 48px;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── App Shell (Sidebar Layout) ─────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sb-w);
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}
.brand-icon { color: #60a5fa; flex-shrink: 0; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--sb-text);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.sidebar-close:hover { color: #fff; background: var(--sb-hover-bg); }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sb-hover-bg); color: var(--sb-text-active); }
.nav-item.active { background: var(--sb-active-bg); color: var(--sb-text-active); }
.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-details { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--sb-text); text-transform: capitalize; }

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--sb-text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-logout:hover { background: rgba(220,38,38,.15); color: #fca5a5; }

/* ── Main Wrapper ───────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sb-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
}

/* ── Desktop sidebar collapse ───────────────────────────────────── */
.sidebar-collapse-toggle {
  position: fixed;
  top: 14px;
  left: calc(var(--sb-w) - 14px);
  z-index: 250;
  width: 28px; height: 28px;
  display: none;              /* shown on desktop only (below) */
  align-items: center; justify-content: center;
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  color: #475569;
  cursor: pointer;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.08));
  transition: left .25s ease;
}
.sidebar-collapse-toggle:hover { color: var(--c-primary); }

@media (min-width: 901px) {
  .sidebar-collapse-toggle { display: flex; }
  .app-shell.sidebar-collapsed .sidebar { transform: translateX(-100%); }
  .app-shell.sidebar-collapsed .main-wrapper { margin-left: 0; }
  .app-shell.sidebar-collapsed .sidebar-collapse-toggle { left: 12px; }
}

/* ── Mobile Top Bar ─────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--sb-bg);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.hamburger {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
}
.hamburger:hover { color: #fff; background: var(--sb-hover-bg); }

.mobile-title { color: #fff; font-weight: 700; font-size: 15px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190;
}
.sidebar-overlay.active { display: block; }

/* ── Page Content ───────────────────────────────────────────────── */
.page-content {
  padding: 24px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
}

/* Review page: full width, no max-width constraint */
body.review-page .page-content {
  max-width: none;
  padding: 20px 24px;
}

/* ── Footer ─────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--c-text-muted);
  font-size: 12px;
  border-top: 1px solid var(--c-border);
}

/* ── Page Header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-header-left h1, .page-header h1 { font-size: 22px; font-weight: 700; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex-shrink: 0; }
/* legacy alias */
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex-shrink: 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--c-text-muted);
}
.breadcrumb a { color: var(--c-primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb svg { color: var(--c-text-muted); }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
}
.card-title { font-size: 15px; font-weight: 700; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  border: 1px solid transparent;
  font-size: 14px;
  padding: 8px 16px;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-hover); }

.btn-secondary { background: #f1f5f9; color: #334155; border-color: var(--c-border); }
.btn-secondary:hover { background: #e2e8f0; }

.btn-ghost { background: none; color: var(--c-text-muted); border: none; padding: 4px 8px; }
.btn-ghost:hover { color: var(--c-text); background: rgba(0,0,0,.05); }

.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--c-danger-hover); }

.btn-success { background: var(--c-success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--c-success-hover); }

.btn-sm { font-size: 12px; padding: 4px 10px; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #334155; }
.form-control,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  transition: border-color .15s;
}
.form-control:focus,
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.form-action { display: flex; align-items: flex-end; }

.field-type { font-weight: 400; color: var(--c-text-muted); }
.required { color: var(--c-danger); }
.hint { font-size: 12px; color: var(--c-text-muted); margin-bottom: 8px; }

/* ── Table ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--c-border); color: #334155; }
.table td { padding: 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table tr:hover td { background: #fafbfc; }
.actions { display: flex; gap: 6px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-select-cell { text-align: center; }
.row-select-cell input, #select-all { cursor: pointer; width: 15px; height: 15px; }

/* Inline button spinner (shown via htmx-indicator while a request is in flight) */
.btn-spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
.htmx-indicator.btn-spinner { display: none; }
.htmx-request .htmx-indicator.btn-spinner,
.htmx-request.htmx-indicator.btn-spinner { display: inline-block; }
button.htmx-request { opacity: .75; cursor: progress; }

/* Series candidate key */
.series-key { font-size: 11px; line-height: 1.6; word-break: break-word; color: var(--c-text-muted, #64748b); }
.series-key-sep { color: #cbd5e1; margin: 0 3px; }
.series-seg { padding: 0 1px; }

/* This series holds a DIFFERENT value than we extracted — the signal the choice
   between siblings actually turns on, so it is shown, not blanked. Matches are
   deliberately NOT coloured: highlighting every agreeing field buried the few
   that differ, and a match the scorer withheld looked like a broken highlight. */
.series-seg-diff { color: #b45309; }
/* The series has no value for this field at all. */
.series-seg-absent { color: #cbd5e1; }

/* Series candidate comparison grid — extraction on top, candidates below.
   Plain = agrees with your extraction; amber = differs; "—" = the series has no
   such field. Blue marks the row the AI (or the deterministic gate) picked. */
.series-compare-wrap { overflow-x: auto; margin: 4px 0 2px; }
.series-compare { border-collapse: collapse; font-size: 11px; width: 100%; }
.series-compare th, .series-compare td { padding: 3px 6px; text-align: left; white-space: nowrap; border-bottom: 1px solid #f1f5f9; }
.series-compare th { font-weight: 600; color: #64748b; text-transform: capitalize; }
.series-extracted-row td { background: #f8fafc; font-weight: 600; color: #334155; }
.series-rowlabel { color: #64748b; }
.series-cand-row:hover td { background: #f8fafc; }
.series-cand-row.is-selected td { background: #eff6ff; }
.series-cell { display: block; cursor: pointer; }
/* The picker's reasoning, so a human can audit the machine's judgement. */
.series-ai-reason {
  font-size: 12px; line-height: 1.45; color: #334155;
  background: #f0f7ff; border-left: 3px solid #60a5fa;
  border-radius: 0 4px 4px 0; padding: 6px 10px; margin: 6px 0 2px;
}
.series-ai-reason strong { color: #1e40af; }
.series-pick, .series-score { text-align: center; }
.series-score label { cursor: pointer; font-weight: 600; }
/* The full key wraps rather than being truncated — its trailing note sections
   ('+Härteprotokoll') appear in no other column. */
.series-compare td:last-child { white-space: normal; max-width: 300px; }
.series-key-full { font-size: 10.5px; color: #94a3b8; cursor: pointer; word-break: break-word; }
/* Column headers: which field can't discriminate, and which we failed to read. */
.series-col-shared, .series-col-unread { color: #94a3b8; font-weight: 500; }
.series-col-tag {
  font-size: 9px; text-transform: uppercase; letter-spacing: .04em;
  color: #94a3b8; background: #f1f5f9; border-radius: 3px; padding: 1px 3px;
}
/* Marks the row 'Auto' would send — the series matched by the gate or picked by
   the AI, which otherwise looked identical to the alternatives. */
.series-cand-row.is-autopick td { background: #f0f9ff; }
.series-cand-row.is-autopick td:first-child { box-shadow: inset 3px 0 0 #38bdf8; }
.series-pick-badge {
  display: inline-block; margin-left: 4px; font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: #0369a1; background: #e0f2fe; border-radius: 3px; padding: 1px 4px;
}

/* Full-width series section (moved out of the cramped review right column) */
.series-section .card-header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.series-position { border-top: 1px solid var(--c-border); padding: 12px 0; }
.series-position:first-of-type { border-top: none; }
.series-position-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.series-actions { border-top: 1px solid var(--c-border); margin-top: 12px; padding-top: 14px; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.badge-uploaded { background: #f1f5f9; color: #475569; }
.badge-processing { background: #fef3c7; color: #92400e; animation: pulse 1.5s infinite; }
.badge-extracted { background: #dbeafe; color: #1e40af; }
.badge-validated { background: #dcfce7; color: #166534; }
.badge-corrected { background: #e0e7ff; color: #3730a3; }
.badge-verified { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-error { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f1f5f9; color: #475569; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

/* ── Stats Grid ─────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.stat-card-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  background: #eff6ff;
  color: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card > div { display: flex; flex-direction: column; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--c-text); line-height: 1; }
.stat-label { font-size: 13px; color: var(--c-text-muted); margin-top: 2px; }
.stat-link { font-size: 12px; color: var(--c-primary); text-decoration: none; margin-top: 4px; }
.stat-link:hover { text-decoration: underline; }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Login Page ─────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--c-text);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}
.login-logo svg { color: var(--c-primary); }
.login-subtitle {
  text-align: center;
  color: var(--c-text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}
.login-card h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; color: var(--c-text-muted); font-size: 14px; margin-bottom: 24px; }

/* ── Review Layout (two-column) ─────────────────────────────────── */
.review-layout {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1024px) {
  .review-layout { grid-template-columns: 1fr; }
}

.doc-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.meta-item { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--c-text-muted); }

/* ── Document Viewer ────────────────────────────────────────────── */
.doc-viewer {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky;
  top: 16px;
  box-shadow: var(--shadow);
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  flex-wrap: wrap;
}

.viewer-info { font-size: 13px; color: var(--c-text-muted); }
.viewer-zoom { font-size: 13px; color: var(--c-text-muted); min-width: 40px; text-align: center; }

.sep {
  width: 1px;
  height: 20px;
  background: var(--c-border);
  flex-shrink: 0;
}

.doc-viewer-canvas {
  max-height: calc(100vh - 180px);
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 12px;
  background: #525659;
}

#pdf-canvas { max-width: 100%; }
#review-image { max-width: 100%; height: auto; display: block; user-select: none; }

.raw-text-viewer {
  padding: 16px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  background: #f8fafc;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ── Review Form ────────────────────────────────────────────────── */
.review-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field-group {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.field-group legend {
  font-weight: 700;
  font-size: 14px;
  padding: 0 6px;
  color: var(--c-primary);
}
.entry-sep { border: none; border-top: 1px dashed var(--c-border); margin: 12px 0; }

.form-actions { display: flex; align-items: center; gap: 12px; }
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--c-surface);
  padding: 12px 0;
  border-top: 1px solid var(--c-border);
  z-index: 10;
}
.save-status { font-size: 13px; color: var(--c-text-muted); }
.field-validation { font-size: 11px; color: var(--c-danger); min-height: 14px; }


/* ── Schema Editor ──────────────────────────────────────────────── */

/* Toolbar above groups */
.se-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.se-group-picker {
  display: flex;
  gap: 6px;
  align-items: center;
}
.se-group-picker select { min-width: 220px; font-size: 13px; padding: 6px 8px; border: 1px solid var(--c-border); border-radius: 6px; }

/* Save bar */
.se-save-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--c-border);
}

/* ── Schema import panel ─────────────────────────────────────────────── */
.se-import-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text);
  width: 100%;
  text-align: left;
}
.se-import-toggle:hover { color: var(--c-primary); }
.se-import-chevron { margin-left: auto; transition: transform .2s; }
.se-import-body { padding: 0 16px 16px; }
.se-import-drop {
  border: 2px dashed var(--c-border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
  cursor: default;
}
.se-import-drop.se-import-active,
.se-import-drop:hover {
  border-color: var(--c-primary);
  background: #eff6ff;
}
.se-import-preview-table {
  border-radius: var(--radius);
  overflow: auto;
  max-height: 320px;
  border: 1px solid var(--c-border);
}
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; }
.alert-info  { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* Group card */
.se-group-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, opacity .15s;
}
.se-group-card.se-dragging { opacity: .45; box-shadow: var(--shadow-md); }
.se-group-card.se-drag-over { border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(37,99,235,.2); }

.se-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-border);
  background: #f8fafc;
  border-radius: var(--radius) var(--radius) 0 0;
}

.se-drag-handle {
  color: var(--c-text-muted);
  cursor: grab;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.se-drag-handle:hover { background: var(--c-border); color: var(--c-text); }
.se-drag-handle:active { cursor: grabbing; }

.se-group-name-wrap {
  flex: 1;
  display: flex;
  gap: 10px;
  min-width: 0;
}
.sg-name {
  font-weight: 700;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  background: transparent;
  min-width: 120px;
  max-width: 200px;
  transition: border-color .15s;
}
.sg-name:hover, .sg-name:focus { border-color: var(--c-border); background: #fff; outline: none; }
.sg-desc {
  flex: 1;
  font-size: 13px;
  color: var(--c-text-muted);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  background: transparent;
  transition: border-color .15s;
}
.sg-desc:hover, .sg-desc:focus { border-color: var(--c-border); background: #fff; outline: none; }

.se-group-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Group body */
.se-group-body { padding: 10px 14px 12px; }

/* Field column headers */
.sef-headers {
  display: grid;
  grid-template-columns: 24px 1fr 90px 1fr 40px 32px;
  gap: 8px;
  padding: 0 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Field row */
.sef-row {
  display: grid;
  grid-template-columns: 24px 1fr 90px 1fr 40px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  border-radius: 6px;
  transition: background .1s, opacity .15s;
}
.sef-row:hover { background: rgba(0,0,0,.02); }
.sef-row.se-dragging { opacity: .4; }
.sef-row.se-drag-over { box-shadow: 0 -2px 0 var(--c-primary); }

.sef-row input[type="text"],
.sef-row select {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 13px;
  background: #fff;
  transition: border-color .15s;
}
.sef-row input[type="text"]:focus,
.sef-row select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }

/* Field name cell with picker */
.sef-name-cell { min-width: 0; }
.se-field-picker { display: flex; gap: 5px; align-items: center; }
.se-field-picker select { flex: 1; min-width: 0; font-size: 12px; }

/* Add-field bar */
.se-add-field-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--c-border);
  flex-wrap: wrap;
}
.se-add-field-bar .se-field-picker select { min-width: 200px; font-size: 13px; padding: 5px 7px; border: 1px solid var(--c-border); border-radius: 6px; }

/* Chevron rotation */
.sg-chevron { transition: transform .2s; }

/* Legacy — keep for backward compat if any page still uses these */
.schema-field-row {
  display: grid;
  grid-template-columns: 140px 140px 100px 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.schema-field-row input, .schema-field-row select {
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
}
.checkbox-label { font-size: 12px; display: flex; align-items: center; gap: 4px; white-space: nowrap; }

/* ── Processing Indicator ───────────────────────────────────────── */
.processing-indicator { text-align: center; padding: 40px; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Correction History ─────────────────────────────────────────── */
.error-log { font-size: 12px; background: #fef2f2; padding: 10px; border-radius: 4px; overflow-x: auto; white-space: pre-wrap; }

/* ── Upload Form ────────────────────────────────────────────────── */
.upload-form .form-row { align-items: flex-end; }

/* ── Upload Drop Zone ───────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--c-border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-zone:hover,
.upload-zone-active {
  border-color: var(--c-primary);
  background: rgba(37,99,235,.04);
}
.upload-zone-content p { font-size: 13px; color: var(--c-text-muted); margin: 4px 0; }
.upload-icon { font-size: 28px; display: block; margin-bottom: 4px; }
.upload-buttons { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }

/* ── Progress Bar ───────────────────────────────────────────────── */
.progress-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--c-border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--c-primary);
  border-radius: 4px;
  transition: width .3s ease;
}
.progress-detail {
  font-size: 12px;
  color: var(--c-text-muted);
  margin-top: 4px;
}

/* ── Empty State ────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 32px; color: var(--c-text-muted); font-size: 14px; }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; line-height: 1; }

/* ── Utilities ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--c-text-muted); }
.text-success { color: var(--c-success); }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.source-pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 420px;
  overflow-y: auto;
  background: #f8fafc;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  margin-top: 8px;
  border: 1px solid var(--c-border);
}
.save-status { font-size: 13px; color: var(--c-text-muted); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .sidebar-close { display: flex; }
  .main-wrapper { margin-left: 0; }
  .mobile-topbar { display: flex; }
  .page-content { padding: 16px; }
  body.review-page .page-content { padding: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .schema-field-row { grid-template-columns: 1fr 1fr; }
  .sef-row { grid-template-columns: 24px 1fr 80px 32px; }
  .sef-row .f-desc, .sef-row .checkbox-label { display: none; }
  .sef-headers { display: none; }
  .se-group-name-wrap { flex-direction: column; gap: 4px; }
  .sg-name { max-width: 100%; }
  .page-header { flex-direction: column; }
  .page-header-actions { width: 100%; }
}

/* ── Language switch (sidebar) ───────────────────────────────────────────────
   Interface language only; it has no effect on extracted data or on the order
   body sent to the ERP. */
.sidebar-lang {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  margin-top: auto;
}
.sidebar-lang .lang-option {
  flex: 0 0 auto;
  min-width: 34px;
  padding: 3px 8px;
  border: 1px solid var(--border, #d8dce3);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-align: center;
  text-decoration: none;
  color: var(--text-muted, #6b7280);
  background: transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.sidebar-lang .lang-option:hover {
  color: var(--text, #1f2937);
  border-color: var(--text-muted, #9aa1ab);
}
.sidebar-lang .lang-option.active {
  color: #fff;
  background: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
}

/* ── Layout tolerance for longer translations ────────────────────────────────
   German runs 7-15 characters longer than English on exactly the strings that
   sit in fixed-width controls ("Upload & Extract" -> "Hochladen & Extrahieren",
   "Uploaded" -> "Hochgeladen"). These rules let text set the width instead of
   the reverse, so a locale change cannot break the layout. */

/* Buttons: never squash or clip a label; let the button grow instead. */
.btn,
.btn-primary,
.btn-logout {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Toolbars and form rows wrap rather than overflow once labels get longer. */
.form-row,
.toolbar,
.page-actions,
.card-actions {
  flex-wrap: wrap;
}

/* Table headers: allow two lines rather than forcing a wide column. */
table th {
  white-space: normal;
  hyphens: auto;
  overflow-wrap: break-word;
}

/* Sidebar nav labels: German compounds ("Serienzuordnung") are long; ellipsis
   beats pushing the sidebar wider or wrapping onto two lines. */
.nav-item span,
.sidebar-brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Stat tiles size to content so a longer caption cannot clip the number. */
.stat-card,
.stat-tile {
  min-width: 0;
}
.stat-card .stat-label,
.stat-tile .stat-label {
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Series section waiting for the matcher. Series matching runs after the
   document becomes reviewable, so this is what a reviewer who opened the page
   early sees until the grid arrives on its own. */
.series-pending {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
}
.series-pending .btn-spinner {
  display: inline-block;      /* htmx-indicator rules hide it otherwise */
  opacity: 1;
}
