:root {
  /* HPS Corporate Design: Orange / Grau / Schwarz / Weiß */
  --bg: #f5f5f5;
  --panel: #ffffff;
  --border: #e0e0e0;
  --text: #333333;
  --muted: #777777;
  --primary: #de800e;          /* HPS Orange */
  --primary-dark: #af6005;     /* Orange Hover/Dark */
  --primary-accent: #de800e;   /* Orange dezent */
  --success: #4d8c3a;
  --warn: #d48806;
  --danger: #b52c2c;
  --sidebar-bg: #222222;       /* fast schwarz */
  --sidebar-text: #bdbdbd;
  --sidebar-active: #333333;
  --sidebar-hover: #2c2c2c;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary-accent); text-decoration: none; }
a:hover { color: var(--primary); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .75rem 0; color: #222; }
h1 { font-size: 1.5rem; }
.page-head h1 { font-size: 2rem; margin: 0 0 .25rem; line-height: 1.15; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.warn { color: var(--warn); font-weight: 600; }

/* App-Shell */
.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
body.fullscreen .app { grid-template-columns: 1fr; }
body.fullscreen .sidebar { display: none; }
body.fullscreen .main { padding: 0; }
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 1rem 0;
  position: sticky; top: 0;
  height: 100vh; max-height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: .25rem 1.25rem 1rem; border-bottom: 1px solid #1e293b; }
.sidebar .brand .brand-image { display: block; width: 100%; max-width: 240px; height: auto; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--primary); color: white; display: grid; place-items: center; font-weight: 700;
}
.brand-logo.lg { width: 56px; height: 56px; font-size: 1.25rem; }
.brand-name { color: white; font-weight: 600; }
.sidebar nav { display: flex; flex-direction: column; padding: .5rem 0; flex: 1; }
.nav-item { display: block; padding: .7rem 1.5rem; font-size: .92rem; color: var(--sidebar-text); border-left: 3px solid transparent; }
.nav-item:hover { background: var(--sidebar-hover); color: white; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: white; border-left-color: var(--primary); }
.nav-divider {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem 1.5rem .5rem;
  font-size: .75rem; letter-spacing: .05em; text-transform: uppercase; color: #888;
}
.nav-divider::before, .nav-divider::after {
  content: ""; flex: 1; height: 1px; background: rgba(255,255,255,.07);
}
.nav-separator { height: 1px; background: rgba(255,255,255,.07); margin: .6rem 1.5rem; }
.nav-bottom { margin-top: auto; padding-bottom: 1.25rem; }

.brand { border-bottom-color: #333; }

.sidebar-user { padding: 1rem 1.25rem; border-top: 1px solid #333; display: flex; justify-content: space-between; align-items: center; }
.user-name { color: white; font-weight: 500; }
.user-role { font-size: .75rem; color: #999; }

.main { padding: 1.5rem 2rem; overflow-x: hidden; }

/* Login */
.login-body {
  background:
    linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)),
    url('/images/bauarbeiterl.jpg') center/cover no-repeat fixed;
  min-height: 100vh;
}
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  background: rgba(95,95,95,.78);
  color: #f0f0f0;
  padding: 2.75rem 3rem;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  width: 100%; max-width: 560px;
}
.login-card label { color: rgba(255,255,255,.92); font-size: .95rem; margin-bottom: 1.1rem; }
.login-card .btn-block { margin-top: 1.5rem; padding: .75rem 1rem; font-size: 1rem; }
.login-help {
  margin: 1.25rem 0 0; text-align: center;
  font-size: .8rem; color: rgba(255,255,255,.7);
}
.login-help a { color: #f0a35a; text-decoration: none; }
.login-help a:hover { text-decoration: underline; }
.login-brand { text-align: center; margin-bottom: 2.25rem; }
.login-brand .brand-image {
  display: block; margin: 0 auto; width: 100%; max-width: 460px; height: auto;
}

/* Passwort-Feld mit Auge-Toggle */
.password-field { position: relative; display: block; }
.password-field input { width: 100%; padding-right: 2.75rem; }
.password-toggle {
  position: absolute; top: 50%; right: .5rem; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0;
  background: transparent; border: none; cursor: pointer;
  color: #888; border-radius: 4px;
}
.password-toggle:hover { color: #555; background: rgba(0,0,0,.05); }
.password-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle.is-shown .icon-eye { display: none; }
.password-toggle.is-shown .icon-eye-off { display: inline; }

/* Pflichtfeld-Stern */
.req { color: #d92d20; font-weight: 700; margin-left: .2rem; font-size: .95em; line-height: 1; }
.login-card .req { color: #ff7a6b; }

/* Eigene Feld-Validierung (Formulare mit [data-custom-validate]) */
.field-error {
  display: none; align-items: center; gap: .35rem;
  margin-top: .4rem; font-size: .78rem; line-height: 1.3;
  color: #d92d20; font-weight: 500;
}
.field-error.is-visible { display: flex; }
.field-error svg { flex: 0 0 auto; }
.is-invalid, input.is-invalid, select.is-invalid, textarea.is-invalid {
  border-color: #d92d20;
  box-shadow: 0 0 0 3px rgba(217,45,32,.15);
}
.is-invalid:focus, input.is-invalid:focus { outline-color: #d92d20; border-color: #d92d20; }
.login-card .field-error { color: #ffb4a8; }
.login-card .is-invalid { box-shadow: 0 0 0 3px rgba(255,122,107,.28); }

/* Sanftes Wackeln, wenn das Absenden an Pflichtfeldern scheitert */
@keyframes form-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.is-shaking { animation: form-shake .5s cubic-bezier(.36,.07,.19,.97) both; }
@media (prefers-reduced-motion: reduce) { .is-shaking { animation: none; } }

/* Page-head */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.page-head .actions select { width: auto; }

/* System-Log: Export-Popover */
.log-export { position: relative; display: inline-block; }
.log-export-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  width: 250px; padding: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.14);
  display: flex; flex-direction: column; gap: 10px;
}
.log-export-pop[hidden] { display: none; }
.log-export-pop .log-export-title { font-weight: 600; }
.log-export-pop label { display: block; }
.log-export-pop .label-text { display: block; font-size: .8rem; color: var(--muted, #6b7280); margin-bottom: 2px; }
.log-export-pop input[type="date"] { width: 100%; }
.page-head-3col { align-items: center; }
.page-head-3col > h1 { margin: 0; flex: 0 0 auto; }
.page-head-search { flex: 1 1 320px; max-width: 520px; margin: 0 auto; display: flex; gap: .5rem; align-items: stretch; }
.page-head-search input[type="search"] { flex: 1 1 auto; }
@media (max-width: 800px) {
  .page-head-search { max-width: none; margin: 0; }
}

/* Card */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  color: var(--text);
  box-shadow: var(--shadow);
}
.tile:hover { text-decoration: none; background: #fafbfc; }
.tile-num { font-size: 1.8rem; font-weight: 600; color: var(--primary); }
.tile-label { color: var(--muted); font-size: .8rem; margin-top: .25rem; }
.tile.warn .tile-num { color: var(--warn); }

/* Grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem 1rem; }
.form-grid.compact { gap: .5rem; }
.form-grid label, label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }

input, select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--border);
  border-radius: 6px; font: inherit; background: white; color: var(--text);
}
input[type="checkbox"], input[type="radio"] {
  width: auto; padding: 0; margin: 0; flex: 0 0 auto;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; font-family: inherit; }

.inline-form { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.inline-form label { flex-direction: row; align-items: center; gap: .25rem; }
.inline-form input, .inline-form select { width: auto; }

.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* Buttons */
.btn {
  display: inline-block;
  padding: .45rem .9rem; border: 1px solid var(--border); background: white; color: var(--text);
  border-radius: 6px; cursor: pointer; font: inherit; text-decoration: none;
}
.btn:hover { background: #f5f6f8; text-decoration: none; }
.btn-sm { padding: .25rem .55rem; font-size: .85rem; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }
.btn-danger { background: white; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--sidebar-text); }
.btn-ghost:hover { background: var(--sidebar-active); color: white; }
.btn-logout {
  border-color: transparent; background: transparent;
  color: #f08a8a; border-radius: 6px; transition: background .15s, color .15s;
}
.btn-logout:hover {
  background: rgba(220,53,69,.18); color: #ff8585;
  border-color: rgba(220,53,69,.35);
}
.btn-block { display: block; width: 100%; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .65rem .5rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-weight: 600; color: var(--muted); background: #f9f9f9; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
.table.compact th, .table.compact td { padding: .35rem .4rem; }
.table tbody tr:hover { background: #fafafa; }
.table .right { text-align: right; }

/* Badges */
.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 99px;
  font-size: .75rem; background: #ebebeb; color: #444; margin-right: .2rem;
}
.badge-success, .badge-paid, .badge-done, .badge-completed, .badge-accepted, .badge-shipped, .badge-delivered { background: #e4f0da; color: #3d6b2d; }
.badge-danger, .badge-overdue, .badge-rejected, .badge-cancelled, .badge-scrapped { background: #f5d5d5; color: #8a1f1f; }
.badge-warn, .badge-expired, .badge-paused, .badge-partially_paid, .badge-waiting_parts, .badge-returned, .badge-partially_received { background: #fff0d6; color: #8a5a00; }
.badge-received { background: #e4f0da; color: #3d6b2d; }
.badge-info, .badge-sent, .badge-in_progress, .badge-in_production, .badge-confirmed, .badge-released { background: #ffe4c7; color: #af6005; }
.badge-draft, .badge-planned, .badge-open, .badge-in_stock { background: #ebebeb; color: #555; }
.badge-reserved { background: #ffd9a8; color: #af6005; }
.badge-aktiv { background: #e4f0da; color: #3d6b2d; }
.badge-abgelaufen, .badge-widerrufen { background: #f5d5d5; color: #8a1f1f; }
.badge-eingelöst { background: #ffe4c7; color: #af6005; }

/* Verifikations-Code-Input */
.verify-code {
  font-size: 1.6rem; letter-spacing: .5rem; text-align: center;
  font-family: ui-monospace, monospace; padding: .6rem;
}

/* Flash */
.flash { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-success { background: #e4f0da; color: #3d6b2d; border-color: #c8e0b3; }
.flash-error { background: #f5d5d5; color: #8a1f1f; border-color: #e8b5b5; }
.flash-info { background: #fff0d6; color: #af6005; border-color: #ffd9a8; }
/* Login-Fehlermeldung passend zur dunklen Karte (muss nach .flash-error stehen) */
.login-flash {
  display: flex; align-items: center; gap: .6rem;
  background: rgba(158,32,32,.42); color: #ffe3de;
  border-color: rgba(255,138,122,.55);
  backdrop-filter: blur(2px);
}
.login-flash svg { flex: 0 0 auto; color: #ff9c8c; }
.flash-link { color: inherit; font-weight: 700; text-decoration: underline; margin-left: .35rem; }
/* Vorlage-Übernahme beim Anlegen */
.copy-from { background: #fafbfc; }

/* Dokumente: Liste mit Aktionen + Vorschau-Modal */
.doc-item { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; padding: .15rem 0; }
.doc-name { cursor: pointer; }
.doc-actions { display: inline-flex; gap: .15rem; margin-left: auto; }
.doc-actions .icon-btn { width: 30px; height: 30px; }
.doc-actions .inline-form { display: inline-flex; }
.doc-preview-card { max-width: 920px; width: 95vw; }
.doc-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 1.75rem .75rem 0; }
.doc-preview-head h3 { margin: 0; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-preview-body { background: #f1f3f5; border: 1px solid var(--border); border-radius: 8px; overflow: auto; }
.doc-preview-body iframe { width: 100%; height: 75vh; border: 0; display: block; }
.doc-preview-body img { display: block; max-width: 100%; max-height: 75vh; margin: 0 auto; }

/* KV list */
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem 1rem; }
.kv > div { display: flex; flex-direction: column; gap: 2px; }
.kv > .kv-wide { grid-column: 1 / -1; }
.kv b { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }

.conditions-panel {
  margin-top: 1rem;
  padding: .75rem .9rem;
  background: #f6f7f9;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.conditions-panel h4 {
  margin: 0 0 .5rem;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

/* Totals */
.totals { display: flex; justify-content: flex-end; gap: 1.5rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.totals.right { justify-content: flex-end; }

/* Items editor */
.items-editor { overflow-x: auto; }
.items-table { min-width: 720px; }
.items-table input { padding: .35rem .45rem; font-size: .9rem; }
.items-table td { vertical-align: middle; }
/* Zahlenfelder komfortabel breit (Menge, Nettopreis, Rabatt, MwSt) */
.items-table input[type="number"] { width: 5rem; }
.items-table input[name="item_discount_percent"],
.items-table input[name="item_tax_rate"] { width: 5rem; }
.items-table [data-total] { font-size: 1rem; font-weight: 700; white-space: nowrap; }

/* Address / contact blocks */
.address-block, .contact-block {
  border: 1px solid var(--border); border-radius: 6px; padding: .6rem; margin-bottom: .5rem; background: #fafbfc;
}
.address-label { margin-bottom: .4rem; font-size: .85rem; }

/* Documents */
.doc-list { list-style: none; padding: 0; }
.doc-list li { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.doc-list li:last-child { border-bottom: none; }

/* Seriennummern */
.sn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .3rem; margin-top: .5rem; }
.sn { background: #f3f4f6; border: 1px solid var(--border); padding: .25rem .5rem; border-radius: 4px; font-family: monospace; font-size: .8rem; }

/* Permissions grid */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .25rem; }
.perm-grid label { padding: .25rem; }
.perm-grid code { font-size: .75rem; color: var(--primary-accent); }

/* Gruppierte Berechtigungsliste */
.perm-group {
  border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem 1rem 1rem; margin: 0 0 1rem;
}
.perm-group legend {
  font-weight: 600; font-size: .9rem;
  padding: 0 .5rem; display: inline-flex; align-items: center; gap: .5rem;
}
.perm-toggle-all {
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  padding: .15rem .5rem; font-size: .7rem; cursor: pointer; color: var(--muted);
}
.perm-toggle-all:hover { background: rgba(0,0,0,.04); color: var(--text); }
.perm-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: .25rem .75rem;
}
.perm-item {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .5rem .65rem; border-radius: 6px; cursor: pointer;
  transition: background .12s;
}
.perm-item:hover { background: rgba(0,0,0,.03); }
.perm-item input[type="checkbox"] { margin-top: .2rem; flex: 0 0 auto; }
.perm-text { display: flex; flex-direction: column; line-height: 1.3; }
.perm-text strong { font-weight: 500; font-size: .9rem; color: var(--text); }
.perm-text code { font-size: .7rem; color: var(--muted); margin-top: .1rem; }

/* Benutzerzeile anklickbar (öffnet die Profilvorschau) */
.user-row { cursor: pointer; }
.user-row:hover { background: rgba(0,0,0,.03); }
.user-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.user-link { color: var(--primary); font-weight: 600; }
.user-row:hover .user-link { text-decoration: underline; }
.user-row-chevron { display: inline-flex; color: var(--muted); transition: transform .15s ease; }
.user-row[aria-expanded="true"] .user-row-chevron { transform: rotate(90deg); }

/* Profil-Detail – aufklappbare Zeile über die volle Tabellenbreite */
.user-detail-row > td {
  background: #f9fafb;
  padding: 1.1rem 1.25rem 1.25rem;
  box-shadow: inset 0 2px 0 var(--primary);
}
/* Profilvorschau (nur lesen) */
.user-preview-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .8rem 1.5rem; margin: 0 0 1.1rem;
}
.user-preview-grid > div { display: flex; flex-direction: column; gap: .15rem; }
.user-preview-grid dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.user-preview-grid dd { margin: 0; color: var(--text); }
.user-edit-head { display: flex; align-items: center; gap: .7rem; margin-bottom: 1rem; }
.user-edit-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .95rem;
}
.user-edit-head strong { display: block; line-height: 1.2; }
.user-edit-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .8rem 1rem; align-items: end;
}
.user-edit-status { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.user-edit-status .checkbox { margin-top: .3rem; }
.user-edit-roles { grid-column: 1 / -1; display: flex; flex-direction: column; gap: .4rem; font-size: .85rem; color: var(--muted); }
.role-checks { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; }
.role-checks .checkbox { color: var(--text); font-size: .9rem; }
.user-edit-actions { display: flex; gap: .5rem; margin-top: 1.1rem; }
.user-row-view { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.user-row:hover .user-row-view { color: var(--primary); }

/* Discord-artige Profilkarte (Modal) – Benutzerliste */
.uprofile-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.uprofile-modal[hidden] { display: none; }
.profile-backdrop { position: absolute; inset: 0; background: rgba(17,17,20,.55); }
.profile-card {
  position: relative; width: 600px; max-width: 100%; max-height: 92vh; overflow-y: auto;
  background: #fff; border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.4);
  animation: profilePop .16s ease-out;
}
@keyframes profilePop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bannerShift { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }
.profile-banner {
  height: 168px; border-radius: 18px 18px 0 0; position: relative;
  background-image: linear-gradient(120deg, var(--primary), var(--primary-dark), var(--primary));
  background-size: 220% 100%;
  animation: bannerShift 7s ease-in-out infinite alternate;
}
.profile-banner.has-image {
  background-size: cover; background-position: center; background-repeat: no-repeat;
  animation: none;
}
.profile-iconbtn {
  position: absolute; top: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: rgba(0,0,0,.32); color: #fff; cursor: pointer; display: grid; place-items: center;
  transition: background .12s;
}
.profile-iconbtn:hover { background: rgba(0,0,0,.55); }
.profile-x { left: 14px; }
.profile-gear { right: 14px; }
.profile-avatar {
  position: absolute; top: 110px; left: 26px;
  width: 108px; height: 108px; border-radius: 50%;
  background: var(--primary); color: #fff;
  border: 7px solid #fff; box-sizing: content-box;
  display: grid; place-items: center; font-size: 2.9rem; font-weight: 700; line-height: 1;
}
/* Präsenz-Punkt (online/abwesend/offline) unten rechts am Avatar */
.profile-dot {
  position: absolute; right: 4px; bottom: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  border: 5px solid #fff; box-sizing: border-box;
}
.profile-dot.is-online  { background: #23a55a; }
.profile-dot.is-away    { background: #f0b232; }
.profile-dot.is-offline { background: #80848e; }
.profile-body { padding: 72px 26px 26px; }
.profile-name { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1.15; }
.profile-handle { color: var(--muted); font-size: 1rem; margin-top: .2rem; }
.profile-divider { height: 1px; background: var(--border); margin: 1.15rem 0; }
.profile-section { margin-bottom: 1.25rem; }
.profile-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: .6rem; }
.profile-roles { display: flex; flex-wrap: wrap; gap: .45rem; }
.role-pill {
  background: #eef0f3; color: #3a3f45; border-radius: 6px; padding: .28rem .65rem;
  font-size: .88rem; font-weight: 600; display: inline-flex; align-items: center; gap: .4rem;
}
.role-pill::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.role-pill-admin { background: rgba(222,128,14,.15); }
.role-pill-admin::before { background: var(--primary); }
.role-pill-cevio { background: rgba(138,103,255,.16); }
.role-pill-cevio::before { background: #8a67ff; }
.profile-info { margin: 0; display: flex; flex-direction: column; gap: .55rem; }
.profile-info > div { display: flex; justify-content: space-between; gap: 1rem; }
.profile-info dt { color: var(--muted); font-size: .92rem; }
.profile-info dd { margin: 0; color: var(--text); font-size: .92rem; text-align: right; word-break: break-word; }
.profile-status.is-active { color: #1a9e56; font-weight: 700; }
.profile-status.is-inactive { color: var(--muted); font-weight: 600; }
.profile-edit-title { font-size: 1.25rem; margin-bottom: 1rem; }
.profile-card .user-edit-grid { grid-template-columns: 1fr; }

/* Riesiges Deko-Zahnrad oben rechts auf der Einstellungen-Seite (im Hintergrund) */
.settings-gear {
  position: fixed;
  top: -12vh; right: -9vw;
  width: min(88vh, 860px); height: min(88vh, 860px);
  color: var(--primary);
  opacity: .11;
  z-index: -1;
  pointer-events: none;
}
.settings-gear svg { width: 100%; height: 100%; display: block; }
@media (max-width: 900px) { .settings-gear { opacity: .08; width: 88vw; height: 88vw; } }

/* Legal-Pages (Datenschutz, Impressum) */
body.legal-body { background: #f5f5f5; }
.legal-wrap { min-height: 100vh; padding: 2rem 1rem; }
.legal-article {
  max-width: 800px; margin: 0 auto; background: white;
  padding: 2.5rem 3rem; border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  line-height: 1.6;
}
.legal-article h1 { font-size: 2rem; margin: 0 0 .5rem; }
.legal-article h2 { font-size: 1.25rem; margin: 2rem 0 .5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.legal-article h2:first-of-type { border-top: 0; padding-top: 0; }
.legal-article ul { padding-left: 1.25rem; }
.legal-article li { margin-bottom: .35rem; }
.legal-article code { font-size: .85rem; background: #f5f5f5; padding: .1rem .35rem; border-radius: 3px; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: .5rem; height: 220px; padding: 1rem 0; }
.chart-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; }
.chart-bar .bar { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.chart-bar .bar-fill { background: var(--primary); width: 100%; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; }
.chart-bar:hover .bar-fill { background: var(--primary-dark); }
.bar-label { font-size: .75rem; color: var(--muted); }
.bar-value { font-size: .7rem; color: var(--muted); }

/* Details/Summary as button */
details { margin-top: .5rem; }
details summary { cursor: pointer; user-select: none; list-style: none; display: inline-block; }
details summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: .5rem; }

/* Sidebar User-Trigger + Avatar */
.user-trigger {
  display: flex; align-items: center; gap: .75rem;
  flex: 1; min-width: 0;
  background: transparent; border: 0; padding: .35rem .5rem; margin: -.35rem -.5rem;
  cursor: pointer; color: inherit; text-align: left; font: inherit;
  border-radius: 8px; transition: background .15s;
}
.user-trigger:hover { background: rgba(255,255,255,.06); }
.user-text { display: flex; flex-direction: column; min-width: 0; }
.user-text .user-name { color: white; font-weight: 500; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-text .user-role { font-size: .75rem; color: #999; line-height: 1.2; }
.user-avatar {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6a6a6a, #3a3a3a);
  display: grid; place-items: center;
  overflow: hidden;
  color: white; font-weight: 600; font-size: .9rem;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Profil-Modal */
body.modal-open { overflow: hidden; }
.profile-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem;
}
.profile-modal[hidden] { display: none; }
.profile-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.profile-modal-card {
  position: relative;
  background: var(--panel); color: var(--text);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  width: 100%; max-width: 640px;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 2rem;
}
.profile-modal-close {
  position: absolute; top: .75rem; right: 1rem;
  background: transparent; border: none;
  font-size: 1.75rem; line-height: 1; color: #888; cursor: pointer;
}
.profile-modal-close:hover { color: var(--text); }
.profile-modal-header {
  display: flex; align-items: center; gap: 1.25rem;
  margin-bottom: 1.5rem; padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.profile-modal-header h2 { margin: 0 0 .25rem; }
.profile-avatar-large {
  flex: 0 0 auto;
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, #b0b0b0, #6a6a6a);
  display: grid; place-items: center; overflow: hidden;
  color: white; font-weight: 600; font-size: 1.75rem;
}
.profile-avatar-large img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Selbst-Profil als Discord-Karte: Banner + überlappender Avatar + Vorschau/Bearbeiten */
.profile-modal-card { padding: 0; }
.profile-modal-banner {
  height: 150px; border-radius: 16px 16px 0 0; position: relative;
  background-image: linear-gradient(120deg, var(--primary), var(--primary-dark), var(--primary));
  background-size: 220% 100%;
  animation: bannerShift 7s ease-in-out infinite alternate;
}
.profile-modal-banner.has-image {
  background-size: cover; background-position: center; background-repeat: no-repeat;
  animation: none;
}
.profile-modal-x { left: 14px; }
.profile-modal-gear { right: 14px; }
/* Avatar-Wrapper: hält den weißen Ring, KEIN overflow -> der Status-Punkt liegt oben drauf */
.profile-avatar-overlap {
  position: absolute; top: 90px; left: 28px; z-index: 2;
  width: 100px; height: 100px; border: 7px solid #fff; border-radius: 50%;
  box-sizing: content-box; background: #fff;
}
.profile-avatar-overlap .profile-avatar-large {
  width: 100%; height: 100%; border: 0; background: var(--primary); font-size: 2.6rem;
}
.profile-avatar-overlap .profile-dot { z-index: 3; }
.profile-self-body { padding: 62px 2rem 2rem; }
.profile-back { margin-bottom: 1.5rem; }
.banner-preview {
  height: 90px; border-radius: 10px; margin-bottom: .6rem;
  background-image: linear-gradient(120deg, var(--primary), var(--primary-dark), var(--primary));
  background-size: 220% 100%;
  animation: bannerShift 7s ease-in-out infinite alternate;
}
.banner-preview.has-image { background-size: cover; background-position: center; background-repeat: no-repeat; animation: none; }
.profile-modal-section { margin-bottom: 1.75rem; }
.profile-modal-section:last-child { margin-bottom: 0; }
.profile-modal-section h3 { font-size: 1rem; margin: 0 0 .75rem; }
.profile-avatar-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .35rem; }
.profile-avatar-actions form { margin: 0; }
.profile-avatar-actions .btn { cursor: pointer; }
.profile-form { display: grid; gap: .75rem; }
.profile-form-meta { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: .25rem; }
.small { font-size: .8rem; }

/* Action-Icons in Listen-Zellen */
.actions-cell { white-space: nowrap; text-align: right; width: 1%; padding-right: 0 !important; }
.actions-cell > * { vertical-align: middle; }
.actions-cell .inline-form { display: inline; }
.table tr > .actions-cell:last-child { padding-right: 0 !important; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; margin-left: .25rem;
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  color: #555; cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: rgba(0,0,0,.04); color: #111; text-decoration: none; }
.icon-btn-view  { color: #2563eb; }
.icon-btn-view:hover  { background: rgba(37,99,235,.10); color: #1d4ed8; border-color: rgba(37,99,235,.4); }
.icon-btn-edit  { color: #c2780b; }
.icon-btn-edit:hover  { background: rgba(217,119,6,.10); color: #92400e; border-color: rgba(217,119,6,.4); }
.icon-btn-danger { color: #c0392b; }
.icon-btn-danger:hover { background: rgba(220,53,69,.1); color: #a02818; border-color: rgba(220,53,69,.4); }

/* Zurück-Pfeil */
.back-link {
  display: inline-flex; align-items: center; gap: .3rem;
  color: var(--muted); text-decoration: none; font-size: .85rem;
  margin-bottom: .35rem;
}
.back-link:hover { color: var(--text); text-decoration: none; }
.back-link svg { width: 14px; height: 14px; }

/* ============================================================
   Kunden: Typ-Toggle (Firma / Privat)
   ============================================================ */
.customer-form .type-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
  margin: 0 0 1.25rem;
}
.customer-form .type-card {
  position: relative; cursor: pointer; padding: 1rem;
  border: 2px solid var(--border); border-radius: 10px; background: #fff;
  transition: border-color .15s, background .15s, box-shadow .15s;
  display: block;
}
.customer-form .type-card input[type="radio"] {
  position: absolute; opacity: 0; pointer-events: none;
}
.customer-form .type-card-body { display: flex; gap: .9rem; align-items: center; }
.customer-form .type-card-icon {
  flex: 0 0 48px; height: 48px; width: 48px; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; color: #555; border-radius: 10px; transition: background .15s, color .15s;
}
.customer-form .type-card-title { font-weight: 600; font-size: 1rem; color: #111; }
.customer-form .type-card-desc  { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.customer-form .type-card:hover { border-color: #b8bdc4; }
.customer-form .type-card.is-active {
  border-color: var(--primary);
  background: rgba(255,159,67,.06);
  box-shadow: 0 0 0 3px rgba(255,159,67,.12);
}
.customer-form .type-card.is-active .type-card-icon {
  background: var(--primary); color: #fff;
}
.customer-form section { margin-bottom: 1rem; }
.customer-form .req { color: #c0392b; margin-left: .15rem; }
.customer-form .span-2 { grid-column: span 2; }
.customer-form .form-grid label > .label-text {
  display: block; min-height: 1.2em; line-height: 1.2;
}
.customer-form .form-hint {
  font-size: .72rem; color: var(--muted); line-height: 1.2;
  margin-top: .15rem;
}
.customer-form .notes-field { margin-top: 1.5rem; }

/* Bestätigungs-Modal */
.confirm-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center;
  z-index: 2000;
  padding: 1rem;
}
.confirm-modal-overlay.is-open { display: flex; }
.confirm-modal {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
  animation: confirmIn .15s ease-out;
}
@keyframes confirmIn {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.confirm-modal h3 { margin: 0 0 .5rem; font-size: 1.1rem; }
.confirm-modal p { margin: 0 0 1.25rem; color: var(--muted); line-height: 1.4; white-space: pre-wrap; }
.confirm-modal-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* 2FA-Erinnerung beim Login */
.twofa-remind-card { text-align: center; }
.twofa-remind-card .confirm-modal-actions { justify-content: center; flex-wrap: wrap; }
.twofa-remind-icon {
  width: 56px; height: 56px; margin: .25rem auto 1rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(222,128,14,.12); color: var(--primary);
}

/* Passwort ändern / zurücksetzen (Profil-Modal) */
.pw-msg { padding: .55rem .75rem; border-radius: 6px; font-size: .85rem; margin-bottom: .75rem; line-height: 1.4; }
.pw-msg-error   { background: #fdecea; color: #b71c1c; border: 1px solid #f5c6cb; }
.pw-msg-success { background: #e7f6ec; color: #1b5e20; border: 1px solid #c3e6cb; }
.pw-actions { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.pw-reset { margin-top: .5rem; padding-top: .75rem; border-top: 1px dashed var(--border); }
.pw-reset-title { margin: 0 0 .5rem; font-size: 1rem; }
.btn-link {
  background: none; border: none; padding: 0; margin: 0;
  color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline;
}
.btn-link:hover { opacity: .8; }

/* Avatar-Cropper */
.cropper-modal { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: center; justify-content: center; }
.cropper-modal[hidden] { display: none; }
.cropper-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.cropper-card {
  position: relative; z-index: 1; background: #fff; border-radius: 12px;
  padding: 20px; width: min(360px, 92vw); text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.cropper-card h3 { margin: 0 0 1rem; font-size: 1.1rem; }
.cropper-stage {
  position: relative; width: 288px; height: 288px; margin: 0 auto;
  border-radius: 8px; overflow: hidden; background: #1f2937; touch-action: none;
}
.cropper-canvas { display: block; width: 288px; height: 288px; cursor: grab; }
.cropper-canvas:active { cursor: grabbing; }
.cropper-ring {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.7);
}
.cropper-zoom { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; color: var(--muted); }
.cropper-zoom input[type="range"] { flex: 1; }
.cropper-actions { display: flex; gap: .5rem; justify-content: center; margin-top: 1rem; }
.cropper-modal .pw-msg { text-align: left; }

/* Filter-Leiste (Log etc.) */
.filter-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem 1rem; align-items: end;
}
.filter-bar .filter-actions {
  display: flex; gap: .5rem; align-items: center;
  grid-column: 1 / -1; justify-content: flex-end;
}
.log-table .nowrap { white-space: nowrap; }
.log-table .log-details {
  max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.log-table .log-details:hover { white-space: normal; word-break: break-word; }

/* =====================================================
   Customer-Picker (Modal + Trigger)
   ===================================================== */
.customer-picker-trigger {
  width: 100%;
  padding: 1.1rem 1.25rem;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  background: #fff7ed;
  text-align: center;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.customer-picker-trigger:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.customer-picker-trigger:active { transform: translateY(1px); }
.customer-picker-trigger .picker-text {
  flex: 0 1 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.customer-picker-trigger .picker-text strong { font-weight: 700; }

.customer-picker-modal {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.customer-picker-modal[hidden] { display: none; }
.picker-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
}
.picker-dialog {
  position: relative;
  width: 100%; max-width: 720px;
  max-height: 80vh;
  background: white;
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pickerIn .15s ease-out;
}
@keyframes pickerIn {
  from { opacity: 0; transform: scale(.97) translateY(-8px); }
  to { opacity: 1; transform: none; }
}
.picker-head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.picker-head h3 { margin: 0; font-size: 1.1rem; }
.picker-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.5rem; line-height: 1; color: var(--muted);
  padding: 0 .25rem;
}
.picker-close:hover { color: var(--text); }
.picker-search { padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); }
.picker-search input { width: 100%; }
.picker-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: .5rem;
}
.picker-empty { padding: 1.5rem; text-align: center; color: var(--muted); }
.picker-item {
  display: flex; flex-direction: column;
  width: 100%; text-align: left;
  padding: .65rem .85rem;
  background: white; border: 1px solid transparent;
  border-radius: 6px; cursor: pointer;
  font: inherit; color: var(--text);
}
.picker-item:hover { background: #fff7ed; border-color: rgba(222,128,14,.3); }
.picker-item-name { font-weight: 600; }
.picker-item-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
/* Inaktive Produkte im Picker: ausgegraut, rote Kennzeichnung, nicht wählbar */
.picker-item-inactive { opacity: .9; cursor: not-allowed; }
.picker-item-inactive:hover { background: #fef2f2; border-color: rgba(185,28,28,.3); }
.picker-item-inactive .picker-item-name { color: #b91c1c; }
.picker-item-inactive .picker-item-sub { color: #b91c1c; }
.badge-inactive {
  display: inline-block; font-size: .65rem; font-weight: 700;
  color: #b91c1c; background: #fee2e2; border-radius: 4px;
  padding: 1px 6px; margin-left: 6px; text-transform: uppercase; letter-spacing: .04em;
}
/* Hinweis-Popup über allen anderen Overlays (Picker liegt bei z-index 3000) */
.alert-modal-overlay { z-index: 4000; }
.picker-foot {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
}

/* =====================================================
   Angebot: Split-Screen-Formular mit Live-Preview
   ===================================================== */
.offer-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  align-items: start;
  min-height: 100vh;
}
@media (max-width: 1100px) {
  .offer-split { grid-template-columns: 1fr; }
}
.offer-form {
  padding: 1.75rem 2rem 2rem;
  display: flex; flex-direction: column; gap: 1rem;
  min-width: 0;
}
.offer-form .card { margin-bottom: 0; }
.offer-form-head { margin-bottom: .5rem; }
.offer-form-head h1 { margin: .35rem 0 0; font-size: 1.6rem; }

/* Adressblöcke (Haupt-/Rechnungs-/Lieferadresse) mit Anzeige-Schalter */
.offer-form .addr-block { grid-column: 1 / -1; display: flex; flex-direction: column; gap: .25rem; }
.offer-form .addr-block-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.offer-form .addr-block-head .label-text { font-size: .85rem; color: var(--muted); }
.offer-form .addr-show { flex-direction: row; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); cursor: pointer; }
.offer-form .addr-show input { margin: 0; width: auto; }

.offer-preview-wrap {
  position: sticky;
  top: 0;
  background: #e9ebef;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.preview-toolbar {
  padding: .65rem 1rem;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem;
  flex: 0 0 auto;
  font-size: .85rem;
}
.preview-toolbar .preview-toolbar-left {
  display: inline-flex; align-items: center; gap: .4rem;
  color: var(--muted); font-weight: 500;
}
.preview-toolbar .preview-toolbar-left::before {
  content: '';
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: #2ecc71;
  animation: livePulse 1.7s ease-out infinite;
}
.preview-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0;            /* kein grauer Rand – PDF füllt die volle Fläche */
  display: flex;
  flex-direction: column;
}

/* Live-PDF-Vorschau (echtes, seitengenaues PDF im iframe) – füllt die ganze Fläche, kein grauer Rand */
.preview-pdf-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 82vh;
  border: none;
  border-radius: 0;
  background: #fff;
  display: block;
}

/* HTML-Mock ist nur noch interne Logik – wirklich ausblenden (schlägt .preview-page{display:flex}) */
.preview-page[hidden] { display: none !important; }

.preview-page {
  background: white;
  width: 100%;
  max-width: 820px;
  min-height: 1160px;
  margin: 0 auto;
  padding: 56px 60px 60px;
  box-shadow: 0 12px 36px rgba(0,0,0,.14);
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #1f2937;
  position: relative;
  display: flex; flex-direction: column;
}

/* A4-Seitenumbruch-Markierungen (zeigen, wo im PDF die nächste Seite beginnt) */
.prev-page-breaks { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.prev-page-break { position: absolute; left: 0; right: 0; border-top: 2px dashed #f59e0b; }
.prev-page-break span {
  position: absolute; right: 8px; top: -10px;
  background: #fff7ed; color: #b45309; border: 1px solid #fcd34d;
  font-size: 10px; font-weight: 600; padding: 1px 8px; border-radius: 4px;
}

/* Kopf: Titel links, Logo rechts */
.prev-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: flex-start;
  gap: 32px;
}
.prev-title-left {
  display: flex; flex-direction: column; gap: 4px;
  padding-top: 4px;
}
.prev-big-title {
  margin: 14px 0 0;
  font-size: 40px;
  font-weight: 500;
  letter-spacing: -.01em;
  color: #111827;
  line-height: 1;
}
/* Absenderzeile (Briefstil) + Empfängerblock */
.prev-sender-line {
  font-size: 9px; color: #6b7280;
  border-bottom: 1px solid #d1d5db; padding-bottom: 2px;
  margin-bottom: 16px;
}
.prev-recipient { margin-bottom: 28px; }
.prev-subtitle {
  font-size: 13px;
  color: #6b7280;
  min-height: 1em;
  margin-top: 6px;
}
.prev-header-right {
  display: flex; align-items: flex-start;
}
.prev-logo-img { height: 60px; width: auto; display: block; }

/* Orange Akzentlinie unter Header */
.prev-accent-line {
  height: 2px;
  background: #de800e;
  margin: 20px 0 28px;
}

/* Parties: Angebotssteller / Empfänger */
.prev-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 28px;
}
.prev-party-label {
  font-size: 10px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 600;
  margin-bottom: 8px;
}
.prev-party-body {
  font-size: 12px;
  line-height: 1.55;
}
.prev-party-name {
  font-weight: 700;
  color: #111827;
  margin-bottom: 2px;
}

/* Meta-Strip – Zellen gleichmäßig über die volle Breite verteilt (auseinandergezogen) */
.prev-meta-strip {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 24px;
  padding: 10px 0;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 22px;
}
.prev-meta-cell { display: flex; flex-direction: column; gap: 3px; flex: 1 1 0; }
.prev-meta-label {
  font-size: 9.5px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 600;
}
.prev-meta-value {
  font-weight: 700;
  color: #111827;
  font-size: 13px;
}

.prev-intro {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 12px;
  min-height: 1em;
  margin-bottom: 18px;
}

/* Items-Tabelle: dezent grauer Header (statt aggressivem Schwarz) */
.prev-items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 11.5px;
}
.prev-items thead th {
  background: #555;
  color: #fff;
  text-align: left;
  padding: 9px 8px;
  font-weight: 700; font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
/* Kopfzeile durchgehend weiß – auch in den farbigen Spalten */
.prev-items thead th.c-pos { color: #fff; }
.prev-items thead th.c-qty,
.prev-items thead th.c-price,
.prev-items thead th.c-disc,
.prev-items thead th.c-total { text-align: right; }
.prev-items td {
  padding: 10px 8px;
  vertical-align: top;
  border-bottom: 1px solid #e5e7eb;
}
.prev-items .c-pos { width: 30px; text-align: left; }
.prev-items tbody .c-pos { color: #6b7280; }
.prev-items .c-qty { width: 56px; text-align: right; white-space: nowrap; }
.prev-items .c-artikel { width: auto; }
.prev-items .c-origin { width: 72px; }
.prev-items .c-customs { width: 92px; }
.prev-items .c-price { width: 80px; text-align: right; white-space: nowrap; }
.prev-items .c-disc { width: 58px; text-align: right; white-space: nowrap; }
/* Rabatt-Spalte komplett ausblenden, wenn keine Position einen Rabatt hat */
.prev-items.hide-disc .c-disc { display: none; }
.prev-items .c-total { width: 90px; text-align: right; font-weight: 700; white-space: nowrap; }
/* Artikel-Zelle: Nummer oben (dezent), Name (fett), Beschreibung darunter */
.prev-items .c-artikel .art-nr { display: block; font-size: 10px; color: #6b7280; margin-bottom: 1px; }
.prev-items .c-artikel .art-name { display: block; }
.prev-items .item-sub { display: block; font-size: 10.5px; color: #6b7280; margin-top: 3px; white-space: pre-wrap; }
.prev-items .empty-row td {
  padding: 20px;
  font-style: italic;
  color: #9ca3af;
  text-align: center;
  border-bottom: none;
}
/* Zwischenüberschrift / Kategorie in der Positions-Vorschau */
.prev-items .prev-cat-row td {
  background: #f2f2f2;
  font-weight: 700;
  color: #111827;
  padding: 6px 8px;
}
/* Zwischenüberschrift / Kategorie in der Angebots-Detailansicht */
/* Zwischenüberschrift in einer Positionstabelle: volle Breite, grau hinterlegt,
   ohne Position/Menge/Preis. Gilt für Angebot, Auftrag und Bestellung gleichermaßen. */
.offer-cat-row td { background: #f2f2f2; }

/* Summen-Bereich rechts */
.prev-sum-section {
  align-self: flex-end;
  width: 380px;
  margin-top: 4px;
  display: flex; flex-direction: column;
}
.prev-sum-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #e5e7eb;
  font-size: 12.5px;
}
.prev-sum-label { color: #374151; font-weight: 600; }
.prev-sum-value { font-weight: 700; color: #111827; min-width: 100px; text-align: right; }
.prev-sum-row.prev-sum-muted .prev-sum-label,
.prev-sum-row.prev-sum-muted .prev-sum-value { color: #6b7280; font-weight: 500; }
.prev-sum-row.prev-sum-final {
  border-top: 2.5px solid #de800e;
  border-bottom: none;
  padding: 16px 0 6px;
  font-size: 15px;
}
.prev-sum-row.prev-sum-final .prev-sum-label,
.prev-sum-row.prev-sum-final .prev-sum-value {
  font-weight: 800; color: #111827;
}

/* Zahlungs-/Konditionen-Box */
.prev-pay-section {
  margin-top: 32px;
  padding: 16px 18px;
  background: #f9fafb;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.6;
}
.prev-pay-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: #111827;
}
.prev-pay-section p { margin: 0 0 6px; }
.prev-pay-section p:last-child { margin-bottom: 0; }

.prev-footer-text {
  margin-top: 14px;
  font-size: 11px;
  line-height: 1.5;
  color: #4b5563;
  white-space: pre-wrap;
}

/* Footer */
.prev-footer {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid #e5e7eb;
  text-align: center;
  font-size: 9px;
  color: #6b7280;
  line-height: 1.6;
}
.prev-footer div { padding: 1px 0; }

/* Postal-Adresse (Detail-Ansicht) */
.postal-address {
  display: block;
  font-style: normal;
  line-height: 1.5;
  font-size: .92rem;
  color: var(--text);
  padding: .25rem 0;
}
.postal-address .postal-line {
  display: block;
}
.postal-address strong.postal-line {
  font-weight: 600;
}
.customer-form h3 { margin-top: 1.25rem; }
@media (max-width: 700px) {
  .customer-form .type-toggle { grid-template-columns: 1fr; }
  .customer-form .span-2 { grid-column: auto; }
}

/* Address blocks */
.address-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: .75rem;
  background: #fafbfc;
}
.address-block-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: .5rem;
}
.address-block-head .same-toggle { margin: 0; }
.address-block-head .remove-btn { margin-left: auto; }
.address-add-row { margin: -.25rem 0 1rem; }

/* ============================================================
   Ansprechpartner-Karten (Detailseite, Firmenkunden)
   ============================================================ */
.contacts-card .card-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem;
}
.contacts-card .card-head h3 { margin: 0; }
.contacts-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .75rem;
}
.contact-card {
  border: 1px solid var(--border); border-radius: 8px; padding: .75rem;
  background: #fafbfc; transition: border-color .15s, box-shadow .15s;
  display: flex; flex-direction: column; gap: .5rem;
}
.contact-card:hover { border-color: #cdd2d8; }
.contact-card.is-primary {
  border-color: var(--primary); background: #fff8ee;
}
.contact-head { display: flex; align-items: flex-start; gap: .6rem; }
.contact-avatar {
  flex: 0 0 36px; width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .85rem; letter-spacing: .02em;
}
.contact-card.is-primary .contact-avatar { background: var(--primary-dark, #d97706); }
.contact-name { flex: 1; min-width: 0; }
.contact-name b { font-weight: 600; }
.contact-actions { display: flex; gap: .15rem; }
.contact-actions .icon-btn { width: 28px; height: 28px; margin-left: 0; }
.contact-body { font-size: .85rem; display: flex; flex-direction: column; gap: .15rem; }
.contact-body a { color: #111; text-decoration: none; }
.contact-body a:hover { text-decoration: underline; }

/* =========================================================
   Statistik – Tabs, KPI-Kacheln, Charts, Donuts, Aging-Bar
   ========================================================= */

.tabs {
  display: flex; flex-wrap: wrap; gap: .25rem;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1rem 0;
}
.tab-btn {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: .65rem 1rem; cursor: pointer;
  font: inherit; font-size: .92rem; color: var(--muted);
  transition: color .15s, border-color .15s, background .15s;
  border-radius: 6px 6px 0 0;
}
.tab-btn:hover { color: var(--text); background: #fafafa; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tiles-lg .tile-num { font-size: 1.45rem; }
.tile { position: relative; }
.tile .delta { font-size: .75rem; margin-top: .25rem; font-weight: 600; }
.tile .muted.small { font-size: .72rem; margin-top: .15rem; }
.delta-up, .pos { color: var(--success); }
.delta-down, .neg { color: var(--danger); }

/* Horizontal Bar (in Tabellen, Quartal, Stadt etc.) */
.bar-h {
  background: #f1f3f5; border-radius: 4px; height: 8px; overflow: hidden; min-width: 80px;
}
.bar-h-fill {
  height: 100%; background: var(--primary); border-radius: 4px;
  transition: width .3s;
}

/* Chart-Erweiterungen */
.chart.chart-compare, .chart.chart-dual { height: 240px; }
.chart-bar.dual .bar.dual {
  position: relative;
  display: flex; align-items: flex-end; gap: 2px;
}
.chart-bar.dual .bar-fill {
  flex: 1; min-height: 2px; border-radius: 4px 4px 0 0;
}
.chart-bar.dual .bar-fill.prev { background: #cbd5e1; }
.chart-bar.dual .bar-fill.curr { background: var(--primary); }
.chart-bar.dual .bar-fill.in   { background: #10b981; }
.chart-bar.dual .bar-fill.out  { background: #ef4444; }
.chart-bar:hover .bar-fill.curr { background: var(--primary-dark); }

/* Legende */
.legend { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; }
.legend.inline { flex-direction: row; flex-wrap: wrap; gap: .85rem; margin-top: .5rem; justify-content: center; }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary);
}

/* Donut */
.donut-wrap {
  display: grid; grid-template-columns: 160px 1fr; gap: 1.25rem; align-items: center;
}
.donut { width: 160px; height: 160px; }
.donut-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-svg .donut-num { font-size: 7px; font-weight: 700; fill: var(--text); transform: rotate(90deg); transform-origin: 21px 21px; }
.donut-svg .donut-sub { font-size: 3px; fill: var(--muted); transform: rotate(90deg); transform-origin: 21px 21px; }
@media (max-width: 700px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}

/* Aging stacked bar */
.aging-stack {
  display: flex; height: 28px; border-radius: 6px; overflow: hidden; background: #f1f3f5;
}
.aging-seg { transition: filter .15s; }
.aging-seg:hover { filter: brightness(0.92); }

/* Progress bar (für Konversionsrate) */
.progress {
  background: #f1f3f5; border-radius: 999px; height: 10px; margin-top: .75rem; overflow: hidden;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, #10b981, #059669); border-radius: 999px;
}

/* KPI-Block (YTD-Vergleich) */
.kpi-block .row {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 1rem;
  align-items: center; margin-top: .5rem;
}
.kpi-block .row b { font-size: 1.1rem; }
.kpi-block .small { font-size: .75rem; }

/* Inline-Form (Jahreswahl im Header) */
.inline-form { display: inline-flex; gap: .5rem; align-items: center; }
.inline-form select {
  padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: white; font: inherit;
}

/* Page-Head Anpassung */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; gap: .5rem; }

/* Inline-Dot in Tabellen (Aging) */
table .legend-dot { vertical-align: middle; margin-right: .35rem; }



/* Bereichsübersicht "Artikel & Produktion" – klickbare Kästchen */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.hub-card {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  min-height: 130px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.hub-card:hover {
  text-decoration: none;
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
  transform: translateY(-2px);
}
.hub-card-head { display: flex; align-items: center; gap: .6rem; }
.hub-card-head svg { color: var(--primary); flex: none; }
.hub-card h2 { margin: 0; font-size: 1.2rem; }
.hub-desc { color: var(--muted); font-size: .85rem; line-height: 1.4; }
.hub-count { margin-top: auto; padding-top: .5rem; font-size: .8rem; color: var(--primary); font-weight: 600; }

/* Produktbilder */
.product-thumb-cell { width: 52px; }
.product-thumb {
  display: block; width: 44px; height: 44px; object-fit: cover;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.product-thumb-empty { background: #f1f3f5; }
.product-img {
  display: block; margin-bottom: 1rem; max-width: 280px;
}
.product-img img {
  width: 100%; height: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff;
}
.product-img-current { display: flex; align-items: center; gap: .75rem; }
.product-img-current img {
  width: 90px; height: 90px; object-fit: cover;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}

/* Produktnummer in der Liste: klar orange & klickbar */
.product-sku-link { color: var(--primary); font-weight: 600; }
.product-sku-link:hover { color: var(--primary-dark); text-decoration: underline; }

/* Produktname in der Liste: normale Textfarbe, klickbar */
.product-name-link { color: var(--text); font-weight: 400; }
.product-name-link:hover { color: var(--text); text-decoration: underline; }

/* Lieferanten-Zeile in der Hersteller-Spalte: dezent */
.product-supplier { color: var(--muted); font-size: .82rem; }

/* Seriennummer in der Liste: orange, aber nicht klickbar */
.sn-serial { color: var(--primary); font-weight: 600; }

/* Mehrere Lieferanten – Zeilen im Produktformular */
.supplier-row {
  border: 1px solid var(--border); border-radius: 8px;
  padding: .8rem; margin-bottom: .7rem; background: #fafbfc;
}
.supplier-row-actions { margin-top: .5rem; text-align: right; }
.sup-primary-label { flex-direction: row; align-items: center; gap: .4rem; white-space: nowrap; }
.sup-primary-label input { width: auto; }

/* Mehrere Lieferanten – Karten in der Detailansicht */
.supplier-cards { display: flex; flex-direction: column; gap: .8rem; }
.supplier-card { border: 1px solid var(--border); border-radius: 8px; padding: .7rem .8rem; }
.supplier-card.is-primary { border-color: var(--primary); background: #fff8ee; }
.supplier-card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.supplier-card-name { font-weight: 600; }
.badge-primary { background: #ffe4c7; color: var(--primary-dark); }

/* Kleines Produktbild im Detail-Kopf (links neben Titel & Nummer) */
.product-head-main { display: flex; align-items: center; gap: 1.1rem; }
.product-img-head-sm { display: inline-flex; flex: none; }
.product-img-head-sm img {
  width: 72px; height: 72px; object-fit: cover;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
/* Abschnittstitel im Produktformular */
.form-section-title { margin: 1.5rem 0 .5rem; font-size: .95rem; color: var(--text); }
/* Automatisch berechnete (gesperrte) Eingabefelder */
input.is-computed { background: #f5f5f5; color: var(--muted); }
/* Pflichtfeld-Markierung */
.req { color: var(--danger); font-weight: 700; }
.form-error {
  background: #f5d5d5; color: #8a1f1f; border: 1px solid #e8b5b5;
  border-radius: 6px; padding: .7rem 1rem; margin-bottom: 1rem; font-size: .9rem;
}
.form-error[hidden] { display: none; }
.field-invalid { border-color: var(--danger) !important; background: #fff6f6; }

/* Fehlerseite (404/403/500) */
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--bg); }
.error-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.12); padding: 2.5rem 3rem; text-align: center; max-width: 460px;
}
.error-icon { font-size: 2.6rem; line-height: 1; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--primary); line-height: 1; margin: .35rem 0 .4rem; }
.error-title { font-size: 1.15rem; font-weight: 600; margin: 0 0 .35rem; }
.error-sub { margin: 0 0 1.5rem; }
.error-actions { display: flex; gap: .5rem; justify-content: center; }

/* Preis-Hervorhebung auf der Produkt-Detailseite (Netto groß, Brutto daneben) */
.price-highlight {
  display: flex; align-items: flex-end; gap: 2rem; flex-wrap: wrap;
  margin-bottom: 1rem; padding: .8rem 1rem;
  background: #fff8ee; border: 1px solid #ffe2bf; border-radius: 10px;
}
.price-cap { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.price-net { font-size: 1.8rem; font-weight: 700; line-height: 1.1; color: var(--primary-dark); }
.price-brutto { font-size: 1.2rem; font-weight: 600; line-height: 1.1; color: var(--text); }
.kv-hint { font-weight: 400; font-style: italic; text-transform: none; letter-spacing: 0; color: var(--muted); }

/* Langbezeichnung / Beschreibung auf der Produkt-Detailseite */
.product-description {
  white-space: pre-line;
  margin-top: .85rem;
  padding: .75rem .9rem;
  background: #f7f7f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.5;
}

/* Kartenkopf mit Aktion (z. B. Stückliste + Hinzufügen) */
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.card-head-row h3 { margin: 0; }

/* Generisches Popup/Modal (z. B. Stückliste-Position) */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: var(--panel); color: var(--text);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
  width: 100%; max-width: 460px;
  max-height: calc(100vh - 4rem); overflow-y: auto;
  padding: 1.75rem;
}
.modal-card h3 { margin: 0 0 .25rem; }
.modal-card > .muted { margin: 0 0 1.25rem; font-size: .85rem; line-height: 1.4; }
.modal-close {
  position: absolute; top: .5rem; right: .85rem;
  background: transparent; border: none;
  font-size: 1.6rem; line-height: 1; color: #888; cursor: pointer;
}
.modal-close:hover { color: var(--text); }

/* Großes Modal (Stückliste) – nimmt fast die ganze Seite ein */
.modal-card-lg { max-width: 1300px; width: 95vw; min-height: 80vh; }
.bom-table { width: 100%; }
.bom-table td, .bom-table th { vertical-align: middle; }
.bom-row-actions { white-space: nowrap; }
.bom-row-actions .inline-form { display: inline-block; margin-left: .25rem; }
.bom-sep { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0 1rem; }
.bom-add-title { margin: 0 0 .75rem; font-size: .95rem; }
.bom-or { text-align: center; color: var(--muted); font-size: .8rem; margin: 1rem 0 .5rem; }
.bom-newprod { margin-top: .75rem; display: flex; flex-direction: column; gap: .5rem; }

/* Aufklappbare Auftragspositionen (Lieferant/Hersteller/Stückliste je Zeile) */
.pos-expand-col { width: 1.8rem; text-align: center; padding-right: 0 !important; }
.pos-row-expandable { cursor: pointer; }
.pos-row-expandable:hover { background: var(--hover, rgba(0,0,0,.03)); }
.pos-chevron { display: inline-flex; color: var(--muted); transition: transform .15s ease; }
.pos-row-expandable.is-open .pos-chevron { transform: rotate(90deg); color: var(--text, inherit); }
.pos-detail-row > .pos-detail-cell { background: var(--hover, rgba(0,0,0,.02)); padding: 1rem 1.2rem; }
.pos-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 1rem; }
.pos-detail-block h4,
.pos-detail-bom h4 { margin: 0 0 .5rem; font-size: .9rem; }
.pos-detail-bom { margin-top: .25rem; }
.pos-detail .kv { gap: .3rem 1rem; }
.pos-detail .kv b { font-weight: 600; font-size: .78rem; color: var(--muted); }
.pos-detail-row[hidden] { display: none; }

/* Stücklisten-Position bearbeiten (Inline-Zeile) */
.bom-edit-row[hidden] { display: none; }
.bom-edit-cell { background: var(--hover, rgba(0,0,0,.03)); padding: 1rem 1.2rem; }
.bom-edit-form .form-grid { margin-bottom: .6rem; }
.bom-edit-linked { margin: 0 0 .6rem; }

/* Grünes Plus (z. B. Produktionsauftrag anlegen) */
.icon-btn-add { color: #16a34a; }
.icon-btn-add:hover { background: rgba(22,163,74,.12); color: #15803d; border-color: rgba(22,163,74,.4); }
/* Aktion, die der aktuelle Status noch nicht zulässt: sichtbar, aber gedämpft.
   Der Klick erklärt per Hinweis, was zuerst passieren muss. */
.icon-btn.is-gated { color: var(--muted); opacity: .55; }
.icon-btn.is-gated:hover { background: rgba(0,0,0,.04); color: var(--muted); border-color: var(--border); }

/* Einklappbare Stückliste im Positions-Detail */
.bom-toggle { display: inline-flex; align-items: center; gap: .4rem; background: none; border: none; padding: .15rem 0; margin: 0 0 .4rem; cursor: pointer; font: inherit; font-weight: 600; font-size: .92rem; color: inherit; }
.bom-toggle .pos-chevron { display: inline-flex; color: var(--muted); transition: transform .15s ease; }
.bom-toggle.is-open .pos-chevron { transform: rotate(90deg); }
.bom-collapse[hidden] { display: none; }

/* Produktionsliste: Status-Zelle (Pille + Einkauf-Häkchen) und Positionsblöcke im Aufklappbereich */
.prod-status-cell { display: flex; flex-direction: row; gap: .4rem; align-items: center; flex-wrap: wrap; }
.prod-status-cell .inline-form { margin: 0; }
/* Prioritäts-Badges */
.prio-badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.prio-low    { background: #ebebeb; color: #555; }
.prio-normal { background: #e7f0fe; color: #1d4ed8; }
.prio-high   { background: #fff0d6; color: #8a5a00; }
.prio-urgent { background: #f5d5d5; color: #8a1f1f; }
.prod-pos-block { margin-bottom: 1.1rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--border); }
.prod-pos-block:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
/* Kompakte Positionszeile in der Produktion (alles nebeneinander) */
/* Feste Spalten: Art.-Nr., Bezeichnung, Beschreibung, Menge immer an gleicher Stelle; lange Texte brechen um. */
.prod-pos-line { display: grid; grid-template-columns: 8rem 13rem 20rem 6.5rem max-content 1fr; gap: .4rem 1.5rem; align-items: start; }
.prod-pos-line .ppl { display: block; font-size: .9rem; word-break: break-word; min-width: 0; }
.prod-pos-line .ppl-lbl { font-weight: 700; color: inherit; margin-right: .3rem; }
.prod-pos-line .ppl-stueck { font-size: .9rem; min-width: 0; }
.prod-pos-line .bom-popup-btn { margin: 0; font-size: .9rem; }
.prod-pos-line .pos-built { justify-self: end; align-self: start; }
.prod-pos-block .bom-popup-content[hidden] { display: none; }
@media (max-width: 900px) {
  .prod-pos-line { grid-template-columns: 1fr 1fr; }
  .prod-pos-line .pos-built { justify-self: start; }
}
/* Produktionsliste: Zeilen sauber vertikal ausrichten (gleiche Höhe der Trennlinien) */
.pos-table td, .pos-table th { vertical-align: middle; }
.prod-status-cell { min-height: 1px; }
/* Geöffneter Produktionsauftrag farblich leicht hervorheben (Zeile + alle Artikel/Details) */
.pos-table .pos-row.is-open > td { background: #eef4fd; }
.pos-table .pos-row.is-open + .pos-detail-row > .pos-detail-cell { background: #f4f8fe; }
.prod-assign { display: block; margin: .85rem 0 .25rem; max-width: 320px; }
.prod-assign select { width: 100%; }

/* Benachrichtigungs-Toasts (unten rechts). z-index 900 < Modals (>=1000), damit nichts überlagert wird. */
.toast-stack { position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 900; display: flex; flex-direction: column-reverse; gap: .6rem; max-width: 340px; }
.toast {
  position: relative; overflow: hidden;
  background: var(--panel, #fff); border: 1px solid var(--border, #e3e3e3); border-left: 4px solid #16a34a;
  border-radius: 10px; box-shadow: 0 10px 28px rgba(0,0,0,.16);
  padding: .7rem .95rem .85rem; animation: toast-in .25s ease;
}
.toast-hide { animation: toast-out .25s ease forwards; }
.toast-close { position: absolute; top: .35rem; right: .5rem; background: none; border: none; font-size: 1.15rem; line-height: 1; color: var(--muted); cursor: pointer; }
.toast-title { font-weight: 600; font-size: .92rem; padding-right: 1rem; }
.toast-msg { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.toast-link { display: inline-block; margin-top: .5rem; font-size: .82rem; font-weight: 600; color: #16a34a; text-decoration: none; }
.toast-link:hover { text-decoration: underline; }
.toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: rgba(0,0,0,.07); }
.toast-progress span { display: block; height: 100%; width: 0; background: #16a34a; animation: toast-bar 7s linear forwards; }
@keyframes toast-in  { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(120%); opacity: 0; } }
@keyframes toast-bar { from { width: 0; } to { width: 100%; } }
.bom-suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 240px; overflow-y: auto; margin-top: 2px;
}
.bom-suggest[hidden] { display: none; }
.bom-suggest-item {
  display: block; width: 100%; text-align: left; background: transparent; border: none;
  padding: .5rem .65rem; cursor: pointer; font-size: .85rem; color: var(--text); border-bottom: 1px solid var(--border);
}
.bom-suggest-item:last-child { border-bottom: none; }
.bom-suggest-item:hover { background: #f1f3f5; }

/* Status-Feld (Aktiv/Inaktiv) */
.status-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .25rem .65rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; background: transparent;
  font-family: inherit; cursor: default; white-space: nowrap;
}
button.status-badge { cursor: pointer; }
button.status-badge:hover { filter: brightness(0.96); }
.status-badge .status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-active   { color: #1a7f37; background: #e6f4ea; border-color: #b7e0c2; }
.status-active   .status-dot { background: #1a7f37; }
.status-inactive { color: #b52c2c; background: #fdecec; border-color: #f3c0c0; }
.status-inactive .status-dot { background: #b52c2c; }

/* Status-Panel im Detail-Kopf */
.status-panel { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; text-align: right; }
.status-panel .status-note { font-size: .8rem; color: var(--text); max-width: 260px; }
.status-panel .status-time { font-size: .75rem; color: var(--muted); }
.status-panel .status-by { font-size: .7rem; color: var(--muted); }

/* Kombiniertes Status-Feld im Detail-Kopf: links Aktiv/Inaktiv, rechts seit/geändert von */
.status-box {
  display: inline-flex; align-items: center; gap: 1rem;
  align-self: center; margin-right: auto; margin-left: .75rem;  /* nach links, aber etwas Abstand zum Titel */
  padding: .6rem 1.2rem; border-radius: 12px;
  border: 1px solid transparent; font-family: inherit; text-align: left;
}
button.status-box { cursor: pointer; }
button.status-box:hover { filter: brightness(0.97); }
.status-box.status-active   { background: #e6f4ea; border-color: #b7e0c2; color: #1a7f37; }
.status-box.status-inactive { background: #fdecec; border-color: #f3c0c0; color: #b52c2c; }
.status-box-label { font-size: 1.6rem; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.status-box-meta {
  display: flex; flex-direction: column; gap: .1rem;
  font-size: .74rem; line-height: 1.3; text-align: left;
}
.status-box-note { font-weight: 600; max-width: 240px; }

/* Status-Auswahl im Modal */
.status-modal-card { max-width: 640px; }

/* Umwandlung: Lade-Overlay + Ergebnis-Modal mit Auftragsbestätigung */
.convert-loading {
  position: fixed; inset: 0; z-index: 4000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,23,42,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.convert-loading[hidden] { display: none; }
.convert-loading-box {
  background: #fff; color: var(--text); border-radius: 12px;
  padding: 1.5rem 2rem; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display: flex; align-items: center; gap: 1rem; font-weight: 600;
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #e5e7eb; border-top-color: var(--primary-accent, #de800e);
  display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.convert-modal-card { display: flex; flex-direction: column; }
.convert-pdf-wrap { flex: 1 1 auto; min-height: 60vh; margin: .5rem 0 1rem; }
.convert-pdf-frame { width: 100%; height: 100%; min-height: 60vh; border: 1px solid var(--border); border-radius: 6px; background: #fff; }

/* E-Mail-Sende-Modal mit Vorschau */
.email-modal-card { max-width: 760px; }
.email-grid { display: flex; flex-direction: column; gap: .75rem; }
.email-grid label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.email-grid input, .email-grid textarea { font: inherit; padding: .5rem .6rem; }
.email-grid textarea { resize: vertical; }
.email-attach-row { display: flex; align-items: center; gap: .75rem; margin: .85rem 0; flex-wrap: wrap; }
.email-attach-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  background: #f3f4f6; border: 1px solid var(--border); border-radius: 6px;
  padding: .3rem .6rem; font-size: .85rem; color: var(--text);
}
.email-preview { margin: .5rem 0 1rem; }
.email-preview-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .4rem; }
.email-preview-card { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.email-preview-head { background: #f9fafb; border-bottom: 1px solid var(--border); padding: .7rem .9rem; font-size: .85rem; line-height: 1.7; }
.email-preview-body { padding: .9rem; font-size: .9rem; line-height: 1.5; color: #111827; white-space: normal; min-height: 60px; }
.email-preview-foot {
  display: inline-flex; align-items: center; gap: .4rem;
  margin: 0 .9rem .9rem; padding: .3rem .55rem;
  background: #f3f4f6; border: 1px solid var(--border); border-radius: 6px; font-size: .8rem; color: var(--muted);
}
.status-options { display: flex; gap: 1rem; margin: .25rem 0 1rem; }
.status-opt { flex-direction: row; align-items: center; gap: .5rem; cursor: pointer; }

/* Status-Historie im Modal */
.status-history-wrap { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.status-history-title { margin: 0 0 .6rem; font-size: .95rem; }
.status-history { display: flex; flex-direction: column; gap: .5rem; overflow-y: auto; }
.status-hist-item { display: flex; align-items: center; gap: .75rem; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; }
.status-hist-meta { display: flex; flex-direction: column; gap: .1rem; font-size: .78rem; color: var(--muted); }
.status-hist-note { color: var(--text); }

/* Live-Vorschau: pulsierender, leuchtender Punkt */
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(46,204,113,.55), 0 0 6px 1px rgba(46,204,113,.55); }
  70%  { box-shadow: 0 0 0 9px rgba(46,204,113,0),  0 0 9px 2px rgba(46,204,113,.85); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0),    0 0 6px 1px rgba(46,204,113,.55); }
}
@media (prefers-reduced-motion: reduce) {
  .preview-toolbar .preview-toolbar-left::before { animation: none; }
}

/* Positions-Editor: Aktions-Buttons */
.items-add-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .25rem; }
/* Textzeile (Zwischenüberschrift/Kategorie) im Positions-Editor */
.items-table tr.item-text-row td { background: #f7f7f5; }
.items-table .item-text-input {
  width: 100%;
  font-weight: 700;
  font-size: .95rem;
}
/* Aus Produkt übernommene, gesperrte Felder */
.items-table input[readonly] { background: #f5f5f5; color: var(--muted); cursor: not-allowed; }
/* Entfernen-Button (×) sauber zentriert */
.items-table [data-remove] {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; line-height: 1; font-size: 1.15rem;
}

/* Deaktivierte Auswahl (kein Ansprechpartner/keine Adresse) */
#offer-contact-select:disabled, #offer-address-select:disabled {
  background: #f5f5f5; color: var(--muted); cursor: not-allowed;
}

/* =================================================================
   Angebots-Status: farbige Pills (Liste, Detail, Modal, Historie)
   ================================================================= */
.ostatus-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .28rem .7rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; font-family: inherit; white-space: nowrap;
}
button.ostatus-pill { cursor: pointer; }
.ostatus-clickable { transition: filter .12s, box-shadow .12s; }
.ostatus-clickable:hover { filter: brightness(0.96); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.ostatus-lg { font-size: 1rem; padding: .4rem 1rem; }

.ostatus-draft     { background: #eef0f2; color: #5b6470; border-color: #dde1e6; }
.ostatus-sent      { background: #e7f0fe; color: #1d4ed8; border-color: #c4dafc; }
.ostatus-accepted  { background: #e6f4ea; color: #1a7f37; border-color: #b7e0c2; }
.ostatus-rejected  { background: #fdecec; color: #b52c2c; border-color: #f3c0c0; }
.ostatus-expired   { background: #fff4e0; color: #92600a; border-color: #f5e0b4; }
.ostatus-converted { background: #ffe8d0; color: #b35a00; border-color: #f6cfa3; }
/* Auftrags-Status (gleicher Pill-Stil wie Angebote) */
.ostatus-open             { background: #eef0f2; color: #5b6470; border-color: #dde1e6; }
.ostatus-in_production    { background: #fff4e0; color: #92600a; border-color: #f5e0b4; }
.ostatus-shipped          { background: #e7f0fe; color: #1d4ed8; border-color: #c4dafc; }
.ostatus-delivered        { background: #e0f2f1; color: #0f766e; border-color: #b4dedb; }
.ostatus-completed        { background: #e6f4ea; color: #1a7f37; border-color: #b7e0c2; }
/* Produktionsstatus */
.ostatus-waiting_parts    { background: #e7f0fe; color: #1d4ed8; border-color: #c4dafc; }
.ostatus-in_progress      { background: #fff4e0; color: #92600a; border-color: #f5e0b4; }
.ostatus-done             { background: #e6f4ea; color: #1a7f37; border-color: #b7e0c2; }
.ostatus-cancelled        { background: #f5d5d5; color: #8a1f1f; border-color: #eebcbc; }
/* Einkauf-Häkchen (Produktion) */
.einkauf-check { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; font-size: .82rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: .25rem .6rem; background: none; }
.einkauf-check:hover { background: #eaf6e0; color: #3d6b2d; border-color: #c4e0ad; }
.einkauf-check.is-done { background: #e4f0da; color: #3d6b2d; border-color: #b7e0c2; }
.einkauf-check.is-done:hover { background: #d8ebc8; }
.einkauf-check .einkauf-box { width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center; }
/* Bestell-Status (draft/sent/cancelled teilen sich die Farben mit den Angeboten) */
.ostatus-partially_received { background: #fff4e0; color: #92600a; border-color: #f5e0b4; }
.ostatus-received           { background: #e6f4ea; color: #1a7f37; border-color: #b7e0c2; }
/* Legacy-Auftrags-Status (kommen bei Altdaten/Automatik vor) */
.ostatus-confirmed        { background: #e7f0fe; color: #1d4ed8; border-color: #c4dafc; }
.ostatus-ready            { background: #e6f4ea; color: #1a7f37; border-color: #b7e0c2; }
.ostatus-partially_shipped{ background: #fff4e0; color: #92600a; border-color: #f5e0b4; }
.ostatus-invoiced         { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }
.ostatus-cancelled        { background: #fdecec; color: #b52c2c; border-color: #f3c0c0; }

/* Status-Auswahl im Angebots-Modal */
.ostatus-options { display: flex; flex-wrap: wrap; gap: .6rem; margin: .25rem 0 1rem; }
.ostatus-opt { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.ostatus-opt input { accent-color: var(--accent, #de800e); }

/* Produktions-Status-Modal: alle Optionen nebeneinander (Radio über Pille), Karte breiter */
#prod-status-modal .status-modal-card { max-width: 760px; }
#prod-status-modal .ostatus-options { flex-wrap: nowrap; justify-content: center; gap: .5rem; }
#prod-status-modal .ostatus-opt { flex-direction: column; gap: .35rem; text-align: center; }

/* Einkauf-Häkchen deaktiviert (z. B. wenn abgebrochen/abgeschlossen) */
.einkauf-check.is-disabled { opacity: .5; cursor: not-allowed; }
.einkauf-check.is-disabled:hover { background: none; color: var(--muted); border-color: var(--border); }

/* Produktionsnummer als oranger Sprung zur Produktionsliste */
.prod-num-link { color: #c2780b; font-weight: 600; }
.prod-num-link:hover { color: #92400e; text-decoration: underline; }

/* „Alte Produktionsaufträge" Aufklappbereich */
.old-prod { margin-top: 1rem; }
.old-prod > summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--muted); list-style: none; padding: .35rem 0; }
.old-prod > summary::-webkit-details-marker { display: none; }
.old-prod > summary::before { content: '▸'; display: inline-block; margin-right: .4rem; transition: transform .15s; }
.old-prod[open] > summary::before { transform: rotate(90deg); }
.old-prod-card { margin-top: 1.25rem; }

/* =================================================================
   Bestellungen (Einkauf)
   ================================================================= */
/* Auswahl-Listen in den Bestell-Modals (Artikel, Auftragspositionen) */
.picker-results { max-height: 22rem; overflow-y: auto; margin: .6rem 0; border: 1px solid var(--border); border-radius: 8px; }
.picker-results:empty { display: none; }
.picker-item {
  display: flex; flex-direction: column; gap: .1rem; width: 100%;
  padding: .5rem .7rem; background: none; border: 0; border-bottom: 1px solid var(--border);
  text-align: left; cursor: pointer; font-family: inherit;
}
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover { background: #fff6ea; }
.picker-item .pi-name { font-size: .9rem; color: var(--text); }
.picker-item .pi-sub { font-size: .75rem; color: var(--muted); }
/* Artikel eines anderen Lieferanten: wählbar, aber sichtbar markiert */
.picker-item.is-foreign { background: #fffaf0; }
.picker-item .pi-warn {
  margin-left: .5rem; padding: .05rem .4rem; border-radius: 999px;
  background: #fff0d6; color: #8a5a00; font-size: .7rem; font-weight: 600; white-space: nowrap;
}

/* Positionen aus einem Auftrag übernehmen */
.oi-row {
  display: grid; grid-template-columns: auto 1fr auto 6rem; align-items: center; gap: .6rem;
  padding: .5rem .7rem; border-bottom: 1px solid var(--border); flex-direction: row;
}
.oi-row:last-child { border-bottom: 0; }
.oi-row.is-done { opacity: .5; }
.oi-row .oi-desc { font-size: .9rem; }
.oi-row .oi-take { width: 100%; }

/* Bestell-Positionsraster */
[data-purchase-items] .items-table { min-width: 900px; }
[data-purchase-items] .items-table input { padding: .35rem .45rem; font-size: .9rem; width: 100%; }
[data-purchase-items] .items-table td { vertical-align: middle; }
[data-purchase-items] .text-row-input { font-weight: 600; }
.items-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .8rem 0; }
.items-totals { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; margin-top: .8rem; font-size: .9rem; }
.items-totals > div { display: flex; gap: 1.2rem; min-width: 14rem; justify-content: space-between; }
.items-totals .grand { font-size: 1.05rem; padding-top: .3rem; margin-top: .2rem; border-top: 2px solid var(--primary); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font-size: .75rem; text-decoration: underline; font-family: inherit; }

/* Platzhalter in der PDF-Vorschau, solange noch kein Beleg erzeugt werden kann */
.preview-empty {
  flex: 1 1 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .5rem; padding: 2rem; text-align: center;
  color: var(--muted); background: #e9ebef;
}
.preview-empty[hidden] { display: none; }
/* .preview-pdf-frame setzt display:block, das schlägt sonst das hidden-Attribut. */
.preview-pdf-frame[hidden] { display: none; }
.preview-empty svg { color: #b9bfc8; margin-bottom: .3rem; }
.preview-empty-title { margin: 0; font-size: 1rem; font-weight: 600; color: #6b7280; }
.preview-empty-text { margin: 0; font-size: .85rem; max-width: 26rem; line-height: 1.5; }
/* Der pulsierende Punkt steht für "läuft mit"; ohne PDF wäre er gelogen. */
.preview-toolbar-left.is-idle::before { animation: none; background: #b9bfc8; }

/* SMC-Hinweisleiste auf der Bestell-Detailseite */
.smc-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.smc-bar-actions { display: inline-flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }

/* Bestellformular: großzügigere Abstände zwischen den Feldzeilen.
   .form-grid bringt von sich aus keinen Außenabstand mit, dadurch klebten
   die Zeilen im Kartenlayout aneinander. */
.purchase-form .card > h3 { margin-bottom: 1.15rem; }
.purchase-form .card > .form-grid,
.purchase-form .card > .sn-field,
.purchase-form .card > label { margin-bottom: 1.15rem; }
.purchase-form .card > :last-child { margin-bottom: 0; }
.purchase-form .form-grid { gap: 1.15rem 1.25rem; }
.purchase-form .form-grid.compact { gap: 1.15rem 1.25rem; }
.purchase-form label { gap: .35rem; }
.purchase-form .sn-field > .label-text { margin-bottom: .35rem; }
.purchase-form .sn-chosen { margin-top: .4rem; }
/* Fließtextfelder etwas luftiger */
.purchase-form textarea { padding: .5rem .6rem; line-height: 1.45; }

/* SMC: Statuszeile über dem Dateibrowser */
.smc-status {
  display: flex; align-items: center; gap: .5rem;
  margin: 0 0 1rem; font-size: .85rem; color: var(--muted);
}
.smc-status code { font-size: .8rem; background: #f1f2f4; padding: .05rem .3rem; border-radius: 4px; }
.smc-status .smc-dot { width: 8px; height: 8px; border-radius: 50%; background: #2ecc71; flex: none; }
.smc-status.is-incomplete .smc-dot { background: #d92d20; }

/* SMC: Dateibrowser */
.fb { padding: 0; overflow: hidden; }
.fb-bar {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .6rem .8rem; border-bottom: 1px solid var(--border); background: #fafafa;
}
.fb-bar .btn { padding: .3rem .6rem; font-size: .82rem; }
.fb-bar .btn-icon { padding: .3rem .45rem; line-height: 0; }
.fb-spacer { flex: 1 1 auto; }
.fb-crumbs { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; min-width: 0; }
.fb-crumb {
  background: none; border: 0; padding: .1rem .3rem; border-radius: 4px;
  color: var(--primary); cursor: pointer; font-family: inherit; font-size: .85rem;
}
.fb-crumb:hover { background: #fff0dd; }
.fb-sep { color: var(--muted); font-size: .8rem; }

.fb-drop { position: relative; min-height: 16rem; }
.fb-list { max-height: 60vh; overflow-y: auto; }
.fb-empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); margin: 0; }

/* Ladekreis mittig, während das Verzeichnis geholt wird */
.fb-loading { display: flex; align-items: center; justify-content: center; padding: 3.5rem 1rem; }
.spinner {
  display: inline-block; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #e5e7eb; border-top-color: var(--primary);
  animation: spinner-turn .8s linear infinite;
}
@keyframes spinner-turn { to { transform: rotate(360deg); } }
/* Nicht anhalten, ein stehender Kreis sieht aus wie ein Fehler – nur langsamer. */
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.fb-table { margin: 0; }
.fb-table td { padding: .4rem .8rem; vertical-align: middle; }
.fb-table tr.fb-dir td { background: #fffdf8; }
.fb-name { width: auto; }
.fb-size { width: 6rem; white-space: nowrap; }
.fb-act  { width: 8rem; white-space: nowrap; }
/* Zeitstempel ganz rechts */
.fb-date { width: 11rem; white-space: nowrap; }
.fb-open, .fb-file { display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; }
.fb-open { background: none; border: 0; padding: 0; cursor: pointer; color: var(--primary); font-family: inherit; font-weight: 600; }
.fb-open:hover span { text-decoration: underline; }
.fb-file { color: var(--text); }
.fb-file svg { color: var(--muted); }

.fb-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 247, 235, .93); border: 2px dashed var(--primary); border-radius: 8px;
}
.fb-overlay[hidden] { display: none; }
.fb-overlay-inner { text-align: center; color: var(--primary-dark, #b35a00); }
.fb-overlay-inner p { margin: .5rem 0 0; font-weight: 600; }

.fb-msg { margin: 0; padding: .55rem .8rem; font-size: .85rem; border-top: 1px solid var(--border); }
.fb-msg.is-ok { background: #e4f0da; color: #3d6b2d; }
.fb-msg.is-err { background: #f5d5d5; color: #8a1f1f; }
.fb + .muted, .fb .muted.small { padding: .5rem .8rem; margin: 0; }

/* Spalte "bestellt" in den Auftragspositionen */
.qty-open { color: #92600a; font-weight: 600; cursor: help; }
.qty-full { color: #1a7f37; font-weight: 600; cursor: help; }

/* Lager-Ampel in den Auftragspositionen */
.stock-ok   { color: #1a7f37; font-weight: 600; cursor: help; }
.stock-low  { color: #92600a; font-weight: 600; cursor: help; }
.stock-none { color: #b52c2c; font-weight: 600; cursor: help; }

/* Rückfrage im Storno-Dialog: Lagerbestand behalten oder ausbuchen */
.cancel-stock {
  margin: 1rem 0 .25rem; padding: .8rem .9rem;
  background: #fff8ec; border: 1px solid #f5e0b4; border-radius: 8px;
}
.cancel-stock[hidden] { display: none; }
.cancel-stock > p { margin: 0 0 .6rem; font-size: .85rem; color: #8a5a00; }
.cancel-stock .radio-row {
  display: flex; flex-direction: row; align-items: flex-start; gap: .5rem;
  font-size: .85rem; color: var(--text); margin-bottom: .4rem; cursor: pointer;
}
.cancel-stock .radio-row:last-child { margin-bottom: 0; }
.cancel-stock .radio-row input { width: auto; margin-top: .2rem; flex: none; }

/* =================================================================
   Angebot-Detailseite: schöne Darstellung + PDF-Vorschau
   ================================================================= */
.offer-detail-head { align-items: flex-start; }
.offer-detail-headline { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.offer-detail-headline h1 { margin: 0; }
.offer-status-meta { margin: -.25rem 0 1.1rem; font-size: .85rem; }

.offer-card { padding: 1.6rem 1.8rem; }
.offer-card-top { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.offer-party-label { font-size: .72rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); margin-bottom: .4rem; }
.offer-party-body { line-height: 1.5; }
.offer-party-body .strong { font-weight: 700; }
.offer-meta-block { display: grid; grid-template-columns: auto auto; gap: .25rem 1rem; align-content: start; text-align: right; }
.offer-meta-block > div { display: contents; }
.offer-meta-block span.muted { font-size: .8rem; }
.offer-meta-block strong { font-variant-numeric: tabular-nums; }

.offer-subject { font-size: 1.25rem; margin: .5rem 0 .4rem; }
.offer-intro { white-space: pre-line; margin: 0 0 1.2rem; color: var(--text); }
.offer-items { margin-top: .4rem; }
.offer-desc-cell { white-space: pre-line; }
.totals-final { font-size: 1.05rem; margin-top: .3rem; padding-top: .3rem; border-top: 2px solid var(--accent, #de800e); }
.offer-footer-text { white-space: pre-line; margin-top: 1.2rem; font-size: .88rem; }

.offer-pdf-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.offer-pdf-head h3 { margin: 0; }
.offer-pdf-frame {
  width: 100%; height: 80vh; min-height: 600px;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #f4f5f7;
}
.offer-pdf-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Klickbarer Kundenname in der Angebotsliste – HPS-Orange */
.cust-link { color: var(--primary); text-decoration: none; border-bottom: 1px dotted transparent; transition: color .12s, border-color .12s; }
.cust-link:hover { color: var(--primary-dark); border-bottom-color: var(--primary-dark); }

/* Zurück-Pfeil auf der Angebots-Detailseite */
.offer-detail-back { margin-bottom: .6rem; }

/* =====================================================================
   Buchhaltung (Doppik)
   ===================================================================== */
.subnav {
  display: flex; gap: .15rem; border-bottom: 1px solid var(--border);
  margin: 0 0 1.25rem 0; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: thin;
}
.subnav a {
  white-space: nowrap; padding: .6rem .85rem; font-size: .9rem; color: var(--muted);
  border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; transition: color .15s, border-color .15s, background .15s;
}
.subnav a:hover { color: var(--text); background: #fafafa; text-decoration: none; }
.subnav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-mono { font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); }

/* Saldo-Ampel (Buchungsmaske, Bilanz, SuSa) */
.balance-badge { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem; border-radius: 6px; font-weight: 600; font-size: .9rem; }
.balance-ok  { background: #e4f0da; color: #3d6b2d; }
.balance-bad { background: #f5d5d5; color: #8a1f1f; }

/* Buchungsmaske */
.buch-lines { width: 100%; border-collapse: collapse; }
.buch-lines th, .buch-lines td { padding: .3rem .35rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.buch-lines th { font-size: .75rem; text-transform: uppercase; color: var(--muted); text-align: left; }
.buch-lines input, .buch-lines select { width: 100%; }
.buch-lines .num input { text-align: right; }
.buch-foot { display: flex; justify-content: flex-end; gap: 1.5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.buch-foot .sum { font-variant-numeric: tabular-nums; }
.line-del { color: var(--danger); background: none; border: 0; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 .3rem; }

/* Report-Tabellen: Summenzeile */
.report-table tfoot td, .report-foot { font-weight: 700; border-top: 2px solid var(--border); background: #f9f9f9; }
.report-group-head td { background: #f3f4f6; font-weight: 600; color: var(--text); }

/* Bilanz zweispaltig */
.bilanz-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px) { .bilanz-grid { grid-template-columns: 1fr; } }

/* UVA-Kennzahlenraster */
.kz-row { display: grid; grid-template-columns: 4rem 1fr 8rem; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.kz-row .kz-code { font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.kz-row .kz-val { text-align: right; font-variant-numeric: tabular-nums; }
.kz-result { font-size: 1.2rem; font-weight: 700; }

/* Aging-Chips */
.aging { font-size: .72rem; padding: .1rem .4rem; border-radius: 10px; background: #ebebeb; color: #555; white-space: nowrap; }
.aging.d0_30 { background: #fff0d6; color: #8a5a00; }
.aging.d31_60, .aging.d61_90 { background: #ffe0c2; color: #9a4a00; }
.aging.d90 { background: #f5d5d5; color: #8a1f1f; }
.recon-ok { color: #3d6b2d; } .recon-bad { color: #8a1f1f; font-weight: 600; }

/* =====================================================================
   Seriennummern-Generator
   ===================================================================== */
.sn-layout {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 1rem; align-items: start; margin-bottom: 1rem;
}
@media (max-width: 900px) { .sn-layout { grid-template-columns: 1fr; } }

.sn-form { margin-bottom: 0; }
.sn-form h3 { margin-bottom: 1rem; }
.sn-field { margin-bottom: .85rem; }
.sn-field > .label-text { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.sn-form .form-grid { margin-bottom: .85rem; }
.sn-actions { margin-top: 1rem; }

/* Autocomplete-Picker */
.sn-picker { position: relative; }
.sn-picker-list {
  position: absolute; z-index: 20; top: calc(100% + 2px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; padding: .25rem;
}
.sn-picker-item {
  display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: 6px; padding: .45rem .6rem; cursor: pointer; font: inherit;
}
.sn-picker-item:hover, .sn-picker-item.is-active { background: #fff3e2; }
.sn-pi-name { font-size: .9rem; color: var(--text); }
.sn-pi-sub { font-size: .78rem; color: var(--muted); }
.sn-picker-empty { padding: .6rem; color: var(--muted); font-size: .85rem; }
.sn-chosen { margin: .3rem 0 0; font-size: .8rem; }
/* Hinweis unter „Start laufende Nummer": wie viele Nummern schon vergeben sind */
.sn-next-hint { font-size: .75rem; line-height: 1.3; color: var(--muted); min-height: 1rem; }
.sn-next-hint.is-ok { color: #3d6b2d; }
.sn-next-hint.is-warn { color: #af6005; font-weight: 600; }

.sn-format { margin: .25rem 0 .5rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.sn-format > summary { cursor: pointer; color: var(--primary); font-size: .88rem; user-select: none; padding: .2rem 0; }
.sn-format > summary:hover { color: var(--primary-dark); }
.sn-format .form-grid { margin: .6rem 0 .2rem; }

/* Vorschau */
.sn-preview-card { position: sticky; top: 1rem; }
.sn-preview-serial {
  font-family: "Consolas", "SFMono-Regular", "Menlo", monospace;
  font-size: 1.7rem; font-weight: 700; color: var(--text); letter-spacing: .5px;
  background: #faf7f2; border: 1px dashed var(--primary); border-radius: 8px;
  padding: 1rem; text-align: center; word-break: break-all; line-height: 1.3;
}
.sn-preview-serial.is-placeholder { color: var(--muted); font-weight: 400; border-color: var(--border); }
.sn-preview-range { text-align: center; margin: .5rem 0 1rem; font-size: .85rem; }

.sn-legend { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.sn-seg {
  flex: 1 1 auto; min-width: 84px; display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .5rem .4rem; border-radius: 8px; background: #f7f7f8; border: 1px solid var(--border);
}
.sn-seg-val {
  font-family: "Consolas", monospace; font-weight: 700; font-size: 1rem; color: var(--primary-dark);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sn-seg-val.is-empty { color: var(--muted); font-weight: 400; }
.sn-seg-lbl { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; text-align: center; line-height: 1.1; }
.sn-preview-hint { margin: .6rem 0 0; font-size: .78rem; }

/* Liste + Druckleiste */
.sn-list-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .25rem; }
.sn-print-bar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.inline-lbl { flex-direction: row !important; align-items: center; gap: .35rem; color: var(--text); font-size: .82rem; }
.inline-lbl input[type="number"] { width: 4.5rem; }
.inline-lbl input[type="text"] { width: 9rem; }
.sn-sel-count { font-size: .82rem; }
.sn-preset-hint { margin: .1rem 0 .75rem; font-size: .8rem; }
.sn-row-new { background: #fff8ef; }
.sn-row-new:hover { background: #fff3e2; }

/* =================================================================
   Statistik: Lagerbestand je Artikel
   ================================================================= */
.stock-filter {
  min-width: 18rem; max-width: 100%;
  padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: .85rem;
}
.stock-table .stock-share-col { width: 7rem; }
/* Anteil am gebundenen Kapital: schmaler Balken statt einer weiteren Zahlenspalte. */
.stock-share { display: block; height: 6px; border-radius: 999px; background: #eef0f2; overflow: hidden; }
.stock-share-fill { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.stock-share-fill.is-neg { background: var(--danger); }

/* Belegaktionen im Kopf: Download und Drucken als farbige Icon-Buttons.
   Eigene Farben, damit sie nicht mit Ansehen (blau), Bearbeiten (orange),
   Anlegen (grün) und Löschen (rot) verwechselt werden. */
.icon-btn-pdf   { color: #4f46e5; }
.icon-btn-pdf:hover   { background: rgba(79,70,229,.10); color: #4338ca; border-color: rgba(79,70,229,.4); }
.icon-btn-print { color: #475569; }
.icon-btn-print:hover { background: rgba(71,85,105,.10); color: #334155; border-color: rgba(71,85,105,.4); }
