/* Outfit lokal laden (eigene Datei-Benennung der v15-latin-Google-Webfonts-Variante) */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('fonts/woff2/outfit-v15-latin-300.woff2') format('woff2');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/woff2/outfit-v15-latin-regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/woff2/outfit-v15-latin-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/woff2/outfit-v15-latin-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/woff2/outfit-v15-latin-700.woff2') format('woff2');
}

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-subtle: #a8a29e;
  --accent: #0891b2;
  --accent-hover: #0e7490;
  --accent-soft: #ecfeff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 6px;
  --radius-sm: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--ui-font, 'Outfit'), sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

/* LAYOUT ---------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg, var(--surface));
  color: var(--sidebar-text, var(--text));
  border-right: 1px solid var(--sidebar-border, var(--border));
  padding: 24px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--sidebar-text, var(--text));
}

.sidebar-sub {
  font-size: 12px;
  color: var(--sidebar-text-muted, var(--text-muted));
  margin-bottom: 28px;
}

.sidebar-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-subtle, var(--text-subtle));
  margin: 20px 0 8px;
  font-weight: 500;
}

.sidebar nav a {
  display: block;
  padding: 8px 0;
  color: var(--sidebar-text, var(--text));
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: all 0.25s ease-in-out;
}
.sidebar nav a:hover {
  background: var(--sidebar-hover, #f5f5f4);
  color: var(--sidebar-hover-text, inherit);
  padding: 8px 10px;
}
.sidebar nav a.active {
  background: var(--sidebar-active, var(--accent-soft));
  color: var(--sidebar-active-text, var(--accent-hover));
  font-weight: 500;
  padding: 8px 10px;
}

/* Dokument-Zeile: Label (→ Liste) + "+"-Button (→ neu) */
.nav-doc {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 2px;
}
.sidebar nav .nav-doc a {
  margin-bottom: 0;
}
.sidebar nav .nav-doc a:first-child {
  flex: 1 1 auto;
  min-width: 0;
}
.sidebar nav .nav-doc-add {
  flex: 0 0 auto;
  width: 32px;
  padding: 8px 0;
  text-align: center;
  font-size: 16px;
  line-height: 1;
  color: var(--sidebar-text-subtle, var(--text-subtle));
}
.sidebar nav .nav-doc-add:hover {
  padding: 8px 0;
  background: var(--sidebar-hover, #f5f5f4);
  color: var(--sidebar-hover-text, inherit);
}

.sidebar-divider {
  margin-top: auto;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--sidebar-border, var(--border));
  margin-bottom: 0;
}

.sidebar-brand-logo {
  max-width: 100%;
  max-height: var(--sidebar-logo-height, 40px);
  object-fit: contain;
}

.sidebar-hint {
  font-size: 12px;
  color: var(--sidebar-text-muted, var(--text-muted));
  line-height: 1.55;
}
.sidebar-hint strong { color: var(--sidebar-text, var(--text)); }

.sidebar-meta {
  font-size: 11px;
  color: var(--sidebar-text-subtle, var(--text-subtle));
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--sidebar-border, var(--border));
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-meta a {
  color: var(--sidebar-text-subtle, var(--text-subtle));
  text-decoration: none;
}
.sidebar-meta a:hover { color: var(--sidebar-text, var(--text)); }

.main {
  padding: 28px 40px 80px;
  max-width: 1200px;
  width: 100%;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-head .sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 6px;
}
.back-link:hover { color: var(--accent); }

/* BUTTONS --------------------------------------------------------------- */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  height: 36px;
  padding: 0 14px;
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #f5f5f4; border-color: var(--text-muted); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: #f5f5f4; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-icon { padding: 0; width: 36px; justify-content: center; }
.btn-icon.btn-sm { width: 28px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* CARDS / FORMS --------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }

/* Kompakte Meta-Zeile im Rechnungs-Editor: 7 Spalten total (Absender = 2) */
.meta-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
  align-items: end;
}
.meta-row .field { margin-bottom: 0; }
@media (max-width: 1100px) {
  .meta-row { grid-template-columns: repeat(4, 1fr); }
  .meta-row .field:first-child { grid-column: span 4; }
}
@media (max-width: 640px) {
  .meta-row { grid-template-columns: repeat(2, 1fr); }
  .meta-row .field:first-child { grid-column: span 2; }
}

/* Zweispalter für Meta-Daten + Empfänger nebeneinander */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.two-col .card { margin-bottom: 0; }
@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr; gap: 0; }
  .two-col .card { margin-bottom: 20px; }
}

/* ============================================================
 * Editor-Shell mit rechter Arbeits-Rail (Status + Aktionen)
 * Verwendet auf den Einzel-Editoren (Rechnung / Angebot / Mahnung).
 * .main--wide hebt die Breitenbegrenzung an, damit die Rail in den
 * sonst leeren rechten Bereich rückt.
 * ============================================================ */
.main--wide { max-width: 1560px; }

.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  align-items: start;
}
.editor-main { min-width: 0; }

.editor-rail {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.editor-rail .card { margin-bottom: 0; }

/* Aktions-Buttons in der Rail: volle Breite, linksbündig, gruppiert */
.rail-actions { display: flex; flex-direction: column; gap: 8px; }
.rail-actions .btn { width: 100%; justify-content: flex-start; }
.rail-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 12px 0 2px;
}
.rail-group-label:first-child { margin-top: 0; }

@media (max-width: 1100px) {
  .editor-shell { grid-template-columns: 1fr; gap: 0; }
  .editor-rail { position: static; margin-bottom: 20px; }
  .editor-rail .card { margin-bottom: 20px; }
}

/* Locked col-config row (Gesamt-Spalte) */
.col-cfg-row.locked {
  opacity: 0.7;
  background: #f5f5f4;
  position: relative;
}
.col-cfg-row.locked input:not([data-f="label"]),
.col-cfg-row.locked select,
.col-cfg-row.locked .btn:disabled {
  cursor: not-allowed;
}
.col-cfg-locked {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 4px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.01em;
}

input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select {
  font-family: inherit;
  font-size: 13px;
  height: 36px;
  padding: 0 10px;
  line-height: 1.5;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
/* Select: eigener Pfeil, damit es identisch zu den Inputs aussieht */
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%2378716c' stroke-width='1.5' d='M1 1.5l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}
/* Native Date/Number UI-Elemente bändigen */
input[type=date]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.6;
}
/* Number-Spinner komplett entfernen */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}
textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  line-height: 1.5;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
  min-height: 60px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.12);
}

/* Auto-grow Textareas: Höhe wird per JS gesteuert, kein manuelles Resize */
textarea.auto-grow {
  resize: none;
  min-height: 38px;
  overflow-y: hidden;
}

.field { margin-bottom: 12px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

/* EXCEL-STYLE TABELLE --------------------------------------------------- */
.items-wrap { border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }

.items-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 12px;
  background: #fafaf9;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  gap: 12px;
  flex-wrap: wrap;
}

/* Info-Icon neben "Positionen"-Header für Excel-Paste-Hinweis */
.card-head h2 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.paste-info {
  background: transparent;
  border: none;
  padding: 2px;
  cursor: help;
  color: var(--text-subtle);
  display: inline-flex;
  align-items: center;
  border-radius: 50%;
  transition: color 0.15s;
}
.paste-info:hover { color: var(--accent); }
.paste-info[hidden] { display: none; }

.items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-table thead th {
  background: #fafaf9;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  position: relative;
}
.items-table thead th:last-child { border-right: none; }
.items-table thead th.num { text-align: right; }
.items-table thead th.col-actions { width: 36px; }

.items-table thead th.col-actions { width: 128px; }

.items-table tbody td.row-actions { padding: 0 4px; vertical-align: middle; }
.row-actions-inner {
  display: flex;
  gap: 1px;
  opacity: 0.25;
  transition: opacity 0.15s;
  justify-content: flex-end;
}
.items-table tbody tr:hover .row-actions-inner,
.items-table tbody tr:focus-within .row-actions-inner { opacity: 1; }

/* Section-Row (Abschnittsüberschrift, zählt nicht als Position) */
.items-table tbody tr.section-row td {
  background: #f5f5f4;
  border-right: none;
  border-top: 1px solid var(--border-strong);
  padding-left: 4px;
}
.items-table tbody tr.section-row input.section-input {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
  padding: 6px 10px;
  background: transparent;
  border: none;
}
.items-table tbody tr.section-row input.section-input:focus {
  background: var(--surface);
  box-shadow: 0 0 0 2px rgba(8,145,178,0.15);
}
.items-table tbody tr.section-row input.section-input::placeholder {
  color: var(--text-subtle);
  font-weight: 400;
}

