/* Projektleitung – Gestaltung nach dem Muster des KiNi-CRM.
   Gleiche Farbmarken, gleiche Bausteine (Karte, Badge, Alert, Toolbar),
   damit sich beide Werkzeuge wie ein Haus anfuehlen.

   Zwei Ansichten, aufeinander abgestimmt:
   * Desktop  – feste dunkle Seitenleiste links, Inhalt rechts daneben
   * ab 900px – dieselbe Leiste wird zur angepinnten Kopfzeile mit Burger,
                das Menue klappt als Overlay darunter auf
   Es ist bewusst dieselbe Navigation in beiden Faellen, nur anders gefaltet.  */

:root {
  --brand: #e8641e;
  --brand-dark: #c24f12;
  --ink: #1f2733;
  --ink-soft: #5b6675;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #dfe4ea;
  --ok: #2e9e5b;
  --warn: #d99a06;
  --err: #cc3b3b;
  --info: #2d6fc2;
  --dunkel: #212a36;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, 0.08), 0 4px 14px rgba(20, 30, 45, 0.06);
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { overflow-wrap: break-word; hyphens: auto; }
h1 { font-size: 1.5rem; margin-bottom: 4px; }
h2 { font-size: 1.15rem; margin: 18px 0 10px; }
h3 { font-size: 1rem; margin: 12px 0 8px; }
td, th { overflow-wrap: anywhere; hyphens: auto; }
p { margin-bottom: 10px; }

/* ------------------------------------------------------------- Grundgeruest */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--dunkel); color: #d6dce4;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .logo {
  padding: 18px 20px; font-size: 1.3rem; font-weight: 700; color: #fff;
  text-decoration: none;
}
.sidebar .logo span { color: var(--brand); }
.sidebar .logo small {
  display: block; font-size: 0.7rem; font-weight: 400; color: #8b95a3;
  letter-spacing: 0.04em; text-transform: uppercase; margin-top: 2px;
}
.sidebar-menu { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a {
  display: block; padding: 11px 20px; color: #c4ccd6;
  border-left: 3px solid transparent; text-decoration: none;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar nav a.active {
  background: rgba(232,100,30,0.15); color: #fff; border-left-color: var(--brand);
}
.sidebar nav .nav-sep {
  margin: 12px 20px 4px; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: #7d8794;
}
.sidebar .userbox {
  padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.85rem;
}
.sidebar .userbox .name { color: #fff; font-weight: 600; }
.sidebar .userbox .role { color: var(--brand); }
.sidebar .userbox a.btn { margin-top: 8px; width: 100%; text-align: center; }

/* Zahl offener Posteingangsstuecke direkt am Menuepunkt – sonst muesste man
   hineinschauen, um zu merken, dass etwas liegt. */
.nav-zahl {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 6px;
  border-radius: 9px; background: var(--brand); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
  vertical-align: middle;
}

/* Burger – nur in der Handyansicht sichtbar */
.burger {
  display: none; background: transparent; border: none; border-radius: 6px;
  padding: 10px; margin-right: 12px; cursor: pointer; flex-shrink: 0;
}
.burger:hover { background: rgba(255,255,255,0.1); }
.burger span {
  display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px;
  margin: 5px 0; transition: transform 0.2s, opacity 0.2s;
}
.sidebar.open .burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar.open .burger span:nth-child(2) { opacity: 0; }
.sidebar.open .burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.main { flex: 1; padding: 26px 32px; max-width: 1200px; min-width: 0; }

/* ------------------------------------------------------------------ Karten */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
  overflow-x: auto;
}
.karten-titel { margin-top: 0; }
.seitenkopf { margin-bottom: 18px; }
.seitenkopf .unterzeile { color: var(--ink-soft); font-size: 0.92rem; }

/* --------------------------------------------------------------- Tabellen */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
tbody tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #f7f2ee; cursor: pointer; }

/* -------------------------------------------------------------- Formulare */
label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]),
select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; background: #fff; color: var(--ink);
}
input[readonly], input:disabled { background: #f4f6f9; color: var(--ink-soft); }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(232,100,30,0.35); border-color: var(--brand);
}
/* Safari gibt Datumsfeldern sonst eine feste Eigenbreite und sprengt die Karte */
input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .hinweis { font-size: 0.82rem; color: var(--ink-soft); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid2 > * { min-width: 0; }

/* ---------------------------------------------------------------- Knoepfe */
button, .btn {
  display: inline-block; padding: 9px 16px; border-radius: 6px;
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button.secondary:hover, .btn.secondary:hover { background: #f0f2f5; color: var(--ink); }
button.danger, .btn.danger { background: var(--err); color: #fff; }
button.danger:hover { background: #b33; }
button.small, .btn.small { padding: 5px 10px; font-size: 0.82rem; }
button.breit { width: 100%; margin-top: 6px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ----------------------------------------------------------------- Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 0.76rem; font-weight: 700; white-space: nowrap;
}
.badge.grau   { background: #e7ebef; color: var(--ink-soft); }
.badge.blau   { background: #dce9f9; color: var(--info); }
.badge.gruen  { background: #dcf2e5; color: var(--ok); }
.badge.gelb   { background: #faf0d2; color: #8a6d00; }
.badge.rot    { background: #f9dede; color: var(--err); }
.badge.orange { background: #fbe4d4; color: var(--brand-dark); }

/* ---------------------------------------------------------------- Hinweise */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.92rem; }
.alert.info { background: #e3edf9; color: #1d4e8f; }
.alert.ok   { background: #ddf2e6; color: #1d6b3e; }
.alert.warn { background: #faf0d2; color: #7a6000; }
.alert.err  { background: #f9dede; color: #922; }
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

/* ------------------------------------------------------------------ Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--dunkel); padding: 20px;
}
.login-card {
  background: #fff; border-radius: 14px; padding: 36px; width: 380px; max-width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-card .logo { font-size: 1.7rem; font-weight: 800; margin-bottom: 4px; }
.login-card .logo span { color: var(--brand); }
.login-card .sub { color: var(--ink-soft); margin-bottom: 22px; }
.login-card button { width: 100%; margin-top: 6px; }
.login-card .fuss { margin: 16px 0 0; font-size: 0.87rem; text-align: center; }

/* ------------------------------------------------------------ Kennzahlen */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat .num { font-size: 1.8rem; font-weight: 800; color: var(--brand-dark); }
.stat .num.rot { color: var(--err); }
.stat .lbl { font-size: 0.82rem; color: var(--ink-soft); }

/* --------------------------------------------------------- Detailangaben */
.kv { display: grid; grid-template-columns: 220px 1fr; gap: 6px 14px; font-size: 0.93rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { font-weight: 500; }
.muted { color: var(--ink-soft); font-size: 0.87rem; }
.leer { padding: 32px 20px; text-align: center; color: var(--ink-soft); }

/* ------------------------------------------------------------------ Gantt */
/* Die Balken sind blau bzw. rot, NICHT in der Markenfarbe: Orange und Rot
   liegen zu nah beieinander, der kritische Pfad muss sich klar abheben. */
.gantt-legende {
  display: flex; gap: 6px 22px; flex-wrap: wrap;
  font-size: 0.9rem; margin: 0 0 12px; color: var(--ink-soft);
}
.gantt-legende .probe {
  display: inline-block; width: 22px; height: 10px; border-radius: 3px;
  margin-right: 6px; vertical-align: baseline;
}
.gantt-legende .probe.kritisch { background: var(--err); }
.gantt-legende .probe.normal   { background: var(--info); }

.spur { position: relative; height: 20px; background: #e7ebef; border-radius: 10px; }
.stab {
  position: relative; height: 100%; min-width: 8px;
  background: var(--info); border-radius: 10px; overflow: hidden;
}
.stab.kritisch { background: var(--err); }
.stab .erledigt { height: 100%; background: rgba(255,255,255,0.45); }
.stab.meilenstein {
  background: transparent; min-width: 0; width: 0 !important; overflow: visible;
}
.stab.meilenstein::before {
  content: ""; position: absolute; top: 2px; left: -8px;
  width: 16px; height: 16px; background: var(--ink); transform: rotate(45deg);
}
tr.ist-kritisch td.was a { color: var(--err); font-weight: 700; }

/* ------------------------------------- Listen-Tabellen werden zu Karten */
@media (max-width: 760px) {
  table.liste { display: block; }
  table.liste thead { display: none; }
  table.liste tbody, table.liste tr, table.liste td { display: block; width: 100%; }
  table.liste tbody tr {
    border: 1px solid var(--line); border-radius: 8px;
    padding: 8px 12px; margin-bottom: 10px;
  }
  table.liste td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 6px 14px; border: none; padding: 4px 0; text-align: left !important;
    flex-wrap: wrap;
  }
  table.liste td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 45%;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--ink-soft); padding-top: 2px;
  }
  table.liste td[data-label=""]::before { content: none; }
  table.liste td > * { text-align: right; }
  /* Der Balken ist am Handy unlesbar schmal – Termin und Puffer stehen
     ohnehin als Text daneben, also faellt er weg. */
  table.liste td.balken, table.liste th.balken { display: none; }
  /* nur die Legende der LISTE ausblenden - die des Diagramms wird gebraucht */
  .card > .gantt-legende:has(+ table.liste) { display: none; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 8px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
  .kv dd { margin-bottom: 2px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > * { width: 100%; }
  .toolbar .spacer { display: none; }
}

/* ------------------------------------------- Handyansicht der Navigation */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 40; }
  .sidebar-head { border-bottom: none; }
  .sidebar .logo { padding: 12px 16px; font-size: 1.15rem; }
  .sidebar .logo small { display: none; }
  .burger { display: block; }
  .sidebar-menu {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--dunkel); border-top: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 14px 28px rgba(15,20,28,0.45);
    max-height: calc(100vh - 60px); overflow-y: auto;
  }
  .sidebar.open .sidebar-menu { display: flex; }

  .grid2 { grid-template-columns: 1fr; }
  .main { padding: 16px 12px; }

  /* 16px verhindert, dass iOS beim Antippen ins Feld zoomt */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]),
  select, textarea { font-size: 16px; padding: 11px 12px; }
  .field { margin-bottom: 18px; }
  label { font-size: 0.85rem; margin-bottom: 6px; }
  button, .btn { padding: 11px 16px; }
  button.small, .btn.small { padding: 7px 12px; }
  .card { padding: 16px 14px; margin-bottom: 14px; }
  .card h2 { font-size: 1.08rem; }
}

/* -------------------------------------------- Titelzeile mit Aktionsknopf */
/* Ueberschrift links, Anlege-Knopf rechtsbuendig auf derselben Hoehe.
   nowrap, damit der Knopf nicht unter die Ueberschrift rutscht. */
.section-title {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; flex-wrap: nowrap; margin-bottom: 18px;
}
.section-title > .titel-text { min-width: 0; }
.section-title h1, .section-title h2 { margin-bottom: 2px; }
.section-title .unterzeile { color: var(--ink-soft); font-size: 0.92rem; }

.neu-knopf { flex-shrink: 0; white-space: nowrap; display: inline-flex; align-items: center; }
.neu-knopf .zeichen { font-size: 1.25rem; line-height: 1; font-weight: 700; }
.neu-knopf .wort { margin-left: 8px; }
/* Im geoeffneten Zustand ist es ein Abbrechen-Knopf, nicht mehr ein Anlegen */
.neu-knopf.offen { background: #fff; color: var(--ink); border-color: var(--line); }
.neu-knopf.offen:hover { background: #f0f2f5; }

@media (max-width: 640px) {
  /* Am Handy nur das Zeichen - der Platz neben der Ueberschrift ist knapp */
  .neu-knopf .wort { display: none; }
  .neu-knopf { padding: 9px 14px; }
  .neu-knopf .zeichen { font-size: 1.35rem; }
}

/* --------------------------------------------------------- Verlaufsliste */
/* Aufbau wie die Korrespondenzliste im CRM, damit Meldungen und spaeter
   Mails im selben Bild erscheinen. */
.mail-liste { display: flex; flex-direction: column; gap: 12px; }
.mail {
  border: 1px solid var(--line); border-left: 4px solid var(--info);
  border-radius: 8px; padding: 10px 12px;
}
.mail.ein { border-left-color: var(--ok); }
.mail-kopf { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; }
.mail-text {
  white-space: pre-wrap; overflow-wrap: anywhere;
  margin-top: 8px; font-size: 0.93rem; line-height: 1.45;
}

/* ------------------------------------------------------------- Meldeseite */
/* Der Handwerker steht auf der Baustelle: grosse Flaechen, kein Menue,
   keine Nebenwege. Die Meldearten sind Flaechen zum Antippen, keine
   Auswahlliste - eine Liste braucht zwei Tipper und trifft schlecht. */
.melde-seite { max-width: 520px; margin: 0 auto; padding: 20px 14px 40px; }
.melde-kopf {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.melde-kopf .logo { font-size: 1.25rem; font-weight: 800; }
.melde-kopf .logo span { color: var(--brand); }
.melde-kopf .wer { color: var(--ink-soft); font-size: 0.9rem; }
.melde-karte {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.melde-vorgang { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.melde-vorgang .projektname {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.melde-vorgang h1 { font-size: 1.35rem; margin: 2px 0 6px; }
.melde-fuss { margin-top: 16px; font-size: 0.85rem; color: var(--ink-soft); text-align: center; }

.melde-knoepfe { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.melde-wahl {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; font-weight: 600; color: var(--ink);
  cursor: pointer; margin: 0; background: #fff;
}
.melde-wahl:hover { background: #f7f2ee; }
.melde-wahl input[type="radio"] {
  width: 22px; height: 22px; flex: 0 0 auto; margin: 0; accent-color: var(--brand);
}
/* Die gewaehlte Flaeche muss man ohne Brille erkennen */
.melde-wahl:has(input:checked) {
  border-color: var(--brand); background: #fdf3ec; box-shadow: inset 0 0 0 1px var(--brand);
}

/* -------------------------------------------------- Ablaufdiagramm (SVG) */
/* Namensspalte steht fest, die Zeitachse scrollt waagrecht. Am Handy ist das
   der einzige Weg, ein Gantt lesbar zu halten - ausblenden waere die falsche
   Antwort, denn das Diagramm ist der Kern des Werkzeugs. */
.gantt-rahmen2 {
  display: flex; align-items: stretch;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #fff;
}
.gantt-namen {
  flex: 0 0 168px; border-right: 1px solid var(--line); background: #fbfcfd;
}
.gantt-name {
  display: flex; align-items: center; padding: 0 10px;
  font-size: 0.86rem; overflow: hidden;
}
.gantt-name a {
  color: var(--ink); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gantt-name.kritisch a { color: var(--err); font-weight: 700; }
.gantt-name a:hover { text-decoration: underline; }

.gantt-flaeche { flex: 1; overflow-x: auto; overflow-y: hidden; min-width: 0; }
.gantt-flaeche svg { display: block; }

.gantt-monat { font-size: 11px; font-weight: 700; fill: var(--ink-soft); }
.gantt-tag { font-size: 10px; fill: var(--ink-soft); }
.gantt-tag.frei { fill: #aab3bd; }
.gantt-heute { font-size: 10px; font-weight: 700; fill: var(--brand); }
.gantt-balkentext { font-size: 11px; fill: #fff; font-weight: 600; }

.gantt-legende .probe.frei { background: #eef1f4; border: 1px solid var(--line); }
.gantt-hinweis { margin-top: 10px; }

@media (max-width: 640px) {
  .gantt-namen { flex-basis: 116px; }
  .gantt-name { font-size: 0.8rem; padding: 0 8px; }
  /* Die Legende wird hier gebraucht - anders als bei der Listenansicht */
  .gantt-rahmen2 + .gantt-hinweis { display: block; }
}

/* ------------------------------------------------- Projektkachel / Archiv */
.projekt-kachel .kv { grid-template-columns: 160px 1fr; }
.trenner { border: none; border-top: 1px solid var(--line); margin: 22px 0 16px; }
.loesch-block { margin-top: 14px; }
.loesch-block > summary { font-weight: 600; color: var(--err); }
.loesch-block > summary:hover { color: #a33; }
.archiv-titel { margin-top: 28px; }
@media (max-width: 760px) { .projekt-kachel .kv { grid-template-columns: 1fr; } }

/* ---------------------------------------------------- Stammdaten-Details */
.farbpunkt {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  margin-right: 8px; vertical-align: -1px;
}
.mt { margin-top: 12px; }
.klein { font-size: 0.85rem; }
.checkline { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; }
.checkline input[type="checkbox"] {
  width: 20px; height: 20px; flex: 0 0 auto; margin: 0; accent-color: var(--brand);
}
.checkline label { font-size: 0.95rem; font-weight: 400; color: var(--ink); margin: 0; }
.mail-anhaenge { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 0.87rem; }
.entscheidung {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
}
.entscheidung select { width: auto; min-width: 0; max-width: 100%; }
