:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2430;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1f5fa8;
  --primary-hover: #174d8a;
  --primary-soft: #e8f0fb;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --success: #1e8a4c;
  --success-soft: #e6f6ec;
  --warning: #b7791f;
  --warning-soft: #fdf3e1;
  --sidebar: #16212f;
  --sidebar-text: #c6d0dc;
  --sidebar-active: #253447;
  --input-bg: #f0f4f9;  /* Eingabefelder leicht graublau */
  --input-border: #d3dce8;
  --thead-bg: #e6ecf4;
  --thead-text: #33475f;
  --thead-line: #b9c6d6;
  --topbar-h: 58px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #17212d;
    --surface-2: #1c2836;
    --text: #e3e9f0;
    --muted: #94a3b8;
    --border: #2a3847;
    --primary: #5a9be6;
    --primary-hover: #7bb0ec;
    --primary-soft: #1d3149;
    --danger: #ef6b5b;
    --danger-soft: #3a1f1d;
    --success: #4cc283;
    --success-soft: #173326;
    --warning: #e3a94b;
    --warning-soft: #3a2d17;
    --sidebar: #0b1118;
    --sidebar-active: #1c2836;
    --input-bg: #1d2a3a;
    --input-border: #33465c;
    --thead-bg: #24344a;
    --thead-text: #c9d5e3;
    --thead-line: #3b4f68;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 650; }
