:root {
  --primary: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-dark: #1e40af;
  --sidebar-bg: #f8fafc;
  --sidebar-text: #475569;
  --sidebar-hover: #e2e8f0;
  --sidebar-active: #1d4ed8;
  --sidebar-border: #e2e8f0;
  --sidebar-text-strong: #0f172a;
  --sidebar-text-muted: #94a3b8;
  --sidebar-brand-bg: #f1f5f9;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

/* ── DARK MODE ───────────────────────────────────────────────────────────── */

body.dark-mode {
  --primary: #3b82f6;
  --primary-light: #1e3a5f;
  --primary-dark: #60a5fa;
  --sidebar-bg: #080f1a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --sidebar-border: #1e293b;
  --sidebar-text-strong: #e2e8f0;
  --sidebar-text-muted: #64748b;
  --sidebar-brand-bg: #0f172a;
  --bg: #0f172a;
  --card: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --success: #22c55e;
  --success-bg: #14532d;
  --warning: #f59e0b;
  --warning-bg: #451a03;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
}
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: #0f172a;
  color: var(--text);
  border-color: var(--border);
}
body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
  background: #1e293b;
}
body.dark-mode .seq-table th,
body.dark-mode .pos-table thead th { background: #1e293b; }
body.dark-mode .pos-table tr:nth-child(even) { background: rgba(255,255,255,.02); }
body.dark-mode .data-table tr:hover td { background: rgba(255,255,255,.05); }
body.dark-mode .heading-row { background: #1e3a5f !important; }
body.dark-mode .lock-banner { background: #1c1507; border-color: #b45309; color: #fde68a; }
body.dark-mode .warning-banner { background: #1c0f00; border-color: #ea580c; color: #fed7aa; }
body.dark-mode .legal-check-item.ok { background: #052e16; }
body.dark-mode .legal-check-item.missing { background: #1f0505; }
body.dark-mode .legal-all-ok { background: #052e16; border-color: #166534; color: #4ade80; }
body.dark-mode .due-date-badge { background: #1e293b; }
body.dark-mode .due-date-badge.overdue { background: #1f0505; border-color: #7f1d1d; color: #fca5a5; }
body.dark-mode .info-banner { background: #1e3a5f; border-color: #1d4ed8; color: #93c5fd; }
body.dark-mode .badge-draft   { background:#1e293b; color:#94a3b8; }

/* Dark mode toggle button (sidebar) */
#dark-mode-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-radius: 6px;
  background: none;
  border: none;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
#dark-mode-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
#dark-mode-toggle svg { width: 17px; height: 17px; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── LAYOUT ──────────────────────────────────────────────────────────────── */

#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  background: var(--sidebar-brand-bg);
  color: var(--sidebar-text-strong);
  font-size: 15px;
  font-weight: 600;
}
.brand svg { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; }

.nav-list { list-style: none; padding: 8px 0; }
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-text-muted);
  padding: 14px 16px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  margin: 1px 6px;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.nav-link.active { background: var(--primary); color: #fff; }

/* Docs submenu */
.nav-group-toggle { width: calc(100% - 12px); background: none; border: none; cursor: pointer; text-align: left; }
.nav-chevron { width: 13px !important; height: 13px !important; margin-left: auto; flex-shrink: 0; transition: transform .2s; }
.nav-group-toggle.open .nav-chevron { transform: rotate(180deg); }
.nav-group-toggle.open { color: var(--sidebar-text-strong); }
.nav-submenu { list-style: none; overflow: hidden; max-height: 0; transition: max-height .25s ease; }
.nav-submenu.open { max-height: 300px; }
.nav-sub-link { padding-left: 36px !important; font-size: 13px !important; }

#content { flex: 1; overflow-y: auto; }
#page-container { padding: 28px; max-width: 1100px; }

/* ── CARDS & COMMON ──────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Statistik bar chart ──────────────────────────────────────────────────── */
.stat-bar-chart { display:flex; align-items:flex-end; gap:6px; height:180px; }
.stat-bar-col   { flex:1; display:flex; flex-direction:column; align-items:center; height:100%; gap:2px; }
.stat-bar-val   { font-size:9px; color:var(--text-3); min-height:12px; text-align:center; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%; }
.stat-bar-wrap  { flex:1; width:100%; display:flex; align-items:flex-end; }
.stat-bar-fill  { width:100%; background:var(--primary); border-radius:3px 3px 0 0; min-height:2px; transition:height .3s; }
.stat-bar-empty { background:var(--border); opacity:.4; }
.stat-bar-lbl   { font-size:10px; color:var(--text-2); text-align:center; margin-top:3px; }
.stat-bar-cnt   { font-size:9px; color:var(--text-3); text-align:center; min-height:11px; }
.stat-row-empty td { color:var(--text-3); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header .actions { display: flex; gap: 8px; }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #fca5a5; }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-success:hover { background: #86efac; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; border-radius: 6px; background: transparent; border: none; cursor: pointer; color: var(--text-2); }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── FORMS ───────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 5px; }

input[type=text], input[type=number], input[type=email], input[type=tel],
input[type=date], input[type=password], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--card);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
textarea { resize: vertical; min-height: 70px; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }

.input-currency { position: relative; }
.input-currency input { padding-right: 28px; }
.input-currency::after { content: '€'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; font-size: 13px; }

/* ── DASHBOARD ───────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stats-grid.two-col {
  grid-template-columns: 1fr 1fr;
}
.dashboard-greeting {
  margin-bottom: 18px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 70%, #6366f1) 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dashboard-greeting-text {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -.01em;
}
.stats-grid.dashboard-widgets {
  grid-template-columns: repeat(4, 1fr);
  align-items: stretch;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--text-3); }
.stat-card.highlight { border-left: 4px solid var(--primary); }
.stat-card.success-card { border-left: 4px solid var(--success); }

/* ── TABLES ──────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  background: var(--bg);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-2);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.data-table .actions-cell { display: flex; gap: 4px; align-items: center; }
.data-table .num { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; font-weight: 600; }
.data-table .amount { text-align: right; font-weight: 600; white-space: nowrap; }
.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { color: var(--primary); }
.si { font-size: 10px; opacity: 0.3; }
.si.si-on { opacity: 1; color: var(--primary); }

/* ── STATUS BADGES ───────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-draft    { background: #f1f5f9; color: #475569; }
.badge-sent     { background: #dbeafe; color: #1d4ed8; }
.badge-accepted { background: #dcfce7; color: #15803d; }
.badge-paid     { background: #dcfce7; color: #15803d; }
.badge-overdue  { background: #fee2e2; color: #dc2626; }
.badge-cancelled{ background: #f1f5f9; color: #94a3b8; }
.badge-angebot  { background: #ede9fe; color: #7c3aed; }
.badge-auftrag  { background: #fef3c7; color: #b45309; }
.badge-rechnung { background: #dbeafe; color: #1d4ed8; }
.badge-storno   { background: #fee2e2; color: #dc2626; }

.payment-select {
  appearance: none;
  border: none;
  border-radius: 4px;
  padding: 2px 18px 2px 7px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
}
.payment-offen   { background: #fee2e2; color: #dc2626; }
.payment-bezahlt { background: #dcfce7; color: #15803d; }
body.dark-mode .payment-offen   { background: #450a0a; color: #fca5a5; }
body.dark-mode .payment-bezahlt { background: #052e16; color: #86efac; }

/* ── DOCUMENT FORM ───────────────────────────────────────────────────────── */

.doc-form-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.doc-form-header h1 { font-size: 20px; font-weight: 700; flex: 1; }

.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.form-section-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.form-section-body { padding: 18px; }

/* Positions table */
.positions-table-wrap { overflow-x: auto; }

table.pos-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pos-table th {
  background: var(--primary);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 9px 8px;
  text-align: left;
  white-space: nowrap;
}
.pos-table th.right { text-align: right; }
.pos-table td {
  padding: 4px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.pos-table tr.pos-row:nth-child(even) td { background: #f8fafc; }
.pos-table tr.pos-row:hover td { background: var(--primary-light); }
.pos-table tr.heading-row td { background: #f1f5f9; }

.pos-table input, .pos-table select {
  padding: 5px 7px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
}
.pos-table input:focus, .pos-table select:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29,78,216,.15);
}
.pos-table .col-pos    { width: 48px; text-align: center; }
.pos-table .col-type   { width: 90px; }
.pos-table .col-desc   { min-width: 200px; }
.pos-table .col-qty    { width: 75px; }
.pos-table .col-unit   { width: 75px; }
.pos-table .col-price  { width: 100px; }
.pos-table .col-tax    { width: 65px; }
.pos-table .col-disc   { width: 60px; }
.pos-table .col-total  { width: 90px; text-align: right; color: var(--primary); font-weight: 600; padding-right: 8px; white-space: nowrap; }
.pos-table .col-del    { width: 30px; text-align: center; }
.pos-table .col-opt    { width: 30px; text-align: center; }
.pos-num-cell { font-size: 11px; color: var(--text-3); text-align: center; padding-top: 9px; cursor: grab; user-select: none; white-space: nowrap; }
.pos-num-cell:active { cursor: grabbing; }
.pos-grip { color: var(--text-3); opacity: .25; margin-right: 3px; font-size: 12px; line-height: 1; transition: opacity .15s; }
.pos-row:hover .pos-grip { opacity: .7; }
.pos-row.dragging { opacity: .5; background: var(--primary-light); }
.pos-row.dragging td { border-color: var(--primary); }

.pos-details-row td { padding-top: 0; padding-bottom: 4px; }
.pos-details-input {
  font-size: 12px;
  color: var(--text-2);
  padding: 3px 7px;
  width: 100%;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 4px;
}
.pos-details-input:focus { background: #fff; border-color: var(--border); }

.pos-add-row td { padding: 8px; }
.pos-add-btns { display: flex; gap: 8px; }

/* Totals section */
.totals-box {
  display: flex;
  justify-content: flex-end;
  padding: 16px 18px;
}
.totals-inner { min-width: 300px; }
.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 13.5px;
}
.totals-row.total-final {
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
}
.totals-row .t-label { color: var(--text-2); }
.totals-row.total-final .t-label { color: rgba(255,255,255,.85); }
.totals-row .t-value { font-weight: 600; white-space: nowrap; }
.totals-divider { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

/* ── SETTINGS ────────────────────────────────────────────────────────────── */

.settings-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: -2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.settings-tab {
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-area:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-area img { max-height: 80px; max-width: 200px; object-fit: contain; }
.upload-area p { color: var(--text-3); font-size: 13px; margin-top: 8px; }

.preview-img {
  max-height: 120px;
  max-width: 300px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

/* Color picker */
.color-input-wrap { display: flex; align-items: center; gap: 10px; }
.color-input-wrap input[type=color] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Number sequences table */
.seq-table { width: 100%; border-collapse: collapse; }
.seq-table th { background: var(--bg); padding: 9px 12px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--text-2); border-bottom: 1px solid var(--border); text-align: left; }
.seq-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.seq-table tr:last-child td { border-bottom: none; }
.seq-preview { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--primary); background: var(--primary-light); padding: 2px 8px; border-radius: 4px; }

/* ── CUSTOMER PICKER ─────────────────────────────────────────────────────── */

.customer-picker-wrap { position: relative; }
.customer-picker-input { cursor: pointer; }
.customer-picker-input::placeholder { color: var(--text-3); }
.customer-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
}
.customer-option {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13.5px;
  transition: background .1s;
}
.customer-option:hover { background: var(--bg); }
.customer-option .cname { font-weight: 500; }
.customer-option .csub { font-size: 12px; color: var(--text-3); }

/* ── TOAST ───────────────────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #1e293b;
  color: #fff;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
  min-width: 260px;
}
.toast.success { background: #15803d; }
.toast.error   { background: #dc2626; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ── MODAL ───────────────────────────────────────────────────────────────── */

#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#modal-overlay.hidden { display: none; }
#modal-box {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-width: 480px;
  width: 100%;
  padding: 24px;
}
#modal-box.modal-email { max-width: 640px; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.modal-text  { color: var(--text-2); margin-bottom: 20px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* E-Mail field grid (An / CC / BCC / Betreff) */
.email-fields {
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  font-size: 13.5px;
}
.email-field-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.email-field-row:last-child { border-bottom: none; }
.email-field-lbl {
  width: 58px;
  flex-shrink: 0;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--bg);
  align-self: stretch;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border);
}
.email-field-row input {
  flex: 1;
  border: none;
  border-radius: 0;
  padding: 9px 12px;
  font-size: 13.5px;
  background: transparent;
  box-shadow: none;
}
.email-field-row input:focus {
  outline: none;
  border: none;
  box-shadow: none;
  background: #fafbff;
}
.mail-error-box {
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 6px;
  font-size: 13px;
}

/* Template chips (email modal) */
.template-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.template-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.template-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.template-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Document protocol log */
.doc-log-wrap { padding: 0 18px 18px; }
.doc-log-loading, .doc-log-empty { color: var(--text-3); font-size: 13px; padding: 12px 0; }
.doc-log { display: flex; flex-direction: column; gap: 0; }
.doc-log-entry {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.doc-log-entry:last-child { border-bottom: none; }
.doc-log-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}
.doc-log-content { flex: 1; min-width: 0; }
.doc-log-desc { font-size: 13.5px; font-weight: 500; color: var(--text); }
.doc-log-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.doc-log-time { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }

/* ── MISC ────────────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; display: block; }
.empty-state h3 { font-size: 16px; color: var(--text-2); margin-bottom: 6px; }

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.search-bar input { max-width: 320px; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
  padding: 6px 0;
  text-decoration: none;
}
.back-btn:hover { color: var(--primary); }
.back-btn svg { width: 16px; height: 16px; }

.doc-type-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.info-banner {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* GoBD lock banner */
.lock-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fefce8;
  border: 1.5px solid #fbbf24;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #78350f;
  margin-bottom: 20px;
}
.lock-banner svg { flex-shrink: 0; margin-top: 1px; color: #d97706; }

/* Warning banner (dashboard overdue) */
.warning-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff7ed;
  border: 1.5px solid #f97316;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13.5px;
  color: #7c2d12;
  margin-bottom: 20px;
  cursor: pointer;
}
.warning-banner:hover { background: #ffedd5; }

/* Fälligkeitsdatum badge */
.due-date-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  width: fit-content;
}
.due-date-badge.overdue {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}

/* Legal checklist in settings */
.legal-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legal-check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.legal-check-item.ok   { background: #f0fdf4; }
.legal-check-item.missing { background: #fef2f2; }
.legal-check-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.legal-check-item.ok    .legal-check-icon { background: #dcfce7; color: #16a34a; }
.legal-check-item.missing .legal-check-icon { background: #fee2e2; color: #dc2626; }
.legal-check-label { flex: 1; font-weight: 500; }
.legal-check-hint  { font-size: 12px; color: var(--text-3); }
.legal-all-ok {
  padding: 8px 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  color: #15803d;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
}

/* Dashboard widgets */
.clock-card   { background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); color: #fff; }
.weather-card { background: linear-gradient(135deg, #0369a1 0%, #38bdf8 100%); color: #fff; }
.clock-card .stat-label,  .clock-card .stat-sub,
.weather-card .stat-label, .weather-card .stat-sub  { color: rgba(255,255,255,.75); }
.clock-card .stat-value, .weather-card .stat-value  { color: #fff; }
#clock-kw { font-size: 12px; opacity: .7; margin-top: 4px; }

/* Weather 3-day forecast */
.weather-forecast-row { display: flex; gap: 6px; margin-top: 2px; }
.weather-forecast-day { flex: 1; background: rgba(255,255,255,.15); border-radius: 8px; padding: 6px 4px; text-align: center; }
.wf-label { font-size: 11px; font-weight: 600; opacity: .8; margin-bottom: 2px; }
.wf-icon  { font-size: 18px; line-height: 1.2; }
.wf-temp  { font-size: 11px; margin-top: 2px; display: flex; gap: 4px; justify-content: center; }
.wf-max   { font-weight: 700; }
.wf-min   { opacity: .65; }

/* Dunning / Mahnwesen section */
.dunning-section {
  margin-top: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dunning-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.dunning-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.dunning-card:last-child { border-bottom: none; }
.dunning-card:hover { background: var(--bg); }

.dunning-card-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
  border-left: 3px solid;
  padding-left: 10px;
}
.dunning-level-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: none;
}
.dunning-level-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.dunning-doc-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}
.dunning-card-center { flex: 1; min-width: 0; }
.dunning-customer {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}
.dunning-dates {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.dunning-next {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dunning-next-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}
.dunning-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
}
.dunning-badge.red    { background: #fee2e2; color: #991b1b; }
.dunning-badge.orange { background: #ffedd5; color: #9a3412; }
.dunning-badge.blue   { background: #dbeafe; color: #1e40af; }

.dunning-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Urgency row backgrounds */
.dunning-overdue  { background: #fff5f5; }
.dunning-urgent   { background: #fffbeb; }
.dunning-upcoming { background: var(--card); }

body.dark-mode .dunning-overdue  { background: #1f0505; }
body.dark-mode .dunning-urgent   { background: #1c1002; }
body.dark-mode .dunning-badge.red    { background: #450a0a; color: #fca5a5; }
body.dark-mode .dunning-badge.orange { background: #431407; color: #fdba74; }
body.dark-mode .dunning-badge.blue   { background: #1e3a5f; color: #93c5fd; }
body.dark-mode .dunning-section { border-color: var(--border); }
body.dark-mode .dunning-section-header { background: var(--bg); }

.optional-hint { font-size: 11.5px; color: var(--text-3); }

hr.section-sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.ref-badge {
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
}

.status-select {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--card);
  color: var(--text);
}

/* ── DOC ACTIONS (extracted from inline style) ───────────────────────────── */

.doc-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
}

/* ── MOBILE TOP BAR ──────────────────────────────────────────────────────── */

#topbar { display: none; }

#hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--sidebar-text-strong);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
#hamburger:hover { background: var(--sidebar-hover); }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sidebar-text-strong);
  font-size: 15px;
  font-weight: 600;
}
.topbar-brand svg { color: var(--primary); }

/* ── SIDEBAR BACKDROP (mobile) ───────────────────────────────────────────── */

#sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  display: block;
}
#sidebar-backdrop.visible { opacity: 1; pointer-events: all; }

/* ── RESPONSIVE: iPad Hochformat (768 – 1023 px) ─────────────────────────── */

@media (min-width: 768px) and (max-width: 1023px) {
  #sidebar {
    width: 64px;
    min-width: 64px;
    flex-shrink: 0;
  }
  .brand {
    justify-content: center;
    padding: 18px 0;
  }
  .brand-text { display: none; }
  .nav-text   { display: none; }
  .nav-group-label { display: none; }
  .nav-link {
    justify-content: center;
    padding: 11px 0;
    margin: 2px 8px;
  }
  .nav-link svg { width: 20px; height: 20px; }
  .nav-group-toggle { justify-content: center; width: calc(100% - 16px); }
  .nav-chevron { display: none !important; }
  .nav-submenu { max-height: none !important; }
  .nav-sub-link { padding-left: 0 !important; justify-content: center; }

  #page-container { padding: 20px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid.dashboard-widgets { grid-template-columns: repeat(2, 1fr); }

  .form-row.cols-3 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-4 { grid-template-columns: 1fr 1fr; }

  /* prevent grid-column:span from expanding 2-col grid */
  .form-row.cols-3 > *,
  .form-row.cols-4 > * { grid-column: auto !important; }

  .doc-form-header { flex-wrap: wrap; gap: 8px; }
  .doc-actions { margin-left: 0; width: 100%; justify-content: flex-end; }

  #modal-box { max-width: min(480px, calc(100vw - 32px)); }
}

/* ── RESPONSIVE: iPad Querformat + Desktop (≥ 1024 px) ──────────────────── */
/* default CSS already handles this — sidebar 220px, full grids             */

/* ── RESPONSIVE: Mobile Hochformat (< 768 px) ───────────────────────────── */

@media (max-width: 767px) {

  /* ── iOS zoom prevention: inputs must be ≥16px ── */
  input, select, textarea { font-size: 16px !important; }

  /* ── Topbar ── */
  #topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--sidebar-bg);
    z-index: 500;
    padding: 0 14px;
    border-bottom: 1px solid var(--sidebar-border);
  }

  /* ── App layout ── */
  #app { height: calc(100vh - 52px); margin-top: 52px; }

  /* ── Sidebar: off-canvas ── */
  #sidebar {
    position: fixed;
    top: 0; left: -280px;
    width: 270px; min-width: 270px;
    height: 100vh;
    z-index: 999;
    transition: left .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  #sidebar.open { left: 0; }

  /* ── Content ── */
  #content { width: 100%; }
  #page-container { padding: 12px; }

  /* ── Page header ── */
  .page-header { flex-wrap: wrap; gap: 8px; padding-bottom: 4px; }
  .page-header h1 { font-size: 18px; }
  .page-header .actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  .page-header .actions select,
  .page-header .actions .btn { flex: 1; min-width: 0; }

  /* ── Form layout ── */
  .form-row.cols-2,
  .form-row.cols-3,
  .form-row.cols-4 { grid-template-columns: 1fr; }
  .form-row > * { grid-column: 1 !important; }
  .form-section-body { padding: 14px; }
  .form-section-header { padding: 12px 14px; font-size: 13px; }

  /* ── Doc form ── */
  .doc-form-header { flex-wrap: wrap; align-items: center; gap: 8px; }
  .doc-form-header h1 { font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .doc-actions { width: 100%; margin-left: 0 !important; justify-content: flex-start; gap: 6px; flex-wrap: wrap; }
  .doc-actions .btn { flex: 1; min-width: 80px; justify-content: center; }
  .doc-actions .btn-icon { flex: 0; }

  /* ── Positions table ── */
  .positions-table-wrap { -webkit-overflow-scrolling: touch; }
  .positions-table-wrap::after,
  .table-wrap::after {
    content: '';
    position: sticky;
    right: 0;
    display: block;
    width: 24px;
    height: 1px;
    margin-top: -1px;
    margin-left: auto;
    background: linear-gradient(90deg, transparent, var(--card));
    pointer-events: none;
  }
  table.pos-table { min-width: 720px; }
  table.pos-table { font-size: 12px; }
  .pos-table th, .pos-table td { padding: 4px 3px; }
  .pos-table .col-type   { width: 70px; }
  .pos-table .col-qty    { width: 55px; }
  .pos-table .col-unit   { width: 55px; }
  .pos-table .col-price  { width: 80px; }
  .pos-table .col-tax    { width: 52px; }
  .pos-table .col-disc   { width: 46px; }

  /* ── Totals ── */
  .totals-box { padding: 12px 14px; }
  .totals-inner { min-width: 0; width: 100%; }

  /* ── Data tables ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
  .data-table { min-width: 480px; }
  .data-table th, .data-table td { padding: 8px 10px; font-size: 13px; }

  /* Dashboard: open invoices become mobile cards instead of a squeezed table. */
  .open-invoices-wrap { overflow: visible; }
  .open-invoices-wrap > div:first-child {
    align-items: flex-start !important;
    gap: 4px;
    flex-direction: column;
  }
  .open-invoices-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
  }
  .open-invoices-table thead { display: none; }
  .open-invoices-table tbody { display: block; padding: 0 12px 12px; }
  .open-invoices-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
  }
  .open-invoices-table td {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 0 !important;
    border: 0 !important;
    font-size: 13px;
  }
  .open-invoices-table td::before {
    color: var(--text-3);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  .open-invoices-table td:nth-child(1)::before { content: 'Nummer'; }
  .open-invoices-table td:nth-child(2)::before { content: 'Kunde'; }
  .open-invoices-table td:nth-child(3)::before { content: 'Datum'; }
  .open-invoices-table td:nth-child(4)::before { content: 'Netto'; }
  .open-invoices-table td:nth-child(5)::before { content: 'Brutto'; }
  .open-invoices-table td:nth-child(1),
  .open-invoices-table td:nth-child(2),
  .open-invoices-table td:nth-child(6) { grid-column: 1 / -1; }
  .open-invoices-table td:nth-child(4),
  .open-invoices-table td:nth-child(5) { text-align: left !important; }
  .open-invoices-table td:nth-child(6) .btn { width: 100%; justify-content: center; }

  /* ── Stat cards ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stats-grid.dashboard-widgets { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
  .stat-card { padding: 14px 12px; }

  /* ── Search bar ── */
  .search-bar { flex-wrap: wrap; gap: 8px; }
  .search-bar input { max-width: 100% !important; flex: 1; min-width: 0; }
  .search-bar select { flex: 1; min-width: 0; }

  /* ── Buttons ── */
  .btn { padding: 9px 12px; min-height: 38px; }
  .btn-sm { padding: 7px 10px; min-height: 32px; }
  .btn-icon { padding: 8px; min-height: 36px; min-width: 36px; }
  .doc-actions .btn-primary { flex-grow: 1.4; }

  /* ── Tab rows: horizontal scroll (no wrapping) ── */
  .proj-tabs,
  .settings-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .proj-tabs::-webkit-scrollbar,
  .settings-tabs::-webkit-scrollbar { display: none; }
  .proj-tab { flex-shrink: 0; white-space: nowrap; padding: 9px 14px; font-size: 13px; }
  .settings-tab { flex-shrink: 0; white-space: nowrap; padding: 8px 14px; }

  /* ── Kanban ── */
  .kanban-board { grid-template-columns: 1fr; }
  .proj-stat-grid { grid-template-columns: 1fr 1fr; }

  /* ── Calendar ── */
  .cal-cell { min-height: 58px; padding: 4px 3px; }
  .cal-day-num { font-size: 11px; }
  .cal-apt { font-size: 10px; padding: 1px 3px; }
  .cal-apt-time { display: none; }
  .cal-th { font-size: 10px; padding: 7px 0; letter-spacing: 0; }

  /* ── Modal ── */
  #modal-overlay { align-items: flex-end; padding: 0; }
  #modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    max-height: 85svh;
    overflow-y: auto;
    margin: 0;
    padding: 20px 16px 28px;
    border-radius: 18px 18px 0 0;
  }
  .modal-actions { position: sticky; bottom: 0; background: var(--card); padding-top: 12px; margin-top: 4px; }

  /* ── Toast ── */
  #toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: unset; width: 100%; }

  /* ── Settings sequence table ── */
  .seq-table { min-width: 560px; }
  .form-section-body:has(.seq-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0; }

  /* ── Buchhaltung: header controls wrap to 2 rows ── */
  .buch-method-row { flex-wrap: wrap; }
  .buch-method-hint { display: none !important; }
  #buch-year, #buch-month { flex: 1; min-width: 0; }

  /* ── Buchhaltung: KPI grid ── */
  .buch-kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .buch-kpi-card { padding: 12px 14px; gap: 10px; }
  .buch-kpi-icon { width: 36px; height: 36px; font-size: 14px; }
  .buch-kpi-value { font-size: 17px; }
  .buch-kpi-sub { font-size: 11px; }

  /* ── Buchhaltung: main layout ── */
  .buch-main-row { grid-template-columns: 1fr; }
  .buch-summary-grid { grid-template-columns: 1fr; }
  .buch-aging-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .buch-side-cards { flex-direction: row; flex-wrap: wrap; }
  .buch-side-card { flex: 1; min-width: 140px; }

  /* ── Dunning ── */
  .dunning-card { flex-wrap: wrap; }

  /* ── Back button ── */
  .back-btn { padding: 8px 0; }

  /* ── Dashboard greeting ── */
  .dashboard-greeting { padding: 14px 16px; }
  .dashboard-greeting-text { font-size: 18px; }

  /* ── Document list: card layout ── */
  #doc-table { min-width: 0; border-collapse: separate; border-spacing: 0 8px; }
  #doc-table thead { display: none; }
  #doc-table tbody { display: block; }
  #doc-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    box-shadow: var(--shadow);
  }
  #doc-table td { display: none; }
  #doc-table td:nth-child(1) {
    display: flex; align-items: center;
    grid-column: 1; grid-row: 1;
    font-weight: 600; font-size: 14px;
  }
  #doc-table td:nth-child(2) {
    display: block;
    grid-column: 1 / -1; grid-row: 2;
    font-size: 13px; color: var(--text-2); padding-top: 1px;
  }
  #doc-table td.amount {
    display: flex; align-items: center; justify-content: flex-end;
    grid-column: 2; grid-row: 1;
    font-weight: 600; font-size: 13px;
  }
  #doc-table td:last-child {
    display: flex; align-items: center; gap: 6px;
    grid-column: 1 / -1; grid-row: 3;
    border-top: 1px solid var(--border);
    padding-top: 8px; margin-top: 4px;
  }

  /* ── Kunden list: hide secondary columns ── */
  table:has(#cust-tbody) { min-width: 0; }
  table:has(#cust-tbody) th:nth-child(1),
  table:has(#cust-tbody) td:nth-child(1),
  table:has(#cust-tbody) th:nth-child(3),
  table:has(#cust-tbody) td:nth-child(3),
  table:has(#cust-tbody) th:nth-child(4),
  table:has(#cust-tbody) td:nth-child(4),
  table:has(#cust-tbody) th:nth-child(5),
  table:has(#cust-tbody) td:nth-child(5) { display: none; }

  /* ── Dashboard Letzte Dokumente: hide Typ + Datum ── */
  table:has(#recent-tbody) { min-width: 0; }
  table:has(#recent-tbody) th:nth-child(1),
  table:has(#recent-tbody) td:nth-child(1),
  table:has(#recent-tbody) th:nth-child(4),
  table:has(#recent-tbody) td:nth-child(4) { display: none; }
}

/* ── STATUS ACTION BUTTONS ─────────────────────────────────────────────────── */
.btn-success { background: #16a34a; color: #fff; border: none; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: #d97706; color: #fff; border: none; }
.btn-warning:hover { background: #b45309; }
.status-badge-form {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  margin-left: 8px; vertical-align: middle;
}
.locked-banner {
  background: #fef3c7; border: 1px solid #fcd34d; color: #92400e;
  border-radius: 8px; padding: 10px 16px; margin-bottom: 16px;
  font-size: 13px; font-weight: 500;
}
.locked-hint { color: var(--text-3); font-size: 13px; font-style: italic; }

/* ── SIDEBAR USER AREA ───────────────────────────────────────────────────── */
.sidebar-user-area {
  margin-top: auto;
  padding: 10px 14px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--sidebar-text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10.5px; color: var(--sidebar-text-muted); }
.sidebar-logout-btn {
  color: var(--sidebar-text-muted) !important;
  flex-shrink: 0;
  opacity: .7;
}
.sidebar-logout-btn:hover { opacity: 1; color: var(--danger) !important; }
.sidebar-logout-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-top: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sidebar-logout-row:hover {
  background: rgba(239,68,68,.1);
  color: var(--danger);
}
.sidebar-logout-row svg { flex-shrink: 0; }

/* ── FULL CALENDAR PAGE ──────────────────────────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.cal-nav-label {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  text-align: center;
}
.cal-grid {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-header-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.cal-th {
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
  padding: 9px 0;
}
.cal-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-cell {
  min-height: 100px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  transition: background .1s;
  overflow: hidden;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell-empty { cursor: default; background: var(--bg); opacity: .5; }
.cal-cell:not(.cal-cell-empty):hover { background: var(--primary-light); }
.cal-cell-today { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.cal-day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 4px;
  line-height: 1;
}
.cal-day-num.today {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-weight: 700;
}
.cal-apt {
  font-size: 11.5px;
  padding: 2px 5px;
  border-radius: 4px;
  margin-bottom: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity .1s;
}
.cal-apt:hover { opacity: .8; }
.cal-apt-time {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  flex-shrink: 0;
}
.cal-apt-title {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-weight: 500;
}
.cal-color-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cal-color-opt input { display: none; }
.cal-color-opt span {
  display: block;
  width: 24px; height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform .1s, border-color .1s;
}
.cal-color-opt input:checked + span {
  border-color: var(--text);
  transform: scale(1.15);
}
.cal-color-opt span:hover { transform: scale(1.1); }

/* ── MODAL FORM ──────────────────────────────────────────────────────────── */
.modal-form { margin-bottom: 20px; }
.modal-form .form-group { margin-bottom: 14px; }
.modal-form .form-group:last-child { margin-bottom: 0; }
.modal-form label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.modal-form input, .modal-form select { width: 100%; box-sizing: border-box; }

/* ── APPOINTMENT MODAL ───────────────────────────────────────────────────── */
.apt-modal { display: flex; flex-direction: column; gap: 0; }
.apt-modal-header {
  display: flex; align-items: center; gap: 10px;
  padding: 0 0 18px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.apt-modal-header .apt-modal-icon { font-size: 22px; line-height: 1; }
.apt-modal-header h2 { margin: 0; font-size: 17px; font-weight: 700; color: var(--text); }
.apt-modal-body { display: flex; flex-direction: column; gap: 16px; }
.apt-field { display: flex; flex-direction: column; gap: 5px; }
.apt-field label {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-2);
}
.apt-field .apt-req { color: var(--danger, #dc2626); }
.apt-field input[type="text"],
.apt-field input[type="date"],
.apt-field input[type="time"],
.apt-field textarea {
  width: 100%; box-sizing: border-box;
  padding: 9px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; color: var(--text);
  background: var(--bg); transition: border-color .15s;
  font-family: inherit;
}
.apt-field input:focus, .apt-field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}
.apt-field textarea { resize: vertical; min-height: 72px; }
.apt-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.apt-field-row .apt-field-full { grid-column: 1 / -1; }
.apt-color-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 4px 0; }
.apt-color-swatch input { display: none; }
.apt-color-swatch span {
  display: block; width: 28px; height: 28px; border-radius: 50%;
  background: var(--swatch); cursor: pointer;
  border: 3px solid transparent; outline: 2px solid transparent;
  transition: transform .12s, outline-color .12s;
}
.apt-color-swatch input:checked + span {
  border-color: #fff; outline-color: var(--swatch); transform: scale(1.18);
}
.apt-color-swatch span:hover { transform: scale(1.12); }
.apt-modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 0; margin-top: 4px; border-top: 1px solid var(--border); gap: 10px;
}
.apt-footer-actions { display: flex; gap: 8px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ── DOCUMENT LAYOUT PREVIEW ─────────────────────────────────────────────── */
.doc-preview-block { transition: opacity .2s, box-shadow .15s, transform .1s; }
.doc-preview-block[draggable="true"]:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.doc-preview-block[draggable="true"]:active { cursor: grabbing; }
.doc-preview-block.drag-over {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
  transform: scale(1.015);
}

/* Project detail tabs */
.proj-tabs { display:flex; gap:2px; border-bottom: 2px solid var(--border); margin-bottom:20px; }
.proj-tab { padding:10px 18px; border:none; background:none; cursor:pointer; font-size:14px; color:var(--text-2); font-weight:500; border-bottom:2px solid transparent; margin-bottom:-2px; transition:color .15s; }
.proj-tab:hover { color:var(--text); }
.proj-tab.active { color:var(--primary); border-bottom-color:var(--primary); font-weight:600; }

/* Kanban */
.kanban-board { display:grid; grid-template-columns:1fr 1fr 1fr; gap:16px; align-items:start; }
.kanban-col { background:var(--bg); border-radius:10px; padding:14px; }
.kanban-col-header { font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--text-2); margin-bottom:12px; display:flex; justify-content:space-between; align-items:center; }
.task-card { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:12px; margin-bottom:8px; }
.task-card-title { font-size:14px; font-weight:600; color:var(--text); margin-bottom:6px; }
.task-card-meta { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-bottom:8px; }
.task-card-actions { display:flex; gap:4px; justify-content:flex-end; }
.priority-badge { font-size:10px; font-weight:700; padding:2px 7px; border-radius:10px; }

/* Progress bar */
.proj-progress { height:8px; background:var(--border); border-radius:4px; overflow:hidden; margin:8px 0; }
.proj-progress-fill { height:100%; background:var(--primary); border-radius:4px; transition:width .3s; }

/* Stat cards */
.proj-stat-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:12px; margin-bottom:20px; }
.proj-stat-card { background:var(--card); border:1px solid var(--border); border-radius:10px; padding:14px 16px; }
.proj-stat-label { font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:var(--text-2); margin-bottom:4px; }
.proj-stat-value { font-size:22px; font-weight:700; color:var(--text); }

/* Comments */
.comment-item { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:12px 14px; margin-bottom:10px; }
.comment-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:6px; }
.comment-author { font-size:12px; font-weight:700; color:var(--text); }
.comment-time { font-size:11px; color:var(--text-3); }
.comment-body { font-size:14px; color:var(--text); line-height:1.5; white-space:pre-wrap; }

/* Milestone row */
.milestone-row { display:flex; align-items:center; gap:10px; padding:10px 12px; background:var(--card); border:1px solid var(--border); border-radius:8px; margin-bottom:8px; }
.milestone-check { width:18px; height:18px; cursor:pointer; accent-color:var(--primary); }
.milestone-title { flex:1; font-size:14px; font-weight:500; }
.milestone-title.done { text-decoration:line-through; color:var(--text-3); }


/* ── BUCHHALTUNG ─────────────────────────────────────────────────────────── */

/* KPI Cards */
.buch-kpi-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:24px; }
.buch-kpi-card { background:var(--card); border:1px solid var(--border); border-radius:12px; padding:18px 20px; display:flex; align-items:center; gap:16px; }
.buch-kpi-icon { width:44px; height:44px; border-radius:10px; display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:18px; font-weight:800; }
.buch-kpi-label { font-size:12px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:var(--text-2); margin-bottom:4px; }
.buch-kpi-value { font-size:22px; font-weight:800; color:var(--text); line-height:1.1; }
.buch-kpi-sub { font-size:12px; color:var(--text-3); margin-top:3px; }
.buch-kpi-sub.pos { color:var(--success); }
.buch-kpi-sub.neg { color:var(--danger); }
.buch-neg { color:var(--danger) !important; }

/* Main row layout */
.buch-main-row { display:grid; grid-template-columns:1fr 220px; gap:20px; align-items:start; }

/* Bar chart */
.buch-chart-card { padding:20px; }
.buch-chart { display:flex; align-items:flex-end; gap:6px; height:140px; padding-top:8px; }
.buch-bar-col { flex:1; display:flex; flex-direction:column; align-items:center; gap:0; }
.buch-bar-wrap { flex:1; width:100%; display:flex; align-items:flex-end; }
.buch-bar { width:100%; background:var(--primary); border-radius:4px 4px 0 0; position:relative; min-height:0; transition:height .3s; opacity:.85; }
.buch-bar:hover { opacity:1; }
.buch-bar-net { position:absolute; bottom:0; left:0; right:0; background:var(--primary); border-radius:4px 4px 0 0; opacity:1; }
.buch-bar { background: rgba(29,78,216,.35); }
.buch-bar-net { background:var(--primary); }
.buch-bar-label { font-size:10px; color:var(--text-3); margin-top:4px; white-space:nowrap; }
.buch-legend { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text-2); margin-top:12px; }
.buch-legend-dot { display:inline-block; width:10px; height:10px; border-radius:2px; }

/* Side cards */
.buch-side-cards { display:flex; flex-direction:column; gap:16px; }
.buch-side-card { padding:18px; }
.buch-side-card.buch-warn { border-left:3px solid var(--danger); }
.buch-side-label { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--text-2); margin-bottom:6px; }
.buch-side-value { font-size:24px; font-weight:800; color:var(--text); line-height:1; margin-bottom:4px; }
.buch-side-sub { font-size:12px; color:var(--text-3); }
.buch-side-overdue { font-size:12px; color:var(--danger); font-weight:600; margin-top:6px; }

/* EÜR summary */
.buch-summary-grid { display:grid; grid-template-columns:1fr 1fr; gap:20px; }
.buch-summary-card { padding:20px; }
.buch-summary-title { font-size:13px; font-weight:700; color:var(--text-2); text-transform:uppercase; letter-spacing:.05em; margin-bottom:14px; }
.buch-summary-row { display:flex; justify-content:space-between; align-items:center; padding:8px 0; font-size:14px; color:var(--text); }
.buch-summary-divider { border-top:2px solid var(--border); margin:8px 0; }

/* VAT */
.buch-rate-badge { display:inline-block; padding:2px 8px; border-radius:10px; font-size:12px; font-weight:700; background:var(--primary-light); color:var(--primary); }

/* Aging */
.buch-aging-grid { display:grid; grid-template-columns:repeat(5,1fr); gap:12px; }
.buch-aging-card { padding:14px 16px; }
.buch-aging-label { font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:var(--text-2); margin-bottom:6px; }
.buch-aging-value { font-size:18px; font-weight:700; color:var(--text); }

/* Expense categories */
.buch-cat-badge { display:inline-block; padding:2px 8px; border-radius:10px; font-size:11px; background:var(--bg); color:var(--text-2); border:1px solid var(--border); white-space:nowrap; }

/* Responsive */
@media (max-width:1100px) {
  .buch-kpi-grid { grid-template-columns:1fr 1fr; }
  .buch-aging-grid { grid-template-columns:1fr 1fr 1fr; }
}

.badge-channel {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  vertical-align: middle;
  margin-left: 4px;
  opacity: 0.85;
  letter-spacing: 0.02em;
}