/* Legacy: sub-row für alte, nicht migrierte Rechnungen identisch wie section */
.items-table tbody tr.sub-row td { background: #f5f5f4; padding-left: 4px; }
.items-table tbody tr.sub-row input.sub-input {
  font-size: 13px; font-weight: 600; color: var(--text);
  padding: 6px 10px; background: transparent; border: none;
}

/* Description-Zelle: Titel-Input oben + Toggle-Icon rechts + optionale Textarea unten */
.items-table td.desc-cell {
  padding: 2px 6px;
  vertical-align: top;
}
.desc-cell .desc-main {
  display: flex;
  align-items: center;
  gap: 2px;
}
.desc-cell .desc-main input {
  flex: 1;
  min-width: 0;
}
.desc-cell .desc-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.12s, color 0.12s, background 0.12s, border-color 0.12s;
}
/* Bei Hover der Zelle: Icon wird deutlich sichtbar */
.items-table tr:hover .desc-cell .desc-toggle,
.desc-cell:hover .desc-toggle {
  opacity: 1;
}
.desc-cell .desc-toggle:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
/* Wenn Beschreibung bereits aktiv ist: permanent sichtbar hervorgehoben */
.desc-cell.has-desc .desc-toggle {
  opacity: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.desc-cell textarea.desc-text {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 0;
  line-height: 1.4;
  resize: none;
  overflow-y: hidden;
  font-family: inherit;
  min-height: 22px;
}
.desc-cell textarea.desc-text:focus {
  outline: none;
  background: #fafaf9;
  box-shadow: none;
}
.desc-cell textarea.desc-text::placeholder {
  color: var(--text-subtle);
  font-style: italic;
}

/* ============================================================
 * StBVV-Zellen: Leistung-Dropdown + dynamische Berechnungs-Inputs
 * ============================================================ */
.items-table td.stbvv-input-cell {
  padding: 4px 8px;
  background: #fafaf9;
}
.stbvv-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
/* StBVV-Beschreibungsspalte: Leistungs-Combo + Zusatzzeilen-Toggle (wie normale
 * Beschreibung). Combo füllt die Zeile, Icon-Button rechts daneben. */
.desc-cell .desc-main .combo { flex: 1 1 auto; min-width: 0; }
.stbvv-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}
.stbvv-field-satz {
  flex: 0 0 110px;
}
.stbvv-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stbvv-range {
  color: var(--text-subtle);
  font-weight: normal;
  letter-spacing: 0;
}
.stbvv-field input {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.3;
  width: 100%;
  min-width: 0;
}
.stbvv-field input:focus {
  outline: none;
  border-color: var(--accent);
}
.stbvv-satz-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stbvv-satz-wrap input {
  width: 3.5em;
  text-align: right;
}
.stbvv-denom {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.stbvv-hint {
  color: var(--text-subtle);
  font-size: 12px;
  font-style: italic;
}
.stbvv-service-select {
  padding: 6px 8px;
}

/* Durchsuchbares Custom-Select (Combobox) ------------------------------- */
.combo { position: relative; width: 100%; }
.items-table .combo-cell { padding: 0; }
.items-table .combo-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: auto;
  padding: 8px 10px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.combo-trigger .combo-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.combo-value.placeholder { color: var(--text-muted); }
.combo-caret { flex: 0 0 auto; color: var(--text-muted); }
.combo.open .combo-trigger,
.items-table .combo-trigger:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}
.combo-panel {
  position: fixed;
  z-index: 100;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(0,0,0,0.16);
  padding: 6px;
}
.combo-panel[hidden] { display: none; }
.items-table .combo-panel .combo-search,
.combo-panel .combo-search {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  margin-bottom: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
}
.combo-options { max-height: 240px; overflow-y: auto; }
.combo-option {
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.combo-option:hover,
.combo-option.active { background: var(--accent-soft); }
.combo-empty { padding: 8px 9px; color: var(--text-muted); font-size: 12px; }
.stbvv-total-cell {
  text-align: right;
  padding: 8px 10px !important;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.items-table tbody td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
}
.items-table tbody td:last-child { border-right: none; }
.items-table tbody tr:last-child td { border-bottom: none; }

.items-table input, .items-table select {
  border: none;
  background: transparent;
  height: auto;
  padding: 8px 10px;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 0;
}
.items-table input:focus, .items-table select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: none;
  background: var(--accent-soft);
}
.items-table input.num { text-align: right; font-variant-numeric: tabular-nums; }

