:root {
  --border: #e2e5eb;
  --border-strong: #c7ccd6;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --primary: #3457d5;
  --primary-dark: #2a44ab;
  --primary-soft: #eaefff;
  --success: #1f9d55;
  --success-soft: #e4f8ec;
  --warning-soft: #fff4d6;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --text: #1a2233;
  --muted: #6b7280;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { display: flex; align-items: center; text-decoration: none; }
.topbar .brand img { height: 24px; width: auto; display: block; }
.topbar nav a {
  margin-left: 18px; text-decoration: none; color: var(--muted); font-weight: 500;
  padding: 6px 4px; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
}
.topbar nav a:hover { color: var(--primary); border-color: var(--primary); }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.muted { color: var(--muted); font-size: 0.9em; }
h1, h2, h3, h4 { letter-spacing: -0.01em; }
h1 { font-size: 1.5em; margin: 0 0 4px; }
h2 { font-size: 1.1em; margin-top: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88em; color: var(--muted); font-weight: 500; }
.form-grid .full { grid-column: 1 / -1; }
.form-inline { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }

input, select, textarea, button {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
button {
  cursor: pointer; font-weight: 500; transition: background .15s, border-color .15s, transform .05s;
}
button:hover { background: #f2f4f8; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c2; }
.btn-danger:hover { background: #fbdedb; }
.btn-link {
  text-decoration: none; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 7px;
  color: var(--primary); font-weight: 500; transition: background .15s;
}
.btn-link:hover { background: var(--primary-soft); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }

.alert { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 500; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f5c6c2; }

.project-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.project-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.project-actions form { display: inline-flex; align-items: center; gap: 6px; }
.inline-check { display: inline-flex; align-items: center; gap: 5px; font-size: 0.85em; font-weight: 500; color: var(--muted); }
.update-source summary { cursor: pointer; color: var(--primary); font-weight: 500; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 7px; }
.update-source form { display: flex; gap: 6px; margin-top: 8px; }

/* ---------------------------------------------------------------- */
/* Statusleiste                                                      */
/* ---------------------------------------------------------------- */
.status-bar {
  display: flex; align-items: center; gap: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px;
  margin-bottom: 18px; box-shadow: var(--shadow); position: sticky; top: 60px; z-index: 10;
}
.status-bar .status-counts { font-weight: 600; white-space: nowrap; font-size: 0.95em; }
.status-bar .status-counts strong { color: var(--primary); }
.status-bar .status-percent { color: var(--muted); font-size: 0.9em; white-space: nowrap; }
.status-bar-track {
  flex: 1; height: 10px; background: #eceff3; border-radius: 999px; overflow: hidden;
}
.status-bar-fill {
  height: 100%; background: linear-gradient(90deg, #3457d5, #1f9d55); border-radius: 999px;
  transition: width .3s ease;
}

/* ---------------------------------------------------------------- */
/* Editor-Layout                                                     */
/* ---------------------------------------------------------------- */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }

.segment-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.pagination { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 0.9em; }
.pagination a { color: var(--primary); text-decoration: none; font-weight: 500; }
.pagination a:hover { text-decoration: underline; }

.segment-table { table-layout: fixed; }
.segment-table col.col-num { width: 44px; }
.segment-table col.col-source { width: 42%; }
.segment-table col.col-target { width: 42%; }
.segment-table col.col-status { width: 130px; }
.segment-table td.src-cell, .segment-table td.tgt-cell {
  white-space: normal; word-break: break-word; overflow-wrap: break-word; line-height: 1.45;
}
.segment-row { cursor: pointer; transition: background .1s; }
.segment-row:hover { background: #f5f7fb; }
.segment-row.selected { background: var(--primary-soft); }
.segment-row.selected td { border-bottom-color: #c9d5fb; }

.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72em;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; background: #eee; color: var(--muted);
}
.status-approved { background: var(--success-soft); color: var(--success); }
.status-translated, .status-ai_translated { background: var(--warning-soft); color: #9a6b00; }
.status-copied { background: var(--primary-soft); color: var(--primary); }
.status-new { background: #f1f1f1; color: var(--muted); }
.status-cell { display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- */
/* Inspector                                                          */
/* ---------------------------------------------------------------- */
.inspector {
  position: sticky; top: 130px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  max-height: calc(100vh - 150px); overflow-y: auto;
}
.inspector h3 { margin-top: 0; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.inspector h3 #insp-order { color: var(--muted); font-weight: 500; font-size: 0.85em; }
.inspector label { display: block; margin-top: 12px; margin-bottom: 4px; font-size: 0.82em; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.source-box { padding: 10px 12px; background: #f5f6f8; border-radius: 8px; min-height: 40px; white-space: pre-wrap; line-height: 1.5; border: 1px solid var(--border); }
#insp-target { width: 100%; margin-top: 2px; line-height: 1.5; resize: vertical; }
.inspector-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.inspector-row .inline-check { font-size: 0.95em; text-transform: none; color: var(--text); font-weight: 500; }
#save-indicator { transition: opacity .2s; }
.inspector-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.inspector-actions button { flex: 1 1 auto; font-size: 0.88em; padding: 8px 10px; }
.inspector h4 { margin-bottom: 6px; margin-top: 16px; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.02em; color: var(--muted); }

.tm-suggestion {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px;
  cursor: pointer; transition: background .1s, border-color .1s; font-size: 0.92em;
}
.tm-suggestion:hover { background: var(--primary-soft); border-color: #c9d5fb; }
.tm-score { float: right; color: var(--muted); font-size: 0.85em; font-weight: 600; }

.qa-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.qa-badge { padding: 10px 14px; border-radius: var(--radius); background: var(--success-soft); color: var(--success); font-weight: 600; box-shadow: var(--shadow); }
.qa-badge.has-issues { background: var(--danger-soft); color: var(--danger); }

code { background: #f1f1f1; padding: 2px 6px; border-radius: 5px; font-size: 0.92em; }

/* ---------------------------------------------------------------- */
/* Segmentsuche                                                       */
/* ---------------------------------------------------------------- */
.segment-search { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.segment-search input[type="text"] { flex: 1 1 auto; }
.search-results {
  border: 1px solid var(--border); border-radius: var(--radius); background: #fbfcfe;
  margin-bottom: 12px; max-height: 260px; overflow-y: auto; padding: 6px;
}
.search-results-header { padding: 4px 6px 6px; }
.search-result-item {
  display: grid; grid-template-columns: 44px 1fr 1fr; gap: 8px; padding: 6px 6px;
  border-radius: 6px; cursor: pointer; font-size: 0.9em; align-items: start;
}
.search-result-item:hover { background: var(--primary-soft); }
.search-result-num { color: var(--muted); font-weight: 600; }
.search-result-src, .search-result-tgt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-tgt { color: var(--muted); }

/* ---------------------------------------------------------------- */
/* Bestehende Projekte: Bulk-Aktionen + Mini-Statusbalken             */
/* ---------------------------------------------------------------- */
.bulk-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.bulk-divider { width: 1px; height: 22px; background: var(--border-strong); margin: 0 4px; }
.bulk-hint { margin-left: auto; }
.btn-link-inline {
  background: var(--primary-soft); color: var(--primary); border-color: #c9d5fb; font-weight: 600;
}
.btn-link-inline:hover { background: #dde6ff; }
.project-checkbox { width: 16px; height: 16px; }

.status-mini { font-weight: 600; font-size: 0.9em; white-space: nowrap; }
.status-mini-track { width: 90px; height: 6px; background: #eceff3; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.status-mini-fill { height: 100%; background: linear-gradient(90deg, #3457d5, #1f9d55); border-radius: 999px; }

/* ---------------------------------------------------------------- */
/* Analyse                                                             */
/* ---------------------------------------------------------------- */
.analysis-totals-row td { border-top: 2px solid var(--border-strong); background: #fafbfd; }

@media (max-width: 1100px) {
  .editor-layout { grid-template-columns: 1fr; }
  .inspector { position: static; max-height: none; }
}

/* ---------------------------------------------------------------- */
/* Translation-Memory-Verwaltung (Übersicht/Detail/Bearbeiten)        */
/* ---------------------------------------------------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.breadcrumb { color: var(--muted); font-size: 0.85em; margin: 0 0 10px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }

.badge {
  display: inline-block; padding: 2px 8px; margin: 0 4px 4px 0; border-radius: 6px;
  background: var(--primary-soft); color: var(--primary-dark); font-size: 0.82em; font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.badge-muted { background: #eef0f4; color: var(--muted); }

.tm-toolbar { padding: 14px 16px; }
.tm-table td, .tm-table th { padding: 12px 14px; }
.tm-table tbody tr:hover { background: #fafbfd; }
.tm-link { color: var(--text); font-weight: 600; text-decoration: none; }
.tm-link:hover { color: var(--primary); text-decoration: underline; }

.detail-kv {
  display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 16px 24px;
}
.detail-kv > div span.muted { display: block; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.detail-kv-full { grid-column: 1 / -1; }
@media (max-width: 900px) { .detail-kv { grid-template-columns: repeat(2, 1fr); } }

.tm-form { display: flex; flex-direction: column; gap: 18px; max-width: 720px; }
.tm-form-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9em; }
.tm-form-field input[type="text"], .tm-form-field select { width: 100%; }
.tm-form-actions { display: flex; gap: 10px; align-items: center; }

.dual-list { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.dual-list-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.dual-list-label { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
.dual-list-search { padding: 6px 8px; font-size: 0.85em; }
.dual-list select { min-width: 0; font-size: 0.88em; }
.dual-list-buttons { display: flex; flex-direction: column; gap: 6px; }
.dual-list-buttons button { padding: 6px 10px; font-size: 1.1em; line-height: 1; }
@media (max-width: 700px) { .dual-list { grid-template-columns: 1fr; } .dual-list-buttons { flex-direction: row; justify-content: center; } }

.tag-pill-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark); font-size: 0.85em; font-weight: 600; cursor: pointer;
}
.tag-pill input { margin: 0; }

/* Modal-Popups (Import/Export), auf Basis von <dialog> */
dialog.modal {
  border: none; border-radius: var(--radius); padding: 0; box-shadow: 0 12px 32px rgba(16, 24, 40, 0.18);
  width: min(480px, 92vw);
}
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
dialog.modal .modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
dialog.modal .modal-header h3 { margin: 0; font-size: 1.05em; }
dialog.modal .modal-close { background: none; border: none; font-size: 1.3em; line-height: 1; padding: 2px 6px; color: var(--muted); }
dialog.modal .modal-close:hover { color: var(--text); background: none; }
dialog.modal .modal-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
dialog.modal .modal-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9em; }
dialog.modal .modal-field select, dialog.modal .modal-field input[type="file"], dialog.modal .modal-field input[type="text"] { width: 100%; }
dialog.modal .modal-field span { font-weight: 600; }

.term-quickadd { margin-top: 8px; }
.term-quickadd-preview { margin-bottom: 6px; font-size: 0.85em; }
.term-quickadd-message { font-size: 0.9em; padding: 8px 10px; border-radius: 7px; }
.term-quickadd-message.success { background: var(--success-soft); color: var(--success); }
.term-quickadd-message.warning { background: var(--warning-soft); color: var(--text); }
.term-quickadd-message.error { background: var(--danger-soft); color: var(--danger); }
dialog.modal .modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: #fafbfd; border-radius: 0 0 var(--radius) var(--radius); }

/* ---------------------------------------------------------------- */
/* TM-Konkordanzsuche (Detailseite)                                    */
/* ---------------------------------------------------------------- */
.tm-search-form { display: flex; flex-direction: column; gap: 10px; }
.tm-search-form textarea { width: 100%; resize: vertical; font-family: inherit; }
.tm-search-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tm-search-lang { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 0.9em; color: var(--muted); }

.tm-search-table th, .tm-search-table td { white-space: nowrap; }
.tm-search-table td.tm-cell-td { white-space: normal; min-width: 160px; max-width: 320px; }
.tm-cell-form { margin: 0; }
.tm-cell-text { display: block; cursor: text; padding: 2px 0; min-height: 1.2em; }
.tm-cell-text:hover { background: var(--primary-soft); border-radius: 4px; }
.tm-cell-input { display: none; width: 100%; padding: 4px 6px; font-size: 0.9em; }
mark { background: #fff1a8; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------------------------------------------------------------- */
/* CAT-Tags in Source/Target (Formatierung, Querverweis, Anker)       */
/* ---------------------------------------------------------------- */
.inspector label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.target-box {
  width: 100%; margin-top: 2px; line-height: 1.5; min-height: 96px; max-height: 260px; overflow-y: auto;
  padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff;
  white-space: pre-wrap; font: inherit;
}
.target-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.cat-tag {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: 1.3em; padding: 0 4px; margin: 0 1px; border-radius: 4px;
  font-size: 0.72em; font-weight: 700; line-height: 1.5; text-align: center; vertical-align: text-top;
  cursor: pointer; user-select: none; color: #fff;
}
.cat-tag svg { display: block; flex-shrink: 0; }
.cat-tag-num { line-height: 1; }
.cat-tag-span { border-radius: 3px; padding: 0 1px; }

/* Zeichenformatierung (fmt) - violett */
.cat-tag-fmt { background: #7c5cff; }
.cat-tag-span-fmt { background: rgba(124, 92, 255, 0.12); }

/* Querverweis (xref) - türkis */
.cat-tag-xref { background: #0ea5a0; }
.cat-tag-span-xref { background: rgba(14, 165, 160, 0.12); }

/* Anker / verankertes Objekt (anchor) - blau, Bild-Icon + Nummer, kein umschlossener Text */
.cat-tag-anchor { background: #2f6fed; padding: 0 5px; }

/* Automatischer Querverweis/TOC-Eintrag (ref) - bernstein, Ketten-Icon + Nummer,
   kein umschlossener Text (von InDesign generiert, nie übersetzbar) */
.cat-tag-ref { background: #d97706; padding: 0 5px; }

.cat-tag[contenteditable="false"] { cursor: default; }
.source-box .cat-tag:hover { filter: brightness(1.12); }

.tag-toolbar { display: flex; align-items: center; gap: 8px; margin: 4px 0 2px; }
.btn-tag-insert { font-size: 0.8em; padding: 4px 10px; }
.btn-tag-insert:disabled { opacity: 0.5; cursor: default; }
.tag-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 0.75em; color: var(--muted); }
.tag-legend span { display: inline-flex; align-items: center; gap: 4px; }
.tag-legend .dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.tag-legend .dot-fmt { background: #7c5cff; }
.tag-legend .dot-xref { background: #0ea5a0; }
.tag-legend .dot-anchor { background: #2f6fed; }
.tag-legend .dot-ref { background: #d97706; }

/* Fortschrittsanzeige bei Apply TM (normale Formular-Navigation, kein AJAX -
   der Hinweis ist bis zum Laden der Folgeseite sichtbar). Sichtbarkeit wird
   NICHT über das hidden-Attribut/CSS-Kaskade geregelt (das kollidierte mit
   der eigenen display-Regel), sondern direkt per style.display in JS. */
.apply-tm-indicator { align-items: center; gap: 8px; font-size: 0.85em; color: var(--primary); font-weight: 600; }
.progress-bar-track {
  display: inline-block; width: 130px; height: 7px; background: #dfe3ea; border-radius: 4px;
  overflow: hidden; vertical-align: middle;
}
.progress-bar-fill {
  display: block; height: 100%; width: 0%; background: var(--primary); border-radius: 4px;
}

/* ---------------------------------------------------------------- */
/* Fuzzy-Match-Vergleich (Segmente mit Status "translated"): zeigt    */
/* Source des aktuellen Segments gegen Source des TM-Treffers, mit    */
/* gelb hervorgehobenen Unterschieden (Wort-Diff).                    */
/* ---------------------------------------------------------------- */
.fuzzy-compare { margin-bottom: 16px; padding: 10px 12px; background: #fffbea; border: 1px solid #f0dfa0; border-radius: 8px; }
.fuzzy-compare h4 { margin: 0 0 8px; }
.fuzzy-compare-label { display: block; font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 8px 0 3px; }
.fuzzy-compare-label:first-of-type { margin-top: 0; }
.fuzzy-compare-box { background: #fff; border: 1px solid var(--border-strong); border-radius: 6px; padding: 8px 10px; line-height: 1.5; }

/* Kompakte, eingerückte Detail-Tabelle für aufklappbare Analyse-Zeilen
   (Sprachaufschlüsselung je Projekt innerhalb einer gespeicherten Analyse). */
.analysis-detail-row td { border-bottom: 1px solid var(--border); padding: 4px 10px 12px; background: #fafbfd; }
.table-compact { background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.table-compact th, .table-compact td { padding: 6px 10px; font-size: 0.9em; }
.analysis-toggle { font-size: 0.85em; padding: 0; width: 20px; }

/* Geschütztes Leerzeichen (nbsp) sichtbar machen - nur in schreibgeschützten
   Text-Anzeigen (Source-Box, Grid-Vorschau, TM-Vorschläge, Suchergebnisse),
   nie im editierbaren Target (siehe project.js escapeHtmlWithNbspMarkers). */
.nbsp-marker {
  display: inline-block; background: #e5e9f0; color: var(--muted);
  border: 1px solid var(--border-strong); border-radius: 3px;
  font-size: 0.62em; font-weight: 700; letter-spacing: 0.01em;
  line-height: 1.5; padding: 0 3px; margin: 0 1px; vertical-align: text-top;
  cursor: help; user-select: none;
}
