:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e3e1dc;
  --side: #22262b;
  --side-ink: #d7d9dc;
  --accent: #c2410c;
  --accent-soft: #fdeee6;
  --ok: #15803d;
  --ok-soft: #e7f5ec;
  --warn: #b45309;
  --warn-soft: #fdf3e1;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8eefc;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.pre { white-space: pre-wrap; }

/* Seitenleiste */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 16px 12px; overflow-y: auto; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 6px 18px; }
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 14px; }
.brand small { display: block; color: #9aa0a6; font-size: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: grid;
  place-items: center; font-weight: 700; font-size: 18px; flex: none;
}
.brand-large { color: var(--ink); padding-bottom: 8px; }
.brand-large small { color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--side-ink); padding: 8px 10px; border-radius: 6px; }
.sidebar nav a:hover { background: #2f343a; text-decoration: none; }
.sidebar nav a.active { background: #383e45; color: #fff; }
.nav-stages { display: flex; flex-direction: column; margin: 0 0 6px 10px; border-left: 1px solid #3a4047; }
.nav-stages a { display: flex; justify-content: space-between; padding: 5px 10px !important; font-size: 13px; }
.nav-stages a span { color: #8d939a; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding: 12px 8px 0; font-size: 13px; }
.sidebar-footer small { color: #7f858c; }
.sidebar-footer .link { color: #b8bcc1; }

/* Rahmen */
.shell { margin-left: 236px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.search { flex: 1; max-width: 520px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-toggle { display: none; }
.view { padding: 24px; max-width: 1400px; width: 100%; outline: none; }

/* Elemente */
input, select, textarea {
  font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff;
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f3c7ad; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; }
.btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c9c6bf; background: #faf9f7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #a8380a; border-color: #a8380a; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { padding: 4px 8px; font-size: 12px; }
.btn-danger { color: var(--bad); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 16px; }
.panel + .panel { margin-top: 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fbfaf8; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #faf8f5; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eeece8; color: #44484e;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; cursor: pointer; font: inherit; font-size: 13px; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip span { color: var(--muted); margin-left: 4px; }
.chip.active span { color: #c9ccd0; }

/* Übersicht */
.pipeline { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; }
.pipeline a { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; color: var(--ink); }
.pipeline a:hover { border-color: var(--accent); text-decoration: none; }
.pipeline strong { display: block; font-size: 22px; }
.pipeline small { color: var(--muted); font-size: 12px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi strong { display: block; font-size: 24px; }
.kpi.alert strong { color: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.date-box { width: 46px; flex: none; text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 3px 0; }
.date-box b { display: block; font-size: 16px; }
.date-box small { font-size: 11px; color: var(--muted); }
.progress { height: 6px; background: #eeece8; border-radius: 99px; overflow: hidden; margin: 6px 0; }
.progress > span { display: block; height: 100%; background: var(--ok); }

/* Projekt */
.stepper { display: flex; gap: 2px; margin: 14px 0 18px; overflow-x: auto; }
.stepper span {
  flex: 1; min-width: 92px; text-align: center; padding: 7px 4px; font-size: 12px; background: #e9e7e2; color: var(--muted);
}
.stepper span:first-child { border-radius: 6px 0 0 6px; }
.stepper span:last-child { border-radius: 0 6px 6px 0; }
.stepper span.done { background: #d9e9de; color: var(--ok); }
.stepper span.current { background: var(--accent); color: #fff; font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a span { font-size: 11px; background: #eeece8; border-radius: 99px; padding: 1px 6px; margin-left: 4px; }
dl.facts { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
dl.facts dt { color: var(--muted); font-size: 13px; }
dl.facts dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #eeece8; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: #555;
}
.avatar.status { background: var(--accent-soft); color: var(--accent); }
.avatar.system { background: #f1f1f1; color: #999; }
.meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.composer { display: grid; gap: 8px; padding: 16px; border-bottom: 1px solid var(--line); }
.composer-row { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.composer-row select { width: auto; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.over { color: var(--bad); font-weight: 600; }
tfoot td { font-weight: 600; background: #fbfaf8; }
.gantt { position: relative; }
.gantt-row { display: grid; grid-template-columns: 180px 1fr; align-items: center; border-bottom: 1px solid var(--line); min-height: 34px; }
.gantt-row > div:first-child { padding: 6px 12px; font-size: 13px; }
.gantt-track { position: relative; height: 34px; }
.gantt-bar { position: absolute; top: 9px; height: 16px; border-radius: 4px; background: #cfd6dd; }
.gantt-bar.fertig { background: #9fcfae; }
.gantt-bar.laeuft { background: var(--accent); }
.gantt-bar.beauftragt { background: #f0b48f; }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); opacity: .6; }
.gantt-scale { display: grid; grid-template-columns: 180px 1fr; font-size: 11px; color: var(--muted); }
.gantt-scale .ticks { position: relative; height: 22px; }
.gantt-scale .ticks span { position: absolute; top: 4px; transform: translateX(-50%); white-space: nowrap; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.file-card { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.file-card .thumb { height: 120px; background: #f2f1ee; display: grid; place-items: center; color: var(--muted); font-size: 12px; overflow: hidden; }
.file-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card .info { padding: 8px 10px; font-size: 12px; display: grid; gap: 2px; }
.file-card .info a { word-break: break-all; }

/* Beleg-Editor */
.doc-items td { vertical-align: top; }
.doc-items input, .doc-items textarea { padding: 5px 7px; }
.doc-items textarea { min-height: 38px; margin-top: 4px; font-size: 13px; }
.doc-items tr.item-title td { background: #f7f5f1; }
.doc-items tr.item-title input { font-weight: 600; }
.doc-items tr.item-text input { font-style: italic; }
.doc-items input:disabled, .doc-items textarea:disabled, #doc-head :disabled { background: #fbfaf8; color: var(--ink); border-color: transparent; }
table.totals { width: auto; min-width: 320px; margin-left: auto; }
table.totals td { border: 0; padding: 4px 0 4px 24px; }
table.totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 15px; padding-top: 8px; }
code { background: #f1efeb; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Dialog und Meldungen */
.modal { border: 0; border-radius: 10px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(20, 22, 25, .45); }
.modal form { display: flex; flex-direction: column; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .fields { padding: 16px 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-height: 70vh; overflow-y: auto; }
.modal .fields .wide { grid-column: 1 / -1; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--bad); margin: 0; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--bad); }

/* Anmeldung */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(380px, 100%); display: grid; gap: 14px; }

@media (max-width: 1100px) {
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .shell { margin-left: 0; }
  .menu-toggle { display: inline-block; }
  .topbar { padding: 10px 12px; }
  .topbar-actions #new-contact { display: none; }
  .view { padding: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .modal .fields { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
  .gantt-row, .gantt-scale { grid-template-columns: 110px 1fr; }
}
