: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; }
.brand-mark { 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; }
.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; }
.menu-btn { display: none; }
.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; }
  .menu-btn { display: inline-flex; }
  .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; }
.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 */
.kind-select { width: auto; font-size: .8rem; padding: .15rem .3rem; margin-bottom: .25rem; }
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; }
.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; } }

/* ---------- 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); }

/* ---------- 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: 4.6rem; 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; }
.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: 5.5rem; }
.lines .c-total { width: 7.5rem; text-align: right; padding-top: .9rem; 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-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; }

.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); }

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