:root {
  --rot: #e32f1a;
  --rot-hell: #fdecea;
  --kopf: #1d1f23;
  --hg: #f4f5f7;
  --karte: #ffffff;
  --text: #1f2328;
  --leise: #6b7280;
  --linie: #e3e5e9;
  --gruen: #1f8a4c;
  --gelb: #b7791f;
  --blau: #2563eb;
  --lila: #7c3aed;
  --radius: 10px;
  --flaeche: #eceef1;
  --hover: #fafbfc;
  --eingabe: #ffffff;
  --rand: #cfd3d9;
  /* Diagramme: Referenzpalette, Plaetze 1-3 (Einnahmen, Fixkosten, variable Kosten) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  color-scheme: light;
}
/* Dunkelmodus: eigene Stufen, nicht einfach invertiert. Folgt dem System, der Schalter oben rechts gewinnt in beide Richtungen */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --hg: #111315; --karte: #1a1c20; --text: #e7e8ea; --leise: #9aa1aa; --linie: #2b2e34; --flaeche: #23262b; --hover: #202328;
    --eingabe: #15171a; --rand: #3b3f46; --rot-hell: #3b1f1b; --kopf: #0b0c0e;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --hg: #111315; --karte: #1a1c20; --text: #e7e8ea; --leise: #9aa1aa; --linie: #2b2e34; --flaeche: #23262b; --hover: #202328;
  --eingabe: #15171a; --rand: #3b3f46; --rot-hell: #3b1f1b; --kopf: #0b0c0e;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--hg); color: var(--text); }
a { color: inherit; }
button, input, select, textarea { font: inherit; }

.kopf { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 56px; background: var(--kopf); color: #fff; }
.marke { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.marke img { height: 22px; }
.marke span { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: #c9ccd1; border-left: 1px solid #444; padding-left: 12px; }
#nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a { padding: 8px 11px; border-radius: 6px; text-decoration: none; color: #c9ccd1; white-space: nowrap; }
#nav a:hover { color: #fff; background: #2b2e34; }
#nav a.aktiv { color: #fff; background: var(--rot); }
.kopf .leise { color: #c9ccd1; background: none; border: 1px solid #444; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }
footer { max-width: 1400px; margin: 0 auto; padding: 8px 20px 30px; color: var(--leise); font-size: 12px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.laden, .leer { color: var(--leise); }

.karte { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: 16px; }
.raster { display: grid; gap: 16px; }
.r2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.r3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) { .r2, .r3 { grid-template-columns: 1fr; } }

.kennzahlen { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kz { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: block; min-width: 0; overflow: hidden; }
/* Betraege wie 157.763,68 € muessen in die Kachel passen */
.kz b { display: block; font-size: clamp(18px, 1.7vw, 26px); line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kz span { color: var(--leise); font-size: 13px; }
.kz.warn b { color: var(--rot); }

.pipeline { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1100px) { .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.spalte { background: var(--flaeche); border-radius: var(--radius); padding: 10px; min-height: 80px; }
.spalte h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--leise); margin: 2px 4px 8px; display: flex; justify-content: space-between; }
.pk { display: block; background: var(--karte); border: 1px solid var(--linie); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; text-decoration: none; }
.pk:hover { border-color: var(--rand); }
.pk .n { font-weight: 600; }
.pk .m { color: var(--leise); font-size: 12px; margin-top: 2px; }
.pk .z { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--flaeche); color: var(--text); white-space: nowrap; }
.chip.rot { background: var(--rot-hell); color: var(--rot); }
.chip.gruen { background: #e5f4ec; color: var(--gruen); }
.chip.gelb { background: #fdf3e1; color: var(--gelb); }
.chip.blau { background: #e8effd; color: var(--blau); }

.st { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.st-anfrage { background: #eef2ff; color: #4338ca; }
.st-angebot { background: #fdf3e1; color: var(--gelb); }
.st-beauftragt { background: #e5f4ec; color: var(--gruen); }
.st-in_arbeit { background: #e8effd; color: var(--blau); }
.st-abnahme { background: #f3e8ff; color: var(--lila); }
.st-abgeschlossen { background: #eceef1; color: #4b5563; }
.st-verloren, .st-ruht { background: #eceef1; color: #9ca3af; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--leise); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--linie); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--linie); vertical-align: top; }
tr.klick { cursor: pointer; }
tr.klick:hover td { background: var(--hover); }
td.zahl, th.zahl { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tab-wrap { overflow-x: auto; }

.liste { list-style: none; margin: 0; padding: 0; }
.liste li { padding: 9px 0; border-bottom: 1px solid var(--linie); display: flex; gap: 10px; align-items: flex-start; }
.liste li:last-child { border-bottom: 0; }
.liste .d { min-width: 74px; font-size: 13px; color: var(--leise); font-variant-numeric: tabular-nums; }
.liste .d.ueber { color: var(--rot); font-weight: 600; }
.liste .t { flex: 1; }
.liste .t small { display: block; color: var(--leise); }

.werkzeug { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.werkzeug .platz { flex: 1; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  border: 1px solid var(--rand); border-radius: 7px; padding: 7px 10px; background: var(--eingabe); color: var(--text); }
textarea { width: 100%; min-height: 80px; }
button { border: 1px solid var(--rand); background: var(--eingabe); color: var(--text); border-radius: 7px; padding: 7px 12px; cursor: pointer; }
button:hover { border-color: #9ca3af; }
button.haupt { background: var(--rot); border-color: var(--rot); color: #fff; }
button.klein { padding: 3px 8px; font-size: 13px; }
button.leise { background: none; }
.seg { display: inline-flex; border: 1px solid var(--rand); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--rand); }
.seg button:last-child { border-right: 0; }
.seg button.an { background: var(--kopf); color: #fff; }

.formular { display: grid; grid-template-columns: 140px 1fr; gap: 10px 12px; align-items: center; }
.formular label { color: var(--leise); font-size: 13px; }
.formular .voll { grid-column: 1 / -1; }
.knoepfe { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.fehler { color: var(--rot); margin: 8px 0 0; }

#dialog-hg { position: fixed; inset: 0; background: rgba(15, 17, 20, .45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 20; overflow-y: auto; }
[hidden] { display: none !important; }
#dialog { background: var(--karte); border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }

.anmelden { max-width: 380px; margin: 60px auto; }
.anmelden input { width: 100%; margin-bottom: 10px; }

/* Projekt */
.pkopf { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.pkopf h1 { margin: 0; }
.meta { color: var(--leise); margin-bottom: 16px; }
.verlauf { list-style: none; margin: 0; padding: 0; }
.verlauf li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--linie); margin-left: 6px; }
.verlauf li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; }
.verlauf li.aus::before { background: var(--blau); }
.verlauf li.auftrag::before, .verlauf li.nachtrag::before { background: var(--gruen); }
.verlauf li.mangel::before, .verlauf li.rueckfrage::before { background: var(--rot); }
.verlauf .k { font-size: 12px; color: var(--leise); }
.verlauf .b { font-weight: 600; }

/* Kalender */
.kal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--linie); border-top: 1px solid var(--linie); background: var(--karte); border-radius: var(--radius); overflow: hidden; }
.kal .wt { font-size: 12px; color: var(--leise); padding: 6px 8px; border-right: 1px solid var(--linie); border-bottom: 1px solid var(--linie); background: var(--hover); }
.kal .tag { min-height: 110px; padding: 4px; border-right: 1px solid var(--linie); border-bottom: 1px solid var(--linie); cursor: pointer; }
.kal .tag.fremd { background: var(--hover); color: var(--leise); }
.kal .tag.we { background: var(--hover); }
.kal .tag.heute .nr { background: var(--rot); color: #fff; border-radius: 50%; }
.kal .nr { display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; font-size: 12px; margin-bottom: 2px; }
.ev { display: block; font-size: 12px; line-height: 1.3; padding: 2px 5px; margin-bottom: 2px; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; cursor: pointer; }
.ev.unsicher { opacity: .7; background-image: repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,255,255,.2) 6px 12px); }
.ev.erledigt { opacity: .4; text-decoration: line-through; }
.a-Fertigung { background: var(--rot); }
.a-Lieferung { background: #d97706; }
.a-Montage { background: var(--blau); }
.a-Inbetriebnahme { background: #0891b2; }
.a-Begehung { background: #4b5563; }
.a-Abnahme { background: var(--lila); }
.a-Frist { background: #111827; }
.a-Intern { background: #0f766e; }
.a-Sonstiges { background: #9ca3af; }
.legende { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--leise); margin-top: 10px; }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

@media (max-width: 700px) {
  .kopf { gap: 6px 10px; padding: 8px 12px 0; height: auto; flex-wrap: wrap; }
  .marke { flex: 1; }
  #nav { order: 3; flex-basis: 100%; padding-bottom: 8px; }
  #nav a { padding: 6px 9px; font-size: 14px; }
  .kopf .leise { padding: 4px 10px; font-size: 13px; }
  .kennzahlen { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kz { padding: 10px 12px; }
  .kz b { font-size: 18px; }
  .kz span { font-size: 12px; }
  .werkzeug input[type=date] { width: 100%; }
  .marke span { display: none; }
  main { padding: 12px; }
  .kal .tag { min-height: 70px; }
  .ev { font-size: 10px; padding: 1px 3px; }
  .formular { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .pipeline { grid-template-columns: 1fr; } }

/* Zeitplan: Projekte als Zeilen, Tage als Spalten ueber die volle Breite */
.zp { padding: 0; overflow-x: auto; }
.zp-zeile { display: grid; grid-template-columns: 240px minmax(700px, 1fr); border-bottom: 1px solid var(--linie); min-height: 38px; }
.zp-zeile:last-child { border-bottom: 0; }
.zp-name { padding: 6px 10px; border-right: 1px solid var(--linie); text-decoration: none; display: flex; flex-direction: column; gap: 3px; justify-content: center; background: var(--karte); position: sticky; left: 0; z-index: 2; }
.zp-name b { font-size: 13px; line-height: 1.2; }
.zp-name .st { align-self: flex-start; font-size: 11px; padding: 1px 6px; }
.zp-raster { display: grid; grid-template-columns: repeat(var(--tage), minmax(0, 1fr)); grid-auto-rows: 22px; grid-auto-flow: row dense; align-content: center; gap: 3px 0; padding: 6px 0; position: relative; cursor: copy;
  background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(100% / var(--tage) * 7 - 1px), var(--linie) calc(100% / var(--tage) * 7 - 1px), var(--linie) calc(100% / var(--tage) * 7)); }
.zp-kopf { background: var(--hover); }
.zp-kopf .zp-name { background: var(--hover); }
.zp-kopf .zp-raster { cursor: default; padding: 0; grid-auto-rows: auto; }
.zp-woche { font-size: 12px; font-weight: 600; padding: 6px 6px; color: #374151; border-left: 1px solid var(--linie); }
.zp-woche small { display: block; font-weight: 400; color: var(--leise); }
.zp-ev { margin: 0 1px; display: flex; align-items: center; }
.zp-heute { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--rot); opacity: .55; pointer-events: none; }
@media (max-width: 700px) { .zp-zeile { grid-template-columns: 140px minmax(700px, 1fr); } }
main.breit { max-width: none; }
.zp-tag { font-size: 11px; color: var(--leise); padding: 2px 3px; border-left: 1px solid var(--linie); text-align: center; white-space: nowrap; overflow: hidden; }
.zp-tag.we { background: var(--flaeche); }
.zp.tage .zp-raster { background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(100% / var(--tage) - 1px), var(--hover) calc(100% / var(--tage) - 1px), var(--hover) calc(100% / var(--tage))); }
.ev.fest { box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); font-weight: 600; }
.score { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.score b { font-size: 46px; line-height: 1; }
.check-gruen { border-left: 6px solid var(--gruen); } .check-gruen .score b { color: var(--gruen); }
.check-gelb { border-left: 6px solid var(--gelb); } .check-gelb .score b { color: var(--gelb); }
.check-rot { border-left: 6px solid var(--rot); } .check-rot .score b { color: var(--rot); }
table.kosten td, table.kosten th { padding: 5px 7px; font-size: 13px; white-space: nowrap; }
table.kosten tr.gruppe td { background: var(--flaeche); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--leise); }
table.kosten tr.summe td { font-weight: 700; border-top: 2px solid var(--rand); }

/* Dunkelmodus: farbige Plaketten mit durchscheinendem Grund */
:root[data-theme="dark"] .st, :root[data-theme="dark"] .chip.gruen, :root[data-theme="dark"] .chip.gelb, :root[data-theme="dark"] .chip.blau, :root[data-theme="dark"] .chip.rot { background: rgba(255,255,255,.08); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .st, :root:not([data-theme="light"]) .chip.gruen, :root:not([data-theme="light"]) .chip.gelb,
  :root:not([data-theme="light"]) .chip.blau, :root:not([data-theme="light"]) .chip.rot { background: rgba(255,255,255,.08); }
}
#thema { background: none; border: 1px solid #444; color: #c9ccd1; padding: 5px 9px; }

/* Diagramme */
.diagramm { width: 100%; height: auto; display: block; }
.diagramm text { fill: var(--leise); font-size: 11px; font-family: inherit; }
.diagramm .gitter { stroke: var(--linie); stroke-width: 1; }
.diagramm .achse { stroke: var(--rand); stroke-width: 1; }
.diagramm .wert { fill: var(--text); font-size: 11px; }
.diagramm rect.balken:hover, .diagramm .gruppe:hover rect { opacity: .85; }
.legende-d { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--leise); margin: 0 0 6px; }
.legende-d i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
#tip { position: fixed; pointer-events: none; z-index: 40; background: var(--karte); color: var(--text); border: 1px solid var(--rand); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18); white-space: nowrap; }
#tip b { display: block; margin-bottom: 2px; }

/* Assistent */
#ki-knopf { position: fixed; right: 18px; bottom: 18px; z-index: 30; background: var(--rot); color: #fff; border: 0; border-radius: 999px; padding: 12px 18px;
  font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
#ki { position: fixed; right: 18px; bottom: 74px; z-index: 31; width: min(440px, calc(100vw - 24px)); height: min(620px, calc(100vh - 110px)); display: flex;
  flex-direction: column; background: var(--karte); border: 1px solid var(--rand); border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.28); overflow: hidden; }
#ki header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--kopf); color: #fff; }
#ki header b { flex: 1; }
#ki header button { background: none; border: 0; color: #c9ccd1; padding: 2px 6px; }
#ki-verlauf { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ki-n { padding: 9px 12px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; line-height: 1.45; font-size: 14px; }
.ki-n.user { align-self: flex-end; background: var(--rot); color: #fff; }
.ki-n.assistant { align-self: flex-start; background: var(--flaeche); }
.ki-n .aend { margin-top: 6px; font-size: 12px; color: var(--leise); }
.ki-n .kopie { margin-top: 6px; font-size: 12px; padding: 2px 8px; }
#ki form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--linie); }
#ki textarea { flex: 1; min-height: 44px; max-height: 140px; resize: vertical; }
.ki-tipps { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.ki-tipps button { font-size: 12px; padding: 3px 8px; border-radius: 999px; }
@media (max-width: 700px) { #ki { right: 8px; left: 8px; width: auto; bottom: 70px; } #ki-knopf { right: 12px; bottom: 12px; } }

.klein-knopf { font-size: 13px; font-weight: 500; border: 1px solid var(--rand); border-radius: 7px; padding: 3px 9px; cursor: pointer; background: var(--eingabe); }

/* Web-App auf iPhone und iPad: Ränder für Notch und Home-Balken, große Tippflächen, kein Zoomen beim Tippen */
.kopf { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
footer { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
#ki-knopf { bottom: calc(18px + env(safe-area-inset-bottom)); }
#nav { -webkit-overflow-scrolling: touch; }
.tab-wrap { -webkit-overflow-scrolling: touch; }
@media (pointer: coarse) {
  button, .seg button, #nav a, .klein-knopf { min-height: 40px; }
  button.klein { min-height: 34px; padding: 4px 10px; }
  input[type=checkbox] { width: 22px; height: 22px; }
  input, select, textarea { font-size: 16px; }
}
@media (max-width: 1024px) and (min-width: 701px) {
  /* iPad hochkant: Projektseite einspaltig, Kacheln dreispaltig */
  .r3 { grid-template-columns: 1fr; }
  .kennzahlen { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .kopf { height: auto; padding-top: calc(8px + env(safe-area-inset-top)); }
  #dialog-hg { padding: 0; align-items: stretch; }
  #dialog { max-width: none; min-height: 100%; border-radius: 0; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
  #ki { bottom: calc(70px + env(safe-area-inset-bottom)); top: calc(70px + env(safe-area-inset-top)); height: auto; }
  h1 { font-size: 20px; }
}