.items-table tbody tr:hover td { background: #fafaf9; }
.items-table tbody tr.row-del td { background: #fef2f2; }

.row-action-btn {
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-family: inherit;
  transition: background 0.1s, color 0.1s;
}
.row-action-btn svg { display: block; }
.row-action-btn:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
.row-action-btn.del:hover:not(:disabled) { color: var(--danger); background: #fef2f2; }
.row-action-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.col-handle {
  cursor: grab;
  color: var(--text-subtle);
  text-align: center;
  user-select: none;
  font-size: 14px;
}
.col-handle:hover { color: var(--text-muted); }

/* TOTALS ---------------------------------------------------------------- */
.totals {
  margin-top: 20px;
  margin-left: auto;
  max-width: 700px;
  font-variant-numeric: tabular-nums;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 14px;
}
.totals-row.sep { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }
.totals-row.sum {
  font-weight: 600;
  font-size: 16px;
  border-top: 2px solid var(--text);
  margin-top: 4px;
  padding-top: 12px;
}
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.inline-field .suffix { color: var(--text-muted); }

/* Anpassungs-Zeilen (Rabatt, Gebühr, ...) */
.totals-add { justify-content: flex-start !important; padding: 4px 12px !important; }
.totals-add .btn {
  font-weight: 400;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--bg, #fafaf9);
}
.totals-add .btn:hover { color: var(--accent-hover); border-color: var(--border); background: #f5f5f4; }
.totals-add .btn:disabled { opacity: .5; cursor: not-allowed; }

.adj-row {
  display: grid;
  grid-template-columns: 1fr 68px 70px 68px 120px 36px;
  gap: 8px;
  align-items: center;
  padding: 4px 12px;
}
.adj-row input,
.adj-row select {
  width: 100%;
  /* Erbt 36px Höhe von der globalen Input-Regel */
}
.adj-row .adj-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
}
.adj-amount.adj-minus { color: var(--danger); }
.adj-amount.adj-plus  { color: var(--success); }
@media (max-width: 700px) {
  .adj-row {
    grid-template-columns: 1fr 1fr auto;
    row-gap: 6px;
  }
  .adj-row input[data-f="label"] { grid-column: 1 / -1; }
  .adj-row [data-del] { grid-row: 2; }
}

/* LIST (Rechnungen / Absender) ----------------------------------------- */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.5fr;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar .field { margin-bottom: 0; }
@media (max-width: 700px) {
  .filter-bar { grid-template-columns: 1fr; }
}

/* ===== Auswertung / Analytics ===== */
#ana-filter { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.kpi-sub { font-size: 11px; color: var(--text-subtle); margin-top: 4px; min-height: 14px; }

/* Segment-Umschalter (Anzahl/Umsatz) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 14px; font: inherit; font-size: 12px; color: var(--text-muted);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.is-active { background: var(--accent-soft, #eef2ff); color: var(--accent-hover, var(--text)); font-weight: 500; }

/* Balkendiagramm (div-basiert, responsiv) */
.ana-chart { overflow-x: auto; padding-top: 6px; }
.ana-chart-inner { min-width: 100%; }
.ana-plot {
  position: relative;
  /* Dezente horizontale Gitterlinien (0/25/50/75/100 %) */
  background-image:
    linear-gradient(var(--border), var(--border)),
    linear-gradient(var(--border), var(--border)),
    linear-gradient(var(--border), var(--border)),
    linear-gradient(var(--border), var(--border)),
    linear-gradient(var(--border), var(--border));
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: 0 0, 0 25%, 0 50%, 0 75%, 0 100%;
}
.ana-plot .bars {
  position: relative;
  display: flex; align-items: flex-end; gap: 10px;
  height: 100%; min-width: 100%;
}
.bar-col {
  flex: 1 1 0; min-width: 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.bar-val { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; height: 14px; white-space: nowrap; }
.bar {
  width: 100%; max-width: 46px;
  background: var(--accent, #4f46e5); border-radius: 4px 4px 0 0;
  min-height: 2px;
}
.bar-empty { background: var(--border); }
.ana-xaxis { display: flex; gap: 10px; margin-top: 6px; min-width: 100%; }
.bar-label { flex: 1 1 0; min-width: 28px; text-align: center; font-size: 10px; color: var(--text-subtle); white-space: nowrap; }

/* StBVV-Gebührentabellen — read-only Einsicht auf der Leistungen-Seite */
.stbvv-tables-card { margin-top: 24px; border: 1px solid var(--border); border-radius: var(--radius, 8px); background: var(--surface); }
.stbvv-tables-card > summary {
  cursor: pointer; padding: 14px 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  list-style: none;
}
.stbvv-tables-card > summary::-webkit-details-marker { display: none; }
.stbvv-tables-card > summary::before { content: '▸'; margin-right: 8px; color: var(--text-muted); }
.stbvv-tables-card[open] > summary::before { content: '▾'; }
.stbvv-tables-version { font-weight: 400; font-size: 12px; color: var(--text-muted); }
.stbvv-tables-view { padding: 4px 16px 18px; }
.stbvv-tables-note { margin-bottom: 14px; }
.stbvv-tables-checked { margin-top: 14px; }

/* Tab-Leiste A | B | C */
.stbvv-tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.stbvv-tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 8px 14px; font: inherit; font-size: 13px; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.stbvv-tab:hover { color: var(--text); }
.stbvv-tab.is-active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent, #6b8afd); }

.stbvv-pane[hidden] { display: none; }
.stbvv-pane-desc { margin-bottom: 10px; }

.stbvv-fee-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stbvv-fee-table th, .stbvv-fee-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.stbvv-fee-table thead th { color: var(--text-muted); font-weight: 600; text-align: left; }
.stbvv-fee-table .num { text-align: right; white-space: nowrap; }
.stbvv-fee-table tbody tr:hover { background: var(--surface-2, rgba(0,0,0,0.02)); }
.stbvv-fee-table .stbvv-overflow td { font-size: 12px; color: var(--text-muted); }

/* Absender-Textvorlagen: Inline-Tabs (Rechnung/Angebot/Storno) + Sie/Du */
.tpl-section-head { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); margin-bottom: 14px; }
.tpl-section-title { font-weight: 600; font-size: 15px; }
.tpl-section-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.tpl-tabbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.tpl-pane { display: flex; flex-direction: column; gap: 18px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius, 10px); background: var(--bg); }
.tpl-pane .field { margin: 0; }
.tpl-pane .field + .field { border-top: 1px solid var(--border); padding-top: 18px; }
.tpl-pane textarea { min-height: 70px; background: var(--surface); }
.tpl-pane .placeholder-help { margin-top: 0; }
/* Schlanke Variante (Standard-Spalten, Nummernkreise) – ohne Feld-Trennlinie */
.seg-pane { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius, 10px); background: var(--bg); }
.seg-pane > .field:first-child { margin-top: 0; }
.seg-pane .grid-2 { margin-top: 16px; }

/* Layout-Editor: überschreibbare Felder (Kategorie-/Absender-Tabs) */
.layout-field { padding: 12px 0 0; }
.layout-ovr {
  display: flex; align-items: center; gap: 9px;
  cursor: pointer; margin-bottom: 8px; user-select: none;
}
.layout-ovr input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0; flex: 0 0 auto;
  accent-color: var(--accent); cursor: pointer;
}
.layout-ovr-label { font-size: 13px; font-weight: 500; color: var(--text); }
.layout-ovr-tag {
  margin-left: auto; font-size: 10px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--bg-subtle, #f3f4f6); color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.layout-field.is-overridden .layout-ovr-tag {
  background: var(--accent-soft, #eef2ff); color: var(--accent-hover, var(--accent));
}
/* Vererbtes (deaktiviertes) Feld dezent abdimmen */
.layout-field [data-field]:disabled {
  opacity: 0.55; background: var(--bg-subtle, #f8fafc); cursor: not-allowed;
}

/* Mandantentabelle (sortierbar) */
.ana-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ana-table thead th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-subtle);
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.ana-table thead th:hover { color: var(--text); }
.ana-table thead th.is-sorted { color: var(--text); }
.ana-table thead th.ana-num { text-align: right; }
.ana-table .ana-sort { font-size: 9px; margin-left: 3px; }
.ana-table tbody td, .ana-table tfoot td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ana-table tbody tr:last-child td { border-bottom: 0; }
.ana-table .ana-num { text-align: right; white-space: nowrap; }
.ana-table .ana-c-name { font-weight: 500; color: var(--text); }
.ana-table .ana-c-name a { color: var(--text); text-decoration: none; }
.ana-table .ana-c-name a:hover { color: var(--accent-hover, var(--accent)); text-decoration: underline; }
.ana-table .ana-m-count { display: block; font-size: 11px; font-weight: 400; color: var(--text-subtle); margin-top: 2px; }
.ana-table .ana-c-amount .ana-m-gross { display: block; font-size: 14px; font-weight: 600; color: var(--text); }
.ana-table .ana-c-amount .ana-m-net { display: block; font-size: 11px; color: var(--text-subtle); }
.ana-paid { color: #166534; font-weight: 500; }
.ana-open { color: #92400e; font-weight: 500; }
.ana-dash { color: var(--text-subtle); }
.ana-table tfoot td { border-bottom: 0; border-top: 2px solid var(--border); font-weight: 600; }

.list-group-head {
  padding: 14px 18px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: #fafaf9;
  border-bottom: 1px solid var(--border);
}
.list-group-head:first-child { border-top: none; }
.list > .list-group-head + .list-item { border-top: none; }
.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.list-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #fafaf9; }
.list-item .title { font-weight: 500; }
.list-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
/* Feste Breiten für bündige Pseudo-Spalten über alle Zeilen hinweg. */
.list-item .amount {
  width: 120px;
  text-align: right;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Tabellarische Dokument-Zeilen (Rechnungen / Angebote) ----------------- */
.list-item.doc-row {
  grid-template-columns: 104px minmax(140px, 1fr) 150px 116px 132px 184px;
  gap: 14px;
  align-items: center;
}
.list-item.doc-row .amount,
.list-item.doc-row .status-cell { width: auto; }
.doc-row .cell-number .title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.doc-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.doc-badge--storno { background-color: #fef3c7; color: #92400e; }
.doc-row .cell-main { font-size: 13px; }
.doc-row .cell-contact .cell-main { font-weight: 500; }
.doc-row .cell-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.doc-row .cell-amount { text-align: right; }
.doc-row .cell-amount .cell-main { font-weight: 500; font-variant-numeric: tabular-nums; }
.doc-row .cell-amount .cell-sub { font-variant-numeric: tabular-nums; }
.doc-row.is-overdue { background: #fdf5f4; }
.doc-row.is-overdue:hover { background: #fbeeec; }

/* Klickbare Kopfzeile der Dokument-Listen (Spaltensortierung) */
.doc-list-head {
  display: grid;
  grid-template-columns: 104px minmax(140px, 1fr) 150px 116px 132px 184px;
  gap: 14px;
  align-items: center;
  padding: 9px 18px;
  background: #fafaf9;
  border-bottom: 1px solid var(--border);
}
.doc-list-head .dh {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
button.dh {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
button.dh:hover { color: var(--text); }
.doc-list-head .dh.is-active { color: var(--accent); }
.doc-list-head .dh-amount { justify-content: flex-end; text-align: right; }
.doc-list-head .dh-static { cursor: default; }
.sort-ind { font-size: 9px; line-height: 1; }

/* Fälligkeits-/Status-Farben (Listen + Editor-Hint) */
.due-ok   { color: #047857; }
.due-warn { color: #b45309; }
.due-over { color: #b91c1c; font-weight: 500; }

/* Editor: linke Spalte als Stapel (Daten + Status) */
.col-stack { display: flex; flex-direction: column; gap: 20px; }
.col-stack .card { margin-bottom: 0; }

/* Editor: Fälligkeits-Hinweis im Status-Panel */
.due-hint { font-size: 13px; margin-top: 2px; }

/* Service-Register: Kind-Badges */
.svc-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.svc-badge-value   { background: #dbeafe; color: #1e40af; }
.svc-badge-hourly  { background: #fef3c7; color: #92400e; }
.svc-badge-unit    { background: #d1fae5; color: #065f46; }
.svc-badge-flat    { background: #e5e7eb; color: #374151; }
.svc-badge-unknown { background: #fecaca; color: #991b1b; }

/* Sender-Form: Templates-Gruppen */
.templates-group {
  padding: 14px 16px 10px;
  background: #fafaf9;
  border-radius: 8px;
  border: 1px solid var(--border);
}
/* In Tab-Panels sind die Gruppen bereits von der Card umrahmt — kein
   Kasten-im-Kasten. Stattdessen als klar getrennte Unterabschnitte. */
.contact-panel .templates-group {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}
.contact-panel .templates-group + .templates-group {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.templates-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
/* Volle Breite, untereinander — spiegelt das Rechnungslayout (Einleitung oben,
   Fußtext unten über die ganze Seitenbreite). */
.text-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

/* Kleiner Hinweis unter einem Eingabefeld (z.B. Nummern-Vorschlag, Vorschau). */
.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.field-hint--warn { color: #b45309; }

/* Automatisch vergebenes Nummernfeld (Auto-Nummernkreis im Absender): gesperrt,
   optisch als „nicht editierbar" erkennbar. */
input.is-auto {
  background: #f5f5f4;
  color: #57534e;
  cursor: not-allowed;
}

/* Nummernfeld + „Nr. bearbeiten"-Button nebeneinander. */
.num-edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.num-edit-row > input { flex: 1 1 auto; min-width: 0; }
.num-edit-row > .btn { flex: 0 0 auto; white-space: nowrap; }

/* Mahnung: Kostenübersicht */
.align-right { text-align: right; }
.dun-prev-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.dun-prev-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border, #e7e5e4);
  color: var(--text, #1c1917);
}
.dun-prev-table tr:last-child td { border-bottom: none; }
.dun-prev-table .align-right { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dun-prev-table .dun-prev-sum td {
  font-weight: 700;
  font-size: 15px;
  border-top: 2px solid var(--border, #e7e5e4);
  padding-top: 12px;
}

/* Sammelposten-Umschalter im Vorschuss-Kopf */
.adv-combine-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.adv-combine-toggle input { width: auto; height: auto; margin: 0; cursor: pointer; }
.adv-combined-row { color: var(--text); }

/* Vorlagen in den Listen optisch abheben */
.list-item--template { background: #fbfaf8; }

/* ⋮-Aktionsmenü im Editor-Kopf */
.action-menu { position: relative; display: inline-flex; }
.action-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
  padding: 4px;
  z-index: 60;
  display: none;
  flex-direction: column;
}
.action-menu-list.is-open { display: flex; }
.action-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.action-menu-item:hover { background: #f5f5f4; }

/* Offer-Status-Badges in der Liste */
.offer-status {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.offer-status.valid    { background: #d1fae5; color: #065f46; }
.offer-status.expiring { background: #fef3c7; color: #92400e; }
.offer-status.expired  { background: #fecaca; color: #991b1b; }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* KONTAKT-DATEIEN ------------------------------------------------------- */
.files-list { display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.file-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.file-title { font-weight: 500; word-break: break-word; }
.file-meta { font-size: 12px; color: var(--text-muted); }
.file-actions { display: flex; gap: 6px; flex-shrink: 0; }
.files-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* KONTAKT-SEITE (Tabs links, Panel rechts) + HISTORIE ------------------- */
.contact-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
  margin-bottom: 20px;
}
.contact-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 20px;
}
.contact-tab {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.contact-tab:hover { background: #f5f5f4; color: var(--text); }
.contact-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.contact-panels { min-width: 0; }
.contact-panel { display: none; }
.contact-panel.is-active { display: block; }
/* Layout-Editor im Absender-Tab: keine zweite linke Spalte, Tabs horizontal */
.contact-layout.layout-inline { display: block; }
.contact-layout.layout-inline .contact-tabs {
  flex-direction: row;
  flex-wrap: wrap;
  position: static;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
@media (max-width: 900px) {
  .contact-layout { grid-template-columns: 1fr; gap: 16px; }
  .contact-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
    gap: 6px;
  }
}
.contact-side { display: flex; flex-direction: column; gap: 20px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.history-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-title { font-weight: 500; }
.hist-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
}
.hist-badge.invoice { background: #eff6ff; color: #1d4ed8; }
.hist-badge.offer   { background: #f5f3ff; color: #6d28d9; }

/* VORSCHUSS-ANRECHNUNG (Editor-Summenblock) --------------------------- */
.advance-draws-head {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}
/* Zeile bündig zur Rabatt-Zeile: gleiches 6-Spalten-Raster, Select + Betrag
   spannen die mittleren Spalten, Summe und Löschen sitzen exakt unter den
   Rabatt-Pendants. */
.adj-row.adv-draw-row {
  grid-template-columns: 1fr 68px 70px 68px 120px 36px;
}
.adv-draw-row select[data-f="service"] { grid-column: 1 / 2; }
.adv-draw-row input[data-f="amount"]   { grid-column: 2 / 5; }
.adv-draw-row .adv-draw-amount          { grid-column: 5 / 6; }
.adv-draw-row [data-del]                { grid-column: 6 / 7; }
.adv-draw-amount { color: #b45309; }
@media (max-width: 700px) {
  .adj-row.adv-draw-row {
    grid-template-columns: 1fr auto;
    row-gap: 6px;
  }
  .adv-draw-row select[data-f="service"] { grid-column: 1 / -1; }
  .adv-draw-row input[data-f="amount"]   { grid-column: 1 / 2; grid-row: 2; }
  .adv-draw-row .adv-draw-amount          { grid-column: 2 / 3; grid-row: 2; }
  .adv-draw-row [data-del]                { grid-column: 2 / 3; grid-row: 1; justify-self: end; }
}

/* VORSCHUSS-PANEL (Kontakt-Ansicht) ----------------------------------- */
.advances-list { display: flex; flex-direction: column; gap: 12px; }
.adv-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.adv-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.adv-item-name { font-weight: 500; }
.adv-item-balance { font-weight: 600; }
.adv-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.adv-moves { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.adv-move {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  padding: 2px 0;
  border-top: 1px dashed var(--border);
}
.adv-move:first-child { border-top: 0; }
.adv-move-meta { color: var(--text-muted); flex: 1; }
.adv-move-amount { font-variant-numeric: tabular-nums; }
.adv-move-billed .adv-move-amount { color: #15803d; }
.adv-move-drawn .adv-move-amount  { color: #b45309; }
.adv-move-manual-label { font-weight: 500; }
.adv-move-del { padding: 1px 4px; }

/* Manuelle Vorschuss-Erfassung */
.adv-manual {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.adv-manual-head { font-weight: 600; margin-bottom: 10px; }
.adv-manual-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 1fr 0.7fr 1.4fr auto;
  gap: 10px;
  align-items: end;
}
.adv-manual-grid .field-grow { grid-column: auto; }
.adv-manual-grid .field-action { align-self: end; }
.adv-manual-grid .field-action .btn { white-space: nowrap; }
.adv-manual-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
@media (max-width: 720px) {
  .adv-manual-grid { grid-template-columns: 1fr 1fr; }
  .adv-manual-grid .field-grow,
  .adv-manual-grid .field-action { grid-column: 1 / -1; }
}

/* Kontaktliste als Tabelle: Name+Adresse, Kd-Nr., Rechnungen, Umsatz, Aktion */
.contacts-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.contacts-table thead th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted);
  padding: 12px 14px 8px; border-bottom: 1px solid var(--border);
}
.contacts-table thead th.ct-num { text-align: right; }
.contacts-table thead th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.contacts-table thead th[data-sort]:hover { color: var(--text); }
.contacts-table thead th.is-sorted { color: var(--text); }
.contacts-table .ct-sort { font-size: 9px; margin-left: 3px; }
.contacts-table tbody td {
  padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.contacts-table tbody tr:last-child td { border-bottom: 0; }
.contacts-table tbody tr { cursor: pointer; transition: background 0.1s; }
.contacts-table tbody tr:hover { background: #fafaf9; }
.contacts-table .ct-name .title { font-weight: 500; }
.contacts-table .ct-name .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.contacts-table .ct-kdnr { font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }
.contacts-table .ct-count-n { font-size: 13px; margin-bottom: 4px; }
.contacts-table .ct-sum { text-align: right; white-space: nowrap; }
.contacts-table .ct-sum-total { font-weight: 500; font-variant-numeric: tabular-nums; }
.contacts-table .ct-action { text-align: right; white-space: nowrap; vertical-align: middle; }
/* Aktions-Spalte (Button) auf Inhaltsbreite schrumpfen, damit die „Umsatz“-Spalte
   in Kopf- und Körperzeilen exakt dieselbe rechte Kante hat (sonst wirkt der
   rechtsbündige „Umsatz“-Header gegenüber den Beträgen leicht verschoben). */
.contacts-table thead th:last-child,
.contacts-table .ct-action { width: 1%; white-space: nowrap; }
.contacts-table .ct-dash, .contacts-table .ct-muted { color: var(--text-muted); }
.contacts-table .cstat-badges { justify-content: flex-start; }

.kdnr {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  background: #f1f0ed;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.cstat-advance {
  font-size: 12px;
  font-weight: 600;
  color: #15803d;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.cstat-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.cstat-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.cstat-draft     { background: #f1f0ed; color: #57534e; }
.cstat-sent      { background: #dbeafe; color: #1e40af; }
.cstat-paid      { background: #dcfce7; color: #166534; }
.cstat-cancelled { background: #fee2e2; color: #991b1b; }
@media (max-width: 720px) {
  .contacts-table thead { display: none; }
  .contacts-table, .contacts-table tbody, .contacts-table tr, .contacts-table td { display: block; width: 100%; }
  .contacts-table tbody td { border-bottom: 0; padding: 2px 14px; }
  .contacts-table tbody tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .contacts-table .ct-sum, .contacts-table .ct-action { text-align: left; }
}

/* Klickbarer Kontakt-Link in Listenzeilen (Rechnungen/Angebote) */
.contact-link { color: inherit; text-decoration: none; }
.contact-link:hover { color: var(--accent, #0891b2); text-decoration: underline; }

/* Export-Formular */
.export-card { max-width: 720px; }
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}
.check-row input[type="checkbox"] { margin-top: 2px; flex: 0 0 auto; }
.export-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
  line-height: 1.5;
}
.export-hint code {
  background: #f1f0ed;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

/* ==================== VERLAUF / ACTIVITY-LOG ==================== */
.activity-list { margin-top: 4px; }
.act-day {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 18px 0 8px;
}
.act-day:first-child { margin-top: 4px; }
.act-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border, #e7e5e0);
}
.act-badge {
  flex: 0 0 auto;
  display: inline-block;
  min-width: 74px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #f1f0ed;
  color: var(--text-muted);
}
.act-invoice { background: #e6f0fb; color: #1f5fa8; }
.act-offer   { background: #eef3e6; color: #4a7a2a; }
.act-contact { background: #f3ecf8; color: #7a3aa8; }
.act-service { background: #fbf1e3; color: #a86a1f; }
.act-export  { background: #e4f4f3; color: #1f7d77; }
.act-body { min-width: 0; flex: 1 1 auto; }
.act-msg { font-size: 13px; line-height: 1.45; }
.act-ref-link { font-size: 12px; margin-left: 4px; }
.act-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* STATUS-PILLE (Rechnungs-/Angebotsliste) ------------------------------ */
/* Sichtbares Badge + unsichtbares <select> darüber (nativer Dropdown). */
.status-cell { display: flex; justify-content: flex-start; width: 116px; }
.status-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
}
.status-badge::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid currentColor;
  opacity: 0.55;
}
.status-badge:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.status-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.status-badge.status-draft     { background-color: #e7e5e4; color: #44403c; }
.status-badge.status-sent      { background-color: #dbeafe; color: #1e40af; }
.status-badge.status-paid      { background-color: #d1fae5; color: #065f46; }
.status-badge.status-cancelled { background-color: #fecaca; color: #991b1b; }
.status-badge.status-accepted  { background-color: #d1fae5; color: #065f46; }
.status-badge.status-rejected  { background-color: #fecaca; color: #991b1b; }

/* DAUERRECHNUNGEN ------------------------------------------------------- */
.rec-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.rec-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.rec-badge.ok     { background: #ecfdf5; color: #047857; }
.rec-badge.due    { background: #fff7ed; color: #c2410c; }
.rec-badge.paused { background: #f5f5f4; color: var(--text-muted); }

.due-panel { margin-bottom: 24px; border-left: 3px solid #f59e0b; }
.due-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.due-head h2 { font-size: 15px; font-weight: 600; }
.due-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.due-info { min-width: 0; }
.due-title { font-weight: 500; }
.due-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.due-count {
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  background: #fff7ed;
  color: #c2410c;
  margin-left: 6px;
}

/* MODAL ----------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.4);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease-out;
}
.modal-body {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: modalIn 0.2s ease-out;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* COL-CONFIG ROW -------------------------------------------------------- */
.col-cfg-row {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr 0.8fr 0.9fr 0.7fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: #fafaf9;
}
.col-cfg-row .field { margin-bottom: 0; }
.col-cfg-actions { display: flex; gap: 4px; }
.col-cfg-actions .btn { padding: 6px 8px; font-size: 12px; }
@media (max-width: 760px) {
  .col-cfg-row { grid-template-columns: 1fr 1fr; }
  .col-cfg-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* HEADER INLINE CONTROLS ------------------------------------------------ */
.items-table thead th {
  padding: 0;
}
.th-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.th-inner.num { justify-content: flex-end; }
.th-inner .th-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.th-inner.num .th-label { text-align: right; }
.th-controls {
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity 0.15s;
}
.items-table thead th:hover .th-controls { opacity: 1; }
.th-btn {
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  width: 22px;
  height: 22px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.th-btn svg { display: block; }
.th-btn:hover { color: var(--accent); background: var(--accent-soft); }
.th-btn.del:hover { color: var(--danger); background: #fef2f2; }

/* INSERT-COL dropdown menu --------------------------------------------- */
.menu {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 150;
  padding: 4px;
  min-width: 200px;
  font-size: 13px;
}
.menu-item {
  display: block;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 3px;
  color: var(--text);
}
.menu-item:hover { background: var(--accent-soft); color: var(--accent-hover); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-label { padding: 4px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-subtle); }

/* TOAST ----------------------------------------------------------------- */
.toast-wrap {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease-out;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideIn {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* LOGO UPLOAD ----------------------------------------------------------- */
.logo-drop {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  background: #fafaf9;
}
.logo-drop:hover { border-color: var(--accent); color: var(--accent); }
.logo-preview {
  max-width: 180px;
  max-height: 70px;
  display: block;
  margin: 0 auto 10px;
}

/* ============================================================
 * MOBILE / RESPONSIVE
 * ============================================================ */

/* Desktop-Defaults für neue Elemente: ausblenden */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* Tablet + Mobile (≤ 900px) */
@media (max-width: 900px) {
  /* App: einspaltig, Sidebar als Drawer */
  .app { grid-template-columns: 1fr; }

  /* Mobile-Topbar mit Hamburger + Brand */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 90;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
  }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text);
    padding: 0;
  }
  .mobile-menu-btn:hover { background: var(--surface-2, #f5f5f4); }
  .mobile-brand {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
  }
  .mobile-brand img {
    max-height: 32px;
    max-width: 180px;
    object-fit: contain;
  }
  .mobile-brand span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Sidebar als Slide-in-Drawer von links */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    box-shadow: 2px 0 20px rgba(0,0,0,0.05);
    border-right: 1px solid var(--border);
    border-bottom: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 2px 0 20px rgba(0,0,0,0.15);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, 0.4);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }
  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main-Content: Mobile-Padding, kein max-width */
  .main {
    padding: 20px 16px 60px;
    max-width: 100%;
  }

  /* Page-Head: von flex-end auf Stack wenn eng */
  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .page-head h1 { font-size: 22px; }
  .page-head .btn-row { flex-wrap: wrap; }

  /* Grid-Layouts: single column */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }

  /* Filter-Bar: stack */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .field { width: 100%; }

  /* Tabellen horizontal scrollbar machen */
  .items-wrap,
  .card > .items-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .items-table {
    font-size: 12px;
    min-width: 560px; /* damit nicht alles gequetscht wird */
  }
  .items-table input, .items-table select { padding: 6px 8px; font-size: 12px; }

  /* List-Items kompakter */
  .list-item {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 14px;
  }
  .list-item .btn-row { flex-wrap: wrap; }
  /* Feste Spaltenbreiten auf Mobile aufheben — Platz ist hier knapp. */
  .list-item .amount, .status-cell { width: auto; }
  /* Tabellarische Dokument-Zeilen auf Mobile gestapelt. */
  .list-item.doc-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .doc-row .cell-amount { text-align: left; }
  .doc-row .status-cell { justify-content: flex-start; }
  /* Kopfzeile passt im gestapelten Layout nicht — ausblenden. */
  .doc-list-head { display: none; }

  /* Row-Actions immer sichtbar auf Mobile (kein Hover!) */
  .items-table tbody tr .row-actions-inner { opacity: 1; }
  .desc-cell .desc-toggle { opacity: 1; }

  /* Modals: volle Breite, weniger Padding */
  .modal { padding: 20px 12px; }
  .modal-body { padding: 18px; }

  /* Totals-Tabelle: weniger breit, besser lesbar */
  .totals { width: 100%; }
  .totals-row { flex-wrap: wrap; }

  /* Buttons: Text nicht mehr komplett schmal abschneiden */
  .btn { white-space: nowrap; }
}

/* Kleine Smartphones */
@media (max-width: 480px) {
  .main { padding: 16px 12px 48px; }
  .card { padding: 14px; }
  .page-head h1 { font-size: 20px; }
  .btn { font-size: 12px; padding: 7px 10px; }
  .btn-sm { font-size: 11px; padding: 5px 8px; }
}

/* Login-Logo */
.login-logo {
  display: block;
  max-width: 200px;
  max-height: 80px;
  object-fit: contain;
  margin: 0 auto 12px;
}

/* Logo-Uploader (Einstellungen-View) */
.logo-uploader .logo-preview-wrap {
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fafaf9;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Horizontaler Trenner in Formularen zwischen logisch getrennten Bereichen */
.form-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 32px 0 24px;
}

/* Color-Picker Zeilen in Einstellungen */
.color-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-input-row input[type="color"] {
  width: 60px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}
.color-input-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }

/* Sender-Form: Font-Upload-Zeile */
.font-upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.font-status {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--surface-2, #f5f5f4);
}
.font-status.ok {
  color: #166534;
  background: #dcfce7;
}
.font-status.none {
  color: var(--text-subtle);
  background: transparent;
}

/* Code-Input (Custom CSS Textarea) */
textarea.code-input {
  font-family: ui-monospace, SFMono-Regular, 'Cascadia Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px;
  background: #1c1917;
  color: #f5f5f4;
  border: 1px solid #44403c;
  border-radius: var(--radius-sm);
  resize: vertical;
  min-height: 100px;
  tab-size: 2;
}
textarea.code-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.15);
}

/* UTILS ----------------------------------------------------------------- */
.input-sm {
  width: 80px;
  height: 28px;
  padding: 0 8px;
  font-size: 13px;
  text-align: right;
}
.select-sm {
  width: auto;
  height: 28px;
  padding: 0 28px 0 8px;
  font-size: 13px;
  display: inline-block;
  background-position: right 6px center;
}

/* LOGIN SCREEN ---------------------------------------------------------- */
body.login-locked {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-overlay {
  width: 100%;
  max-width: 380px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px 28px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.login-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.login-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.login-trial {
  margin: -8px 0 18px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-subtle, #f5f5f4);
  border: 1px solid var(--border, #e7e5e4);
  border-radius: 999px;
  display: inline-block;
}
.login-trial__date {
  font-weight: 400;
  opacity: 0.75;
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-error {
  background: #fef2f2;
  color: #991b1b;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
}
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }

/* ============================================================
 * Dashboard
 * ============================================================ */

/* Sidebar-Brand als Link */
.sidebar-brand-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  margin-bottom: 24px;
}
.sidebar-brand-link:hover { opacity: 0.85; }

.mobile-brand { text-decoration: none; color: inherit; }

/* Zwei große CTA-Karten oben auf dem Dashboard */
.dashboard-cta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.dashboard-cta-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.dashboard-cta-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.dashboard-cta-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dashboard-cta-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}
.dashboard-cta-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Pro-Absender-Karte */
.dash-sender {
  margin-bottom: 20px;
}
.dash-sender-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.dash-sender-head h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

/* Zwei Spalten: Rechnungen links, Angebote rechts */
.dash-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
.dash-col-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.dash-col-head h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
  margin: 0;
}
.dash-col-link {
  font-size: 11px;
  color: var(--text-subtle);
  text-decoration: none;
}
.dash-col-link:hover { color: var(--accent); }

.dash-doc-list { display: flex; flex-direction: column; }
.dash-doc-row {
  display: grid;
  grid-template-columns: minmax(74px, auto) 1fr auto 92px;
  gap: 12px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}
.dash-doc-row:last-child { border-bottom: 0; }
.dash-doc-row:hover { color: var(--accent); }
.dash-doc-number {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dash-doc-recipient {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-doc-date {
  color: var(--text-subtle);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.dash-doc-total {
  font-weight: 500;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.dash-empty {
  padding: 16px 0;
  color: var(--text-subtle);
  font-size: 13px;
  font-style: italic;
}

.dash-loading,
.dash-error {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}
.dash-error { color: var(--danger); }

.dash-empty-state {
  text-align: center;
  padding: 48px 32px;
}
.dash-empty-state h2 { margin-bottom: 12px; }
.dash-empty-state p { margin-bottom: 16px; color: var(--text-muted); }

/* Mobile: Spalten untereinander, CTAs auch */
@media (max-width: 900px) {
  .dashboard-cta { grid-template-columns: 1fr; }
  .dash-cols { grid-template-columns: 1fr; gap: 24px; }
  .dash-cols .dash-col:not(:last-child) {
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
  }
}

/* Emergency-Mode-Banner (wird oben über den App-Content gezeigt) */
.emergency-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  padding: 10px 20px;
  background: #dc2626;
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.emergency-banner a { color: #fff; text-decoration: underline; }
body:has(.emergency-banner) .app { padding-top: 40px; }

/* Platzhalter-Hilfe unter Text-Feldern */
.placeholder-help { margin-top: 8px; }
.placeholder-help-details { font-size: 12px; }
.placeholder-help-summary {
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}
.placeholder-help-summary:hover { color: var(--text); }
.placeholder-help-intro {
  color: var(--text-subtle);
  margin: 4px 0 10px;
  font-size: 11px;
}
.placeholder-help-grid {
  display: grid;
  /* 2 logische Spalten, jeweils: Token (feste Breite) · Label · Kopier-Icon.
     Durch max-content sind die Token-Spalten je Spalte gleich breit, sodass
     die Labels bündig untereinander starten (tabellarisch). */
  grid-template-columns: max-content minmax(0, 1fr) auto max-content minmax(0, 1fr) auto;
  column-gap: 10px;
  row-gap: 3px;
  align-items: center;
  padding: 8px 10px;
  background: #fafaf9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.placeholder-help-row { display: contents; }
@media (max-width: 640px) {
  .placeholder-help-grid {
    grid-template-columns: max-content minmax(0, 1fr) auto;
  }
}
.placeholder-token {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  color: var(--accent);
  white-space: nowrap;
}
.placeholder-token:hover { background: var(--accent-soft); border-color: var(--accent); }
.placeholder-label {
  flex: 1;
  min-width: 0;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.placeholder-example { color: var(--text-subtle); font-style: italic; }
.placeholder-copy {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-subtle);
  padding: 2px;
  display: inline-flex;
}
.placeholder-copy:hover { color: var(--accent); }

/* Sender-Spalten-Editor */
.sender-cols-editor { margin-top: 4px; }
.sender-cols-list { display: flex; flex-direction: column; gap: 4px; }
.sender-col-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sender-col-label {
  flex: 1;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.sender-col-role {
  font-size: 10px;
  min-width: 80px;
  text-align: right;
}
.sender-col-btn { padding: 0 8px; min-width: 28px; height: 28px; font-size: 13px; }
.sender-col-btn.danger { color: var(--danger); }
.sender-col-btn.danger:hover { background: #fef2f2; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }

/* Sender-Modal: Spalten-Status */
.sender-cols-status {
  padding: 8px 12px;
  background: #fafaf9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 34px;
  display: flex;
  align-items: center;
}
.sender-cols-status code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  margin-right: 3px;
}

/* ============================================================
 * Visueller Layout-Builder (Layout-Ansicht)
 * Klickbare A4-Vorschau links + Formular-Inspector rechts.
 * ============================================================ */
/* Nutzt die editor-shell-Aufteilung (volle Breite). Linke Spalte = Dokument,
   rechte Spalte = Inspector. Kein extra Rahmen — das Blatt steht direkt im
   Content und füllt die Spaltenbreite. */
.lb-side {
  min-width: 0; align-self: start;
  position: sticky; top: 24px;
  max-height: calc(100vh - 48px); overflow-y: auto;
}
@media (max-width: 1100px) { .lb-side { position: static; max-height: none; overflow: visible; } }

.lb-canvas { display: flex; justify-content: flex-start; align-items: flex-start; }
.lb-scaler { }
.lb-sheet {
  width: 210mm; height: 297mm; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.10); border-radius: 3px;
  transform-origin: top left; position: relative;
  padding: var(--pt,12mm) var(--pr,18mm) var(--mb,35mm) var(--pl,18mm);
  font-size: var(--fs, 9pt); color: var(--doc-text, #1c1917); line-height: 1.5;
  display: flex; flex-direction: column;
}

/* Geteiltes Layout: vollhohe Sidebar (Phase 3). Padding + Ausrichtung kommen
   inline (sidebar_pad_*_mm / sidebar_valign). */
.lb-sheet .region.lb-sidebar {
  position: absolute; top: 0; bottom: 0; z-index: 2;
  display: flex; flex-direction: column; gap: 6mm;
  font-size: 7pt; line-height: 1.6; color: var(--doc-muted, #57534e); overflow: hidden;
}
.lb-sidebar-right { right: 0; }
.lb-sidebar-left { left: 0; }
/* Abstand zwischen den Kacheln läuft über gap (kein nachlaufender Rand), damit
   die untere Ausrichtung exakt am padding-bottom endet — wie im PDF. */
.lb-sb-tile { overflow-wrap: anywhere; }
.lb-sb-tile b { color: var(--doc-text, #1c1917); font-weight: 600; }
.lb-sb-tile img { max-width: 100%; height: auto; }

/* Editierbare Seitenränder (mappen auf margin_*_mm) — als dezente Bänder an den
   Blattkanten, anklickbar wie die übrigen Regionen. */
.lb-sheet .region.lb-margin { position: absolute; z-index: 1; }
.lb-margin-l { top: 0; bottom: 0; left: 0; width: var(--ml, 18mm); }
.lb-margin-r { top: 0; bottom: 0; right: 0; width: var(--mr, 18mm); }
.lb-margin-b { left: 0; right: 0; bottom: 0; height: var(--mb, 35mm); }
.lb-margin-label {
  position: absolute; font-size: 6pt; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent, #0891b2); white-space: nowrap; pointer-events: none;
}
.lb-margin-l .lb-margin-label,
.lb-margin-r .lb-margin-label { top: 14mm; left: 50%; transform: translate(-50%, 0) rotate(-90deg); }
.lb-margin-b .lb-margin-label { left: 50%; top: 50%; transform: translate(-50%, -50%); }

/* CD-Kanten-Balken (mappen auf cd_bar_*_mm). Liegen über den Margin-Bändern an
   der äußersten Blattkante; gestrichelt wenn aus, gefüllt wenn aktiv. */
.lb-sheet .region.lb-cd { position: absolute; z-index: 4; border-radius: 0; }
/* Aus-Zustand im Ruhezustand komplett unsichtbar (kein dauerhafter Rand-/Page-
   Border-Marker mehr) — analog zu Gaps und Seitenrändern. Der Bereich bleibt
   klickbar und zeigt sich erst on hover bzw. wenn aktiv/selektiert. */
.lb-sheet .region.lb-cd:not(.is-on) {
  background: transparent;
  outline: 1px dashed transparent; outline-offset: -1px;
  transition: background .12s, outline-color .12s;
}
/* Bei Interaktion (Hover/Auswahl) deutlich erkennbar. */
.lb-sheet .region.lb-cd:not(.is-on):hover,
.lb-sheet .region.lb-cd:not(.is-on).lb-selected {
  background: rgba(200,16,46,.10);
  outline-color: rgba(200,16,46,.5);
}
.lb-cd-t { top: 0; left: 0; right: 0; }
.lb-cd-b { bottom: 0; left: 0; right: 0; }
.lb-cd-l { top: 0; bottom: 0; left: 0; }
.lb-cd-r { top: 0; bottom: 0; right: 0; }

/* Falzmarken/Lochmarke — dünne Striche an der linken Kante (rein visuell). */
.lb-foldmark { position: absolute; left: 0; height: 0; border-top: 1px solid #9ca3af; z-index: 5; pointer-events: none; }

/* Klickbare Regionen */
.lb-sheet .region { position: relative; border-radius: 2px; cursor: pointer; transition: box-shadow .12s, background .12s; }
.lb-sheet .region:hover { box-shadow: 0 0 0 2px var(--accent-soft); background: rgba(8,145,178,.04); }
.lb-sheet .region.lb-selected { box-shadow: 0 0 0 2px var(--accent); background: rgba(8,145,178,.06); }

/* ---- Overlay-Sichtbarkeit ------------------------------------------------
   Die Abstands-/Rand-Overlays (Gaps, Seitenränder, Footerline-Streifen) sind
   im Ruhezustand bewusst zurückhaltend: nur ein hauchdünner gestrichelter
   Rahmen weist darauf hin, dass der Bereich editierbar ist. Tönung, kräftiger
   Rahmen und die lauten mm-Labels erscheinen erst on hover bzw. wenn der
   Bereich aktiv ausgewählt ist — so kommt die Vorschau dem echten Dokument
   nahe, ohne die Editierbarkeit zu verstecken. Zentral über die .lb-*-Klassen. */
.lb-gap, .lb-footerline-gap, .lb-sheet .region.lb-margin {
  background: transparent;
  outline: 1px dashed transparent; outline-offset: -2px;
  transition: background .12s, outline-color .12s;
}
.lb-gap:hover, .lb-gap.lb-selected,
.lb-footerline:hover .lb-footerline-gap, .lb-footerline.lb-selected .lb-footerline-gap,
.lb-sheet .region.lb-margin:hover, .lb-sheet .region.lb-margin.lb-selected {
  background: rgba(8,145,178,.06);
  outline-color: var(--accent-soft, #a5f3fc);
}
/* Labels (mm-Beschriftung) standardmäßig ausgeblendet, on hover/aktiv sichtbar. */
.lb-gap-label, .lb-margin-label { opacity: 0; transition: opacity .12s; }
.lb-gap:hover .lb-gap-label, .lb-gap.lb-selected .lb-gap-label,
.lb-footerline:hover .lb-gap-label, .lb-footerline.lb-selected .lb-gap-label,
.lb-sheet .region.lb-margin:hover .lb-margin-label,
.lb-sheet .region.lb-margin.lb-selected .lb-margin-label { opacity: .75; }

/* Beleg-Bausteine (Annäherung an pdf.php) */
.lb-doc-header { text-align: var(--logo-align, center); padding: 6px 4px; margin-bottom: 0; }
.lb-doc-logo {
  height: var(--logo-h, 14mm); max-width: 55mm; border-radius: 6px; color: #0e7490; font-weight: 700; font-size: 12pt;
  background: repeating-linear-gradient(45deg,#ecfeff,#ecfeff 8px,#cffafe 8px,#cffafe 16px);
  display: inline-flex; align-items: center; justify-content: center; padding: 0 16px;
}
.lb-doc-logo-img { max-width: 55mm; height: auto; display: inline-block; vertical-align: middle; }
.lb-doc-company { font-size: 14pt; font-weight: 600; letter-spacing: .04em; }
.lb-meta { display: flex; gap: 8mm; margin-bottom: 0; align-items: flex-start; }
.lb-meta-left { flex: 1 1 auto; min-width: 0; }
.lb-meta-right { flex: 0 0 var(--meta-right-w, 30%); min-width: 0; text-align: var(--meta-align, right); }
/* Optionale Überschrift über dem Meta-Block (meta_heading). */
.lb-meta-heading { font-size: 8pt; font-weight: 600; color: var(--doc-text, #1c1917); margin-bottom: 0; }
/* Abstand Absender→Empfänger läuft als eigene Klick-Region (sendergap) → hier
   kein margin-bottom mehr (sonst doppelter Abstand). */
.lb-sender-line { font-size: var(--sender-fs, 7pt); font-weight: var(--sender-fw, normal); color: var(--sender-color, var(--doc-muted, #57534e)); margin-bottom: 0; overflow-wrap: anywhere; }
.lb-recipient { font-size: var(--recipient-fs, 10pt); font-weight: var(--recipient-fw, normal); line-height: 1.55; }
.lb-meta-row { display: flex; justify-content: space-between; gap: 6mm; font-size: var(--meta-fs, 8pt); font-weight: var(--meta-fw, normal); padding: .4mm 0; }
.lb-meta-row .l { color: var(--doc-muted, #57534e); font-weight: var(--meta-label-fw, normal); font-style: var(--meta-label-style, normal); }
.lb-meta-row .v { color: var(--doc-text, #1c1917); white-space: nowrap; }
.lb-meta-right.left .lb-meta-row { flex-direction: row-reverse; justify-content: flex-end; }
/* Editierbarer Zwischenraum (übersetzt zu title_spacing_mm) — als eigenes
   Element zwischen Meta-Block und Titel. Tönung/Rahmen/Label erscheinen erst
   on hover bzw. im aktiven Zustand (siehe Overlay-Regeln weiter unten); die
   Höhe (= mm-Wert) bleibt immer erhalten, damit der Beleg maßstabstreu bleibt. */
.lb-gap {
  box-sizing: border-box; min-height: 14px; margin-top: 2mm;
  display: flex; align-items: center; justify-content: center;
}
.lb-gap-label {
  font-size: 6.5pt; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent, #0891b2); pointer-events: none;
}
.lb-title-region { margin-bottom: 0; padding: 2px 4px; }
.lb-doc-title { font-size: var(--subject-fs, 17pt); font-weight: var(--subject-fw, bold); color: var(--accent-doc, #1c1917); margin: 0; }
.lb-intro { margin-bottom: 0; font-size: var(--intro-fs, var(--fs, 9pt)); font-weight: var(--intro-fw, normal); }
.lb-items { width: 100%; border-collapse: collapse; margin-bottom: 2mm; font-size: 8pt; }
.lb-items thead th {
  text-align: left; font-weight: 500; font-size: 7pt; letter-spacing: .05em; padding: 3mm 2mm;
  color: var(--th-color, #57534e); background: var(--th-bg, #ffffff);
  border-bottom: var(--th-rule, 1px solid #57534e);
  text-transform: var(--th-transform, uppercase);
}
.lb-items thead th.r, .lb-items td.r { text-align: right; }
.lb-items tbody td { padding: 2.5mm 2mm; border-bottom: var(--row-border, 1px solid #e7e5e4); vertical-align: top; }
.lb-items tbody tr.z:nth-child(even) td { background: var(--zebra-bg, transparent); }
.lb-sub { font-size: 7pt; color: var(--doc-muted,#57534e); margin-top: 1mm; }
.lb-items tbody tr.lb-section td {
  font-size: 8pt; font-weight: 600; color: #1c1917; border-bottom: 0;
  padding: 3mm 2mm 1mm 1mm; letter-spacing: .02em;
}
.lb-totals { width: 85mm; margin-left: auto; font-size: 8pt; margin-top: 4mm; }
.lb-totals .t { display: flex; justify-content: space-between; padding: 1.5mm 2mm; }
.lb-totals .sep { border-top: 1px solid #d6d3d1; padding-top: 3mm; }
.lb-totals .sum { border-top: var(--totals-sum-line, 2px solid #1c1917); font-size: 11pt; font-weight: 600; padding-top: 3mm; margin-top: 1mm; }

/* Mahnung: Kostenaufstellung */
.lb-dun { width: 100%; border-collapse: collapse; margin-bottom: 6mm; font-size: 9pt; }
.lb-dun td { padding: 2.5mm 2mm; border-bottom: 1px solid var(--doc-line,#e7e5e4); }
.lb-dun td.da { text-align: right; white-space: nowrap; }
.lb-dun tr.dsum td { border-top: 2px solid var(--accent-doc,#1c1917); border-bottom: 0; font-size: 11pt; font-weight: 600; padding-top: 3mm; }
.lb-due { margin: 6mm 0; font-size: 9pt; }
.lb-due strong { font-weight: 600; }

.lb-note { margin: 0; font-size: 9pt; }
/* Footer + Trennlinie als gemeinsamer, ans Seitenende geschobener Block. */
.lb-footer-wrap { display: flex; flex-direction: column; }
/* Klickbare Trennlinien-Region zeigt das GESAMTE Element gestapelt: oberer
   Abstandsstreifen, die Trennlinie selbst und der untere Abstandsstreifen.
   Alles eine Region (footerline). Die Streifen-Höhen entsprechen den mm-Werten;
   ihre Tönung/Beschriftung erscheint – wie die übrigen Abstands-Regionen – nur
   on hover/aktiv (siehe Overlay-Regeln weiter unten). */
.lb-footerline { box-sizing: border-box; display: flex; flex-direction: column; }
.lb-footerline-gap {
  box-sizing: border-box; min-height: 14px;
  display: flex; align-items: center; justify-content: center;
}
/* Die eigentliche Trennlinie ist echter Beleg-Inhalt → immer sichtbar. */
.lb-footerline-rule { border-top: 1px solid var(--doc-line, #e7e5e4); }
.lb-doc-footer {
  padding-top: var(--footer-top-sp, 3mm);
  /* Footer-Schriftgröße: eigene Footer-Größe (0 = erbt Basis --fs). Spiegelt
     die Auflösung in render_layout_columns_html (footer): footer_size_pt > Basis;
     spalteneigene Größen überschreiben per Inline-Style. */
  font-size: var(--footer-fs, var(--fs, 9pt)); line-height: 1.65; color: var(--doc-muted,#57534e); display: flex; gap: 6mm;
}
.lb-doc-footer .lb-fcol { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.lb-doc-footer .lb-fcol b { color: var(--doc-text,#1c1917); font-weight: 600; }

/* Spalten-Header/Footer (Phase 2) – Vorschau */
.lb-doc-header { padding: 0; }
.lb-doc-header--cols { text-align: left; padding: 0; }
.lb-cols { display: flex; width: 100%; align-items: flex-start; }
.lb-cols-head { gap: 6mm; padding: 0; }
.lb-cols-head .lb-ccell { padding: 0; }
.lb-cols-head .lb-ccell { font-size: var(--fs, 9pt); line-height: 1.5; color: var(--doc-text,#1c1917); }
.lb-cols-foot { gap: 6mm; }
.lb-ccell { min-width: 0; overflow-wrap: anywhere; box-sizing: border-box; }
.lb-ccell b { color: var(--doc-text,#1c1917); font-weight: 600; }
.lb-ccell img { max-width: 100%; height: auto; }

/* Spalten-/Kachel-Editor (Inspector) — je Element eine Sub-Karte */
.lb-colcard .lb-colhint { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin-bottom: 10px; }
.lb-colrows { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.lb-colempty { font-size: 12px; color: var(--text-muted); font-style: italic; padding: 4px 0; }
/* Karte ohne Box-Chrome: kein Hintergrund, kein Padding rundum, kein Radius.
   Nur eine Trennlinie oben + vertikaler Rhythmus via gap/padding-top. */
.lb-colitem {
  border-top: 1px solid var(--border); padding-top: 14px; background: none;
  display: flex; flex-direction: column; gap: 10px;
}
.lb-colitem.lb-dragging { opacity: .5; }
.lb-colitem-head { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.lb-colitem-num { font-size: 12px; font-weight: 700; color: var(--text); flex: 1 1 auto; }
/* Aktionen rechtsbündig: zuerst Papierkorb, dann Drag-Handle. */
.lb-colitem-actions { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; margin-left: auto; }
.lb-coldrag {
  flex: 0 0 auto; width: 24px; height: 28px; border: none; background: transparent; cursor: grab;
  color: var(--text-muted); font-size: 15px; line-height: 1; padding: 0; border-radius: 6px;
}
.lb-coldrag:hover:not(:disabled) { background: rgba(0,0,0,.05); color: var(--text); }
.lb-coldrag:active { cursor: grabbing; }
.lb-coldrag:disabled { opacity: .35; cursor: default; }
/* Typ-Label unter der Kopfzeile — eigenständiger, linksbündiger Tag. */
.lb-coltype {
  align-self: flex-start; font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 4px 10px; border-radius: 2px; background: rgba(8,145,178,.10); color: var(--accent-hover, #0e7490);
}
.lb-coltype--logo { background: rgba(180,83,9,.10); color: #b45309; }
.lb-coltype--empty { background: rgba(0,0,0,.05); color: var(--text-muted); }

/* Ausrichtungs-Segment (Radio mit Icons) */
.lb-seg2 { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; flex: 0 0 auto; }
.lb-seg2-btn {
  border: none; background: var(--surface, #fff); cursor: pointer; padding: 5px 8px; line-height: 0;
  color: var(--text-muted); border-left: 1px solid var(--border);
}
.lb-seg2-btn:first-child { border-left: none; }
.lb-seg2-btn svg { fill: currentColor; display: block; }
.lb-seg2-btn.is-on { background: var(--accent, #0891b2); color: #fff; }
.lb-seg2-btn:hover:not(.is-on):not(:disabled) { background: rgba(8,145,178,.08); }
.lb-seg2-btn:disabled { opacity: .4; cursor: default; }

/* Breiten-Slider (eigene Optik statt Browser-Default) */
.lb-colw-lab { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text-muted); margin: 0; }
.lb-colw-cap { flex: 0 0 auto; }
.lb-colw-lab .lb-colw { flex: 1 1 auto; min-width: 0; }
.lb-colw-val { flex: 0 0 auto; width: 40px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
input[type="range"].lb-colw {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 999px;
  background: var(--border-strong, #d6d3d1); outline: none; padding: 0;
}
input[type="range"].lb-colw::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent, #0891b2); cursor: pointer; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
input[type="range"].lb-colw::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent, #0891b2); cursor: pointer; border: 2px solid #fff;
}
input[type="range"].lb-colw:disabled { opacity: .45; }

/* Eine kompakte Icon-Zeile unter Textfeld + Platzhaltern: Ausrichtung + B/I +
   Farbe nebeneinander (bricht nur bei sehr schmaler Breite um). */
/* Icon-Zeile: Ausrichtung + B/I links, Farb-Swatch rechts (margin-left:auto). */
.lb-colctrls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; margin-top: 0; }
.lb-colctrls .lb-seg2 { flex: 0 0 auto; }
.lb-colctrls .lb-colcolor { margin: 0 0 0 auto; }

/* Format-Segment (B/I) — Optik wie das Ausrichtungs-Segment, aber Aktions- statt
   Radio-Buttons. B fett, I kursiv. */
.lb-fmtbtn { min-width: 30px; font-size: 13px; line-height: 1; }
.lb-fmtbtn b { font-weight: 800; }
.lb-fmtbtn i { font-style: italic; }

/* Range-Slider-Feld (Breiten in %, 0 = auto) — Regler + Live-Wertanzeige. */
.lb-rangerow { display: flex; align-items: center; gap: 10px; }
.lb-rangerow input[type="range"] { flex: 1 1 auto; min-width: 0; }
.lb-rangeval { flex: 0 0 auto; min-width: 42px; text-align: right; font-weight: 700; font-size: 13px; }

/* Schriftgröße als eigene, volle Zeile darunter (Label oben, Eingabe über die
   ganze Breite — wie die übrigen Felder, nicht mehr eng inline). */
.lb-colsizerow { display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin: 0; font-size: 11px; color: var(--text-muted); }
.lb-colsizerow-cap { font-weight: 600; }
.lb-colsizerow-hint { font-weight: 400; font-style: italic; }
.lb-colsize { display: flex; align-items: center; gap: 8px; width: 100%; }
.lb-colsize .lb-colsz { flex: 1 1 auto; width: 100%; min-width: 0; }
.lb-colsize-suffix { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); }

.lb-colcolor { position: relative; display: inline-flex; align-items: center; }
.lb-colcol { width: 30px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 50%; cursor: pointer; -webkit-appearance: none; appearance: none; }
.lb-colcol::-webkit-color-swatch-wrapper { padding: 0; }
.lb-colcol::-webkit-color-swatch { border: none; border-radius: 50%; }
.lb-colcol::-moz-color-swatch { border: none; border-radius: 50%; }
.lb-colcol:disabled { opacity: .4; cursor: default; }
/* Ungesetzt: neutraler grauer Punkt über dem Swatch (Klick geht durch → setzt). */
.lb-colcolor:not(.is-on)::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: #d6d3d1; border: 1px solid var(--border); pointer-events: none;
}
.lb-colcol-clear {
  display: none; position: absolute; top: -6px; right: -6px; width: 16px; height: 16px;
  padding: 0; border: 1px solid var(--border); border-radius: 50%; background: #fff;
  color: var(--text-muted); font-size: 11px; line-height: 1; cursor: pointer;
}
.lb-colcolor.is-on .lb-colcol-clear { display: inline-flex; align-items: center; justify-content: center; }

.lb-addrow { display: flex; flex-wrap: wrap; gap: 8px; }
.lb-textarea { width: 100%; min-height: 40px; resize: vertical; font-family: inherit; font-size: 13px; line-height: 1.45; box-sizing: border-box; }
.lb-textarea.auto-grow { resize: none; overflow: hidden; }

/* Platzhalter (einklappbar) */
.lb-chips-det { margin-top: 8px; }
.lb-chips-sum {
  font-size: 11px; color: var(--accent-hover, #0e7490); cursor: pointer; list-style: none;
  display: inline-flex; align-items: center; gap: 4px; user-select: none;
}
.lb-chips-sum::-webkit-details-marker { display: none; }
.lb-chips-sum::before { content: '▸'; font-size: 9px; }
.lb-chips-det[open] .lb-chips-sum::before { content: '▾'; }
.lb-chips-det .lb-chips { margin-top: 6px; }

/* „Alle Platzhalter anzeigen" — sekundärer, dezenterer Toggle unter dem
   kontextbezogenen Set. */
.lb-chips-all { margin-top: 8px; }
.lb-chips-allsum {
  font-size: 11px; color: var(--text-muted, #57534e); cursor: pointer; list-style: none;
}
.lb-chips-allsum::-webkit-details-marker { display: none; }
.lb-chips-allsum::before { content: '▸'; font-size: 9px; margin-right: 2px; }
.lb-chips-all[open] .lb-chips-allsum::before { content: '▾'; }

/* Meta-Repeater — zweizeilig (Label/Wert untereinander), per ⠿ sortierbar */
.lb-metarow {
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--surface-2, #faf9f8);
}
.lb-metarow.lb-dragging { opacity: .5; }
.lb-metarow-head { display: flex; align-items: center; gap: 6px; }
.lb-metarow-sp { flex: 1 1 auto; }
.lb-metarow .lb-metaf { width: 100%; min-width: 0; box-sizing: border-box; }
.lb-metacard .lb-chips-det { margin: 4px 0 10px; }

/* Platzhalter-Chips */
.lb-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lb-chip {
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--border); background: var(--surface, #fff); color: var(--accent-hover, #0e7490);
  border-radius: 999px; padding: 2px 8px; cursor: pointer; line-height: 1.4;
}
.lb-chip:hover { border-color: var(--accent, #0891b2); background: rgba(8,145,178,.06); }
.lb-chip.is-scoped { border-style: dashed; }
.lb-chip-scope { font-size: 9px; color: var(--text-muted); margin-left: 1px; }
/* Formatierungs-Button (Fett) hebt sich von den Platzhaltern ab. */
.lb-chip-fmt { color: var(--text, #1c1917); background: var(--surface-2, #f5f5f4); }
.lb-chip-fmt b { font-weight: 700; }

/* ============================================================
 * Einheitliches Platzhalter-Popup (placeholder-picker.js)
 * ============================================================ */
.ph-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.ph-trigger {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; line-height: 1.4;
  border: 1px solid var(--border); background: var(--surface, #fff);
  color: var(--accent-hover, #0e7490);
  border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.ph-trigger:hover { border-color: var(--accent, #0891b2); background: rgba(8,145,178,.06); }
.ph-trigger svg { opacity: .8; }

/* Globaler Floating-Button (Kreis mit {}) — immer verfügbar, fix am Rand. */
.ph-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 5990;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent, #0891b2); color: #fff;
  border: none; cursor: pointer; padding: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.ph-fab:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,0,0,.22); background: var(--accent-hover, #0e7490); }
.ph-fab:active { transform: translateY(0); }
.ph-fab.is-open { background: var(--accent-hover, #0e7490); }
.ph-fab.is-warn { animation: ph-fab-warn .6s ease; }
@keyframes ph-fab-warn {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
@media (max-width: 640px) {
  .ph-fab { right: 14px; bottom: 14px; width: 42px; height: 42px; }
}

/* Popover */
.ph-pop {
  position: fixed; z-index: 6000; width: 320px; max-width: calc(100vw - 16px);
  background: var(--surface, #fff); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.16);
  display: flex; flex-direction: column; overflow: hidden;
}
.ph-pop-head { padding: 8px; border-bottom: 1px solid var(--border); background: var(--surface-2, #f8f8f7); }
.ph-pop-search {
  width: 100%; box-sizing: border-box; font-size: 13px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  background: var(--surface, #fff); color: var(--text, #1c1917);
}
.ph-pop-search:focus { outline: none; border-color: var(--accent, #0891b2); }
.ph-pop-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; max-height: min(360px, 62vh); padding: 8px; }
.ph-group { margin-bottom: 12px; }
.ph-group:last-child { margin-bottom: 0; }
.ph-group-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-subtle, #a8a29e); padding: 4px 8px 6px;
}
.ph-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; box-sizing: border-box; text-align: left; cursor: pointer;
  border: 0; background: none; border-radius: 8px; padding: 9px 10px;
  font-family: inherit;
}
.ph-item + .ph-item { margin-top: 2px; }
.ph-item:hover { background: var(--accent-soft, rgba(8,145,178,.1)); }
.ph-item[hidden], .ph-group[hidden] { display: none; }
.ph-item-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ph-item-label { font-size: 12.5px; line-height: 1.35; color: var(--text, #1c1917); }
.ph-item-token {
  font-size: 10.5px; line-height: 1.3; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent-hover, #0e7490);
}
.ph-item-ex {
  font-size: 10.5px; line-height: 1.3; color: var(--text-subtle, #a8a29e); white-space: nowrap;
  max-width: 42%; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto;
}
.ph-item-scope { font-size: 9px; color: var(--text-muted); margin-left: 1px; }
.ph-pop-empty { font-size: 12px; color: var(--text-subtle); padding: 14px 8px; text-align: center; }

/* ============================================================
 * Eigene Platzhalter (Einstellungen)
 * ============================================================ */
.customph-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.customph-row { display: flex; align-items: flex-start; gap: 8px; }
.customph-keywrap {
  display: inline-flex; align-items: center; gap: 1px; flex: 0 0 170px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.customph-brace { color: var(--text-subtle, #a8a29e); font-size: 14px; }
.customph-key {
  width: 100%; min-width: 0; box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 8px;
  background: var(--surface, #fff); color: var(--text, #1c1917);
}
.customph-key:focus { outline: none; border-color: var(--accent, #0891b2); }
.customph-val {
  flex: 1 1 auto; min-width: 0; box-sizing: border-box; resize: vertical;
  font-size: 13px; line-height: 1.5;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  background: var(--surface, #fff); color: var(--text, #1c1917);
}
.customph-val:focus { outline: none; border-color: var(--accent, #0891b2); }
.customph-del { flex: 0 0 auto; font-size: 16px; line-height: 1; padding: 6px 10px; }
@media (max-width: 560px) {
  .customph-row { flex-wrap: wrap; }
  .customph-keywrap { flex-basis: 100%; }
}

/* Vorlagen-Toolbar (Layout-/Vorlagen-Seite) */
.lb-tplbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.lb-tplsel { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); font-weight: 500; margin: 0; }
.lb-tplsel select { min-width: 240px; }
.lb-tplbtns { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lb-tplbtns .btn[disabled] { opacity: .45; cursor: default; }

.lb-colrm {
  width: 28px; height: 28px; border: 1px solid var(--border); background: var(--surface, #fff);
  border-radius: 6px; cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; padding: 0; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
}
.lb-colrm svg { display: block; fill: currentColor; }
.lb-colrm:hover:not(:disabled) { border-color: #ef4444; color: #ef4444; }
.lb-colrm:disabled { opacity: .4; cursor: default; }
.lb-addcol { font-size: 13px; }
.lb-empty-hint { font-size: 7pt; color: var(--doc-muted, #57534e); font-style: italic; opacity: .6; }
/* Geist-Platzhalter für ausgeblendete Elemente (nur Editor, nie im PDF): bleibt
   anklickbar, damit man das Element wieder einblenden kann. Dezent gestrichelt. */
.lb-ghost {
  min-height: 7mm; display: flex; align-items: center; justify-content: center;
  outline: 1px dashed rgba(120,113,108,.4); outline-offset: -1px; border-radius: 2px;
}
.lb-ghost .lb-empty-hint { opacity: .75; }

/* Inspector (rechte Spalte) */
.lb-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.lb-hint a { color: var(--accent-hover); text-decoration: none; }
.lb-hint a:hover { text-decoration: underline; }
.lb-reset {
  display: none; margin-top: 8px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--accent, #0891b2); background: rgba(8,145,178,.06); color: var(--accent-hover, #0e7490);
  border-radius: 6px; padding: 5px 12px; cursor: pointer;
}
.lb-reset:hover { background: rgba(8,145,178,.12); }
.lb-hint.has-filter .lb-reset { display: inline-block; }
.lb-side .contact-tabs {
  flex-direction: row; flex-wrap: wrap; position: static; gap: 6px;
  margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 12px;
}
.lb-side .contact-tab { border: 1px solid var(--border); }
.lb-side .card { max-width: none !important; }
@media (max-width: 1100px) { .lb-canvas { justify-content: center; } }