h3 { font-size: .95rem; margin: 0 0 .5rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.svg-icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--sidebar); color: var(--sidebar-text); flex: none; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.2rem; color: #fff; font-weight: 700; font-size: 1.1rem; }
.btn.company-choice { justify-content: flex-start; text-align: left; padding: .75rem 1rem; height: auto; white-space: normal; }
.btn.company-choice > span { display: block; width: 100%; text-align: left; }
.brand-switch { display: block; margin: -.6rem 1.2rem .4rem 3.3rem; font-size: .75rem; color: var(--sidebar-text); opacity: .75;
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.brand-switch:hover { opacity: 1; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-company { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1rem; }
.brand-app { font-size: .72rem; font-weight: 500; opacity: .65; letter-spacing: .02em; }
.topbar-heading { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title { font-size: 1.2rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: .5rem; min-width: 0; }
.topbar-title .badge { font-size: .72rem; }
.topbar-company { display: none; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 960px) { .topbar-company { display: block; } .topbar-title { font-size: 1.05rem; } }
.page-head h1.in-topbar { display: none; }
.brand-mark { flex: none; width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #1f5fa8); display: grid; place-items: center; font-size: .9rem; }
.nav { padding: .25rem .6rem 1rem; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8a9a; padding: 1rem .6rem .35rem; }
.nav a { display: flex; align-items: center; gap: .65rem; color: var(--sidebar-text); padding: .5rem .6rem; border-radius: 8px; font-size: .92rem; }
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #3b82f6; }
.nav > a, .nav-group-head { margin-top: 2px; }

/* Gruppen mit Untermenü */
.nav-group-head { display: flex; align-items: center; gap: .65rem; width: 100%; color: var(--sidebar-text); padding: .5rem .6rem;
  border-radius: 8px; font: inherit; font-size: .92rem; background: none; border: 0; cursor: pointer; text-align: left; }
.nav-group-head:hover { background: var(--sidebar-active); color: #fff; }
.nav-group-head.active { color: #fff; }
.nav-group-head .chev { margin-left: auto; display: inline-flex; opacity: .6; transition: transform .15s ease; }
.nav-group-head .chev .svg-icon { width: 14px; height: 14px; }
.nav-group.open > .nav-group-head .chev { transform: rotate(90deg); }
.nav-sub { display: none; padding: .1rem 0 .3rem 1.95rem; }
.nav-group.open > .nav-sub { display: block; }
.nav-sub a { padding: .36rem .6rem; font-size: .88rem; }
.nav-sub-title { display: none; }
.nav-sub-sep { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8a9a; padding: .55rem .6rem .2rem; }

/* Einklappen */
.sidebar-foot { margin-top: auto; padding: .5rem .6rem .8rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.nav-collapse { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .45rem .6rem; border-radius: 8px;
  background: none; border: 0; color: #9aa7b6; font: inherit; font-size: .85rem; cursor: pointer; }
.nav-collapse:hover { background: var(--sidebar-active); color: #fff; }
@media (max-width: 960px) { .sidebar-foot { display: none; } }
@media (min-width: 961px) {
  .sidebar { transition: width .15s ease; }
  body.nav-collapsed .sidebar { width: 64px; overflow: visible; }
  body.nav-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  body.nav-collapsed .brand-text, body.nav-collapsed .brand-switch, body.nav-collapsed .nav > a > span,
  body.nav-collapsed .nav-group-head > span, body.nav-collapsed .nav-collapse > span { display: none; }
  body.nav-collapsed .nav { padding: .25rem .5rem 1rem; }
  body.nav-collapsed .nav > a, body.nav-collapsed .nav-group-head, body.nav-collapsed .nav-collapse { justify-content: center; padding: .6rem 0; }
  body.nav-collapsed .nav-collapse .svg-icon { transform: rotate(180deg); }
  /* Untermenü als seitliches Menü beim Darüberfahren bzw. per Tastatur */
  body.nav-collapsed .nav-group { position: relative; }
  body.nav-collapsed .nav-group > .nav-sub { display: none; position: absolute; left: 100%; top: -.3rem; z-index: 60; min-width: 230px;
    padding: .4rem; margin-left: .35rem; background: var(--sidebar); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
  body.nav-collapsed .nav-group > .nav-sub::before { content: ""; position: absolute; left: -.6rem; top: 0; bottom: 0; width: .6rem; }
  body.nav-collapsed .nav-group:hover > .nav-sub, body.nav-collapsed .nav-group:focus-within > .nav-sub { display: block; }
  body.nav-collapsed .nav-sub-title { display: block; font-weight: 650; color: #fff; padding: .35rem .6rem .45rem; font-size: .9rem; }
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
/* Seitenleiste vor dem Seiteninhalt (mitlaufende Tabellenköpfe, Kopfleiste), damit Untermenüs ganz vorne liegen */
.sidebar { z-index: 30; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.backdrop { display: none; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .content { padding: 1rem; }
  .topbar { padding: .5rem 1rem; }
}

/* ---------- Komponenten ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-left: auto; }
.page-head:has(> h1.in-topbar:only-child) { display: none; }  /* nur Überschrift – steht jetzt oben */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
/* overflow: clip statt hidden – schneidet die Ecken ab, ohne Scroll-Container zu sein (sonst kein sticky) */
.card.flush { padding: 0; overflow: clip; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.split > * { min-width: 0; }  /* Grid-Spalten nicht auf die Mindestbreite breiter Tabellen aufblähen */
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.kpi { display: flex; flex-direction: column; gap: .25rem; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.danger .value { color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; min-height: 40px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .3rem .6rem; min-height: 32px; font-size: .85rem; }
.btn.icon { padding: .4rem; min-width: 36px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.draft { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.final, .badge.sent { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.paid { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.badge.overdue { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--success-soft); color: var(--success); border: 1px solid transparent; }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.info { background: var(--primary-soft); color: var(--primary); }
tr.group-head td { background: var(--surface-2); }
/* Positionsarten im Beleg-Editor */
.lines .kind-select { width: 100%; min-height: 0; font-size: .75rem; padding: .15rem .2rem; margin: .2rem 0 .1rem; }
.lines-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .5rem; }
.lines-head h2 { margin: 0; flex: 1; }
.lines-head .tax-mode { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.lines-head .tax-mode select { width: auto; }
form.tax-free .lines .c-tax select { opacity: .45; }  /* USt-frei: Schlüssel der Positionen ohne Wirkung */
tr.line.k-title td, tr.line.k-title2 td { background: var(--surface-2); }
tr.line.k-title [name="l_name"], tr.line.k-title2 [name="l_name"] { font-weight: 700; }
tr.line:is(.k-title, .k-title2, .k-text) .c-total { color: transparent; }
tr.line:is(.k-title, .k-title2, .k-text) :is(.c-qty, .c-unit, .c-price, .c-disc, .c-tax) > *,
tr.line.k-subtotal :is(.c-qty, .c-unit, .c-price, .c-disc, .c-tax) > *,
tr.line.k-subtotal textarea,
tr.line.k-text [name="l_name"] { visibility: hidden; }
tr.line.k-text [name="l_name"] { position: absolute; }
tr.line.k-optional [data-line-total] { color: var(--muted); font-style: italic; }
tr.line.k-subtotal td { border-top: 2px solid var(--text, #222); }
tr.line.k-subtotal [name="l_name"], tr.line.k-subtotal [data-line-total] { font-weight: 700; }
/* Plantafel: Abwesenheiten und Feiertage */
.absence-chip { display: block; border-radius: 6px; padding: 2px 6px; margin-bottom: 4px; font-size: .75rem; font-weight: 600; text-decoration: none; background: var(--success-soft); color: var(--success); border: 1px solid transparent; }
.absence-chip:hover { text-decoration: none; filter: brightness(.97); }
.absence-chip.k-sick { background: var(--danger-soft); color: var(--danger); }
.absence-chip.k-comp, .absence-chip.k-unpaid { background: var(--warning-soft); color: var(--warning); }
.absence-chip.k-training, .absence-chip.k-special { background: var(--primary-soft); color: var(--primary); }
.absence-chip.requested { background: transparent; border: 1px dashed currentColor; font-weight: 500; }
table.board thead th .hol { font-size: .7rem; font-weight: 500; color: var(--danger); }
/* Arbeitszeitkonto */
table.worktime tr.weekend td { background: var(--surface-2); }
.wt-error { color: var(--danger); font-weight: 600; }
.wt-warn { color: var(--warning); }
.wt-info { color: var(--muted); }
/* Auswahl des Ersatz-Standorts, wenn kein GPS verfügbar ist */
.place-ask { flex-basis: 100%; width: 100%; margin-top: .6rem; padding: .75rem; border: 1px solid var(--warning); background: var(--warning-soft); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .5rem; }
.place-ask p { flex-basis: 100%; margin: 0 0 .25rem; }
.place-ask .btn { white-space: normal; text-align: left; }
th a.sort { color: inherit; text-decoration: none; }
th a.sort .sort-ind { margin-left: .25rem; font-size: .75em; opacity: .35; }
th a.sort.active .sort-ind, th a.sort:hover .sort-ind { opacity: 1; }
/* Sortieren/Filtern im Browser (app.js: initTableTools) */
th.tt-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.tt-sort .sort-ind { margin-left: .25rem; font-size: .75em; opacity: .35; }
th.tt-sort.active .sort-ind, th.tt-sort:hover .sort-ind, th.tt-sort:focus-visible .sort-ind { opacity: 1; }
.tt-bar { margin-bottom: .75rem; }
.card + .tt-bar, .grid + .tt-bar { margin-top: 1rem; }
.errors { background: var(--danger-soft); color: var(--danger); padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.errors ul { margin: 0; padding-left: 1.2rem; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--thead-text); font-weight: 700; background: var(--thead-bg); }
/* Spaltenköpfe bleiben beim Scrollen unter der Kopfleiste stehen; Linie als Schatten, da Tabellenrahmen nicht mitwandern */
table.list thead th { position: sticky; top: var(--topbar-h); z-index: 5; box-shadow: inset 0 -2px 0 var(--thead-line); border-bottom: none; }
.lines thead th { background: var(--thead-bg); color: var(--thead-text); box-shadow: inset 0 -2px 0 var(--thead-line); }
@media (min-width: 701px) {
  .table-wrap { overflow-x: visible; }  /* ab Tablet-Breite kein eigener Scroll-Bereich → sticky wirkt */
  .table-wrap:has(> table.lines) { overflow-x: auto; }  /* breiter Positions-Editor scrollt weiterhin seitlich */
}
table.list tbody tr:hover { background: var(--primary-soft); }
table.list tr.clickable { cursor: pointer; }
table.list td.right, table.list th.right { text-align: right; }
table.list tr:last-child td { border-bottom: none; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
/* Nebenspalten schon bei mittlerer Breite ausblenden, damit Listen ohne seitliches Scrollen passen (sticky Köpfe) */
@media (max-width: 1250px) { .hide-sm { display: none; } }

/* Listen als Karten auf dem Handy (table.list.cards): c-title + c-status oben, c-sub, darunter c-meta + c-amount */
.c-only, .sort-select { display: none; }
@media (max-width: 640px) {
  table.list.cards thead { display: none; }
  table.list.cards tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem;
    padding: .75rem .9rem; border-bottom: 1px solid var(--border); }
  table.list.cards tbody tr:last-child { border-bottom: 0; }
  table.list.cards td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; }
  table.list.cards td.hide-sm { display: none; }
  table.list.cards td.c-title { grid-column: 1; grid-row: 1; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.list.cards td.c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  table.list.cards td.c-sub { grid-column: 1 / -1; grid-row: 2; overflow: hidden; text-overflow: ellipsis; }
  table.list.cards td.c-meta { grid-column: 1; grid-row: 3; color: var(--muted); font-size: .85rem; }
  table.list.cards td.c-amount { grid-column: 2; grid-row: 3; justify-self: end; font-weight: 650; }
  table.list.cards tr.is-draft { background: var(--warning-soft); }
  table.list.cards td.empty, table.list.cards tr.pager td { grid-column: 1 / -1; text-align: center; }
  table.list.cards .c-only { display: inline; }
  .table-wrap:has(> table.cards) { overflow-x: visible; }
  .sort-select { display: block; }
  .toolbar input[type=search] { max-width: none; flex: 1 1 100%; }
  .toolbar select { flex: 1 1 auto; }
}

/* ---------- Formulare ---------- */
label { display: block; font-size: .85rem; font-weight: 550; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--input-border); border-radius: 8px; background: var(--input-bg); color: var(--text); font: inherit; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); background: var(--surface); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }
input[type=color] { width: 60px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.field { margin-bottom: .9rem; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .92rem; color: var(--text); font-weight: 450; }
.check input { width: 18px; height: 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
[data-tab-panel][hidden] { display: none !important; }
.field-marks { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: -.25rem 0 .5rem; }
.field-marks .btn { padding: .15rem .5rem; min-height: 0; font-size: .8rem; }
h3.sub-head { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* ---------- Beleg-Editor ---------- */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: .75rem; text-transform: uppercase; color: var(--muted); text-align: left; padding: .4rem .3rem; font-weight: 600; }
.lines td { padding: .35rem .3rem; vertical-align: top; border-top: 1px solid var(--border); }
.lines input, .lines select, .lines textarea { min-height: 36px; padding: .4rem .5rem; }
.lines textarea { min-height: 36px; height: 36px; margin-top: .3rem; font-size: .85rem; }
.lines .c-pos { width: 7.5rem; color: var(--muted); padding-top: .6rem; text-align: center; }
.lines .pos-label { display: block; font-variant-numeric: tabular-nums; font-size: .85rem; min-height: 1.2em; }
.lines .pos-tools { display: inline-flex; align-items: center; gap: 0; margin-top: .15rem; }
.lines .pos-tools .btn { padding: .1rem; min-height: 0; }
.drag-handle { cursor: grab; padding: 0 .25rem; font-size: 1.1rem; line-height: 1; color: var(--muted); user-select: none; }
.drag-handle:active { cursor: grabbing; }
tr.line.dragging td { opacity: .45; }
/* sortierbare Tabellen (Schlüsseltabellen, Anreden) */
table[data-sortable] .c-sort { width: 1%; white-space: nowrap; padding-right: 0; }
table[data-sortable] .sort-tools { display: inline-flex; align-items: center; }
table[data-sortable] .sort-tools .btn { padding: .1rem; min-height: 0; }
table[data-sortable] tr.dragging td { opacity: .45; background: var(--surface-2); }
.lines .c-qty { width: 6.5rem; }
.lines .c-unit { width: 7rem; }
.lines .c-price { width: 8rem; }
.lines .c-disc { width: 5rem; }
.lines .c-tax { width: 8.5rem; }
.lines .c-total { width: 7.5rem; text-align: right; padding-top: .6rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .c-act { width: 5.5rem; white-space: nowrap; }
.lines input.num { text-align: right; }
.totals { margin-left: auto; max-width: 360px; }
.totals .row { display: flex; justify-content: space-between; padding: .25rem 0; font-variant-numeric: tabular-nums; }
.totals .row.sum { border-top: 1px solid var(--border); margin-top: .25rem; padding-top: .5rem; font-weight: 700; font-size: 1.1rem; }

@media (max-width: 900px) {
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100% !important; }
  .lines tr { border: 1px solid var(--border); border-radius: 8px; padding: .5rem; margin-bottom: .75rem; display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
  .lines td { border: none; padding: 0; }
  .lines td.c-name { grid-column: 1 / -1; }
  .lines td.c-pos { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; text-align: left; padding: 0; }
  .lines .pos-tools { margin: 0; }
  .lines td.c-pos .kind-select { width: auto; margin: 0; }
  .lines td.c-total, .lines td.c-act { text-align: left; padding-top: .3rem; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; }
}

.pdf-frame { width: 100%; height: 80vh; min-height: 500px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
dl.meta { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .92rem; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu .menu-panel { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: .4rem; min-width: 240px; z-index: 30; }
details.menu .menu-panel button, details.menu .menu-panel a { display: block; width: 100%; text-align: left; background: none; border: none; padding: .5rem .7rem; border-radius: 6px; font: inherit; color: var(--text); cursor: pointer; }
details.menu .menu-panel button:hover, details.menu .menu-panel a:hover { background: var(--surface-2); text-decoration: none; }
.stack > * + * { margin-top: .5rem; }

/* ---------- Anmeldung ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #16212f, #1f5fa8); }
.auth .card { width: 100%; max-width: 420px; padding: 2rem; }
.auth .brand { color: var(--text); padding: 0 0 1.25rem; }

/* ---------- ERP: Projekte, Plantafel, Zeiten ---------- */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; flex: none; }
.badge.p-inquiry { background: var(--surface-2); color: var(--muted); }
.badge.p-planned { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.p-active { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.p-done, .badge.p-closed { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.p-cancelled { text-decoration: line-through; }
.badge.sub-active { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.sub-paused { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.kpi:hover { text-decoration: none; border-color: var(--primary); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: .65rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .75rem; align-items: flex-start; }
.list-plain > li:last-child { border-bottom: none; }
.list-plain .time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 92px; font-size: .88rem; }
.list-plain .grow { flex: 1; min-width: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.section-head h2 { margin: 0; }

.board-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.board { border-collapse: collapse; width: 100%; min-width: 980px; table-layout: fixed; }
table.board th, table.board td { border: 1px solid var(--border); vertical-align: top; }
table.board thead th { background: var(--surface-2); font-size: .8rem; padding: .45rem; font-weight: 600; text-align: left; }
table.board thead th.today { background: var(--primary-soft); color: var(--primary); }
table.board th.emp { width: 150px; background: var(--surface-2); text-align: left; padding: .5rem; font-size: .88rem; font-weight: 600; }
table.board td.cell { height: 84px; padding: 4px; position: relative; }
table.board td.cell.today { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
table.board td.cell.weekend { background: var(--surface-2); }
table.board td.cell.drop-hover { outline: 2px dashed var(--primary); outline-offset: -3px; }
.cell-add { position: absolute; right: 3px; bottom: 3px; opacity: 0; font-size: .8rem; padding: 0 .35rem; border-radius: 4px; color: var(--muted); }
td.cell:hover .cell-add { opacity: 1; }
@media (hover: none) { .cell-add { opacity: .6; } }
.chip { display: block; border-left: 4px solid var(--c, var(--primary)); background: var(--surface-2); border-radius: 6px; padding: 3px 6px; margin-bottom: 4px; font-size: .78rem; line-height: 1.25; color: var(--text); cursor: grab; overflow: hidden; }
.chip:hover { text-decoration: none; background: var(--primary-soft); }
.chip .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.dragging { opacity: .4; }

.timer { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; justify-content: space-between; }
.timer .clock { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.timer.running { border-color: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.btn.big { min-height: 52px; padding: .75rem 1.5rem; font-size: 1.05rem; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { display: flex; width: 100%; }
.geo-map { height: 60vh; min-height: 340px; border-radius: var(--radius); }
.geo-place + .geo-place { margin-top: .15rem; }
.badge.warn { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.timer.paused { border-color: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.pause-box { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-weight: 600; color: var(--warning); margin-right: .5rem; }
.timer .clock.pause-clock { font-size: 1.4rem; }

/* Handy-Seite „Erfassen“: eine Spalte, große Schaltflächen, einhändig bedienbar */
.capture { max-width: 640px; margin: 0 auto; display: grid; gap: 1rem; }
.capture .card { margin: 0; }
.capture .timer { display: grid; gap: .75rem; }
.capture .timer .clock { font-size: 2.8rem; line-height: 1.1; }
.capture-target { margin-top: .35rem; }
.capture-form { display: grid; gap: .6rem; margin-top: .5rem; }
.capture-form label { font-weight: 600; font-size: .9rem; margin-bottom: -.3rem; }
.capture-form input, .capture-form select, .capture-form textarea { font-size: 1rem; min-height: 44px; }
.capture-form .field { margin: 0; }
.capture .chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.capture details > summary { cursor: pointer; font-weight: 650; display: flex; align-items: center; gap: .5rem; min-height: 32px; list-style: none; }
.capture details > summary::-webkit-details-marker { display: none; }
.capture details > summary::after { content: "▸"; margin-left: auto; color: var(--muted); }
.capture details[open] > summary::after { content: "▾"; }
.capture-extras { display: grid; gap: .6rem; }
.capture-extras > p { margin: 0 .25rem; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.gallery figure { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.gallery img { width: 100%; height: 130px; object-fit: cover; display: block; }
.gallery figcaption { padding: .35rem .5rem; font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; gap: .25rem; }
.gallery .file-icon { height: 130px; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.note { white-space: pre-wrap; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }
.pos { color: var(--success); } .neg { color: var(--danger); }
[hidden] { display: none !important; }

/* Kompakte Formularzeile: Beschriftung links, Feld rechts (Beleg-Kopf) */
.frow { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); column-gap: .5rem; align-items: center;
  margin: 0 0 .35rem; font-weight: normal; }
.frow > span:first-child { font-size: .8rem; color: var(--muted); line-height: 1.2; }
.frow.top { align-items: start; }
.frow.top > span:first-child { padding-top: .45rem; }
.frow input, .frow select, .frow textarea { min-height: 32px; padding: .25rem .5rem; font-size: .9rem; }
.frow textarea { min-height: 0; }
.inline2 { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.input-suffix { position: relative; display: block; max-width: 9rem; }
.input-suffix > input { padding-right: 1.8rem; text-align: right; width: 100%; }
.input-suffix > span { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted);
  pointer-events: none; font-size: .9rem; }
.inline3 { display: grid; grid-template-columns: 5rem minmax(0, 1fr) 3rem; gap: .35rem; }

/* Beleg-Editor: Kopf in drei Spalten (Empfänger | Beleg | Konditionen), darunter Texte und Positionen */
.doc-head { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr); gap: 0 1.5rem;
  padding: .9rem 1.1rem; margin-bottom: 1rem; }
.doc-head > section + section { border-left: 1px solid var(--border); padding-left: 1.5rem; }
.doc-head h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .5rem; }
.addr-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem;
  min-height: 5.6rem; font-size: .9rem; line-height: 1.4; }
.head-more { margin-top: .3rem; }
/* Empfänger: Kundenauswahl und Adressblock über die volle Breite, ohne Einrückung */
.doc-head h3 label { font: inherit; color: inherit; margin: 0; cursor: pointer; }
.doc-head .recipient-select { width: 100%; min-height: 34px; padding: .3rem .5rem; font-size: .92rem; margin-bottom: .45rem; }
.doc-head .addr-box { margin-bottom: .35rem; }
.doc-head .free-address { margin: .5rem 0 .2rem; }
.doc-head > section:first-child .head-more > summary { margin-left: 0; }
.head-more > summary { cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--primary); padding: .2rem 0;
  margin-left: 8rem; }
.head-more[open] > summary { margin-bottom: .35rem; }
.doc-texts { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; padding: .9rem 1.1rem; margin-bottom: 1rem; }
.doc-texts .frow { grid-template-columns: 6rem minmax(0, 1fr); }
@media (max-width: 1200px) {
  .doc-head { grid-template-columns: 1fr 1fr; }
  .doc-head > section:nth-child(3) { grid-column: 1 / -1; border-left: 0; padding-left: 0; border-top: 1px solid var(--border);
    padding-top: .75rem; margin-top: .5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; align-content: start; }
  .doc-head > section:nth-child(3) h3 { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .doc-head, .doc-texts, .doc-head > section:nth-child(3) { grid-template-columns: 1fr; }
  .doc-head > section + section { border-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: .75rem; margin-top: .5rem; }
  .head-more > summary { margin-left: 0; }
}

/* Neuer Beleg */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { display: flex; align-items: center; gap: .35rem; margin: 0; padding: .4rem .8rem; cursor: pointer; font-weight: 500; }
.seg label + label { border-left: 1px solid var(--border); }
.seg label:has(input:checked) { background: var(--primary-soft); color: var(--primary); }
.new-doc select[size] { min-height: 0; padding: .25rem; }
.nd-preview .addr-box, .nd-address { margin-bottom: .75rem; }
/* Neuer Beleg: Formular links, Vorschau rechts oben (mitlaufend); erst auf schmalen Bildschirmen untereinander */
.nd-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, 1fr); gap: 1rem; align-items: start; }
.nd-preview { position: sticky; top: calc(var(--topbar-h) + 1rem); }
.nd-address { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem;
  min-height: 5.6rem; font-size: .9rem; line-height: 1.4; }
.nd-section { margin: 1rem 0 .5rem; }
@media (max-width: 760px) { .nd-grid { grid-template-columns: 1fr; } .nd-preview { position: static; } }
.nd-list { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .3rem .75rem; margin: 0; font-size: .9rem; }
.nd-list dt { color: var(--muted); }
.nd-list dd { margin: 0; }

@media print {
  .sidebar, .topbar, .page-head .actions, .no-print { display: none !important; }
  .content { padding: 0; }
}

/* ---------- Handbuch (/help) ---------- */
.help { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.help-toc { position: sticky; top: 4.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.help-toc-title { font-weight: 700; margin-bottom: .4rem; }
.help-toc ol { list-style: none; margin: 0; padding: 0; }
.help-toc li a { display: block; padding: .3rem .5rem; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .92rem; }
.help-toc li a:hover { background: var(--surface-2); }
.help-toc li a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.help-print { display: block; margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--border); font-size: .85rem; }
.help-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem 2rem; max-width: 62rem; line-height: 1.6; }
.help-body h1 { margin-top: 0; }
.help-body h2 { margin-top: 2rem; padding-top: .5rem; border-top: 1px solid var(--border); font-size: 1.25rem; }
.help-body h3 { margin-top: 1.25rem; font-size: 1.05rem; }
.help-body ol, .help-body ul { padding-left: 1.4rem; }
.help-body li { margin: .2rem 0; }
.help-lead { color: var(--muted); font-size: 1.05rem; margin-top: -.5rem; }
.help-sections { background: var(--surface-2); border-radius: 8px; padding: .6rem 1rem; margin: 1rem 0; }
.help-sections ul { margin: .3rem 0 0; columns: 2; }
.help-shot { margin: 1rem 0; }
.help-shot img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.08); display: block; }
.help-shot.narrow img { max-width: 22rem; }
.help-shot figcaption { font-size: .85rem; color: var(--muted); margin-top: .35rem; }
.help-box { display: flex; gap: .75rem; border-radius: 8px; padding: .6rem .9rem; margin: 1rem 0; border: 1px solid transparent; }
.help-box > strong { flex: none; }
.help-box.tip { background: var(--success-soft); color: var(--text); }
.help-box.note { background: var(--primary-soft); color: var(--text); }
.help-box.warn { background: var(--warning-soft); color: var(--text); }
.help-menu { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 .35rem; font-size: .9em; white-space: nowrap; }
.help-body kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem; font-size: .85em; }
.help-body table.help-table { border-collapse: collapse; width: 100%; margin: .75rem 0; font-size: .92rem; }
.help-table th, .help-table td { border: 1px solid var(--border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.help-table th { background: var(--surface-2); }
.help-pager { display: flex; justify-content: space-between; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.help-printbar { display: flex; gap: .5rem; justify-content: space-between; margin-bottom: 1rem; }
.help-cover { font-size: 2rem; margin: 2rem 0 1rem; }
.help-all-toc { margin-bottom: 2rem; }
.help-chapter { break-before: page; }
.help-all .help-body { max-width: none; border: none; padding: 0; }
@media (max-width: 900px) {
  .help { grid-template-columns: 1fr; }
  .help-toc { position: static; }
  .help-body { padding: 1rem; }
  .help-sections ul { columns: 1; }
}
@media print {
  .help { display: block; }
  .help-body { border: none; padding: 0; max-width: none; }
  .help-shot img { box-shadow: none; max-width: 100%; break-inside: avoid; }
  .help-chapter:first-of-type { break-before: auto; }
  .sidebar, .topbar { display: none !important; }
}
