/* ==========================================================================
   WorkSimple Aufwandsschätzung - Branding & Layout
   Die Markenfarben stehen gebündelt in :root - hier lassen sich exakte
   CI-Werte in einem Schritt austauschen.
   ========================================================================== */

:root {
  /* Marke */
  --ws-navy: #0b1c33;
  --ws-navy-soft: #14284a;
  --ws-blue: #1f6feb;
  --ws-blue-dark: #14396b;
  --ws-blue-light: #dce6f1;
  --ws-teal: #00b39a;
  --ws-amber: #f5a623;
  --ws-red: #d64545;

  /* Flächen (Light Mode) */
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eaeff6;
  --border: #d5dde8;
  --border-strong: #b9c5d6;
  --text: #17212f;
  --text-muted: #5a6a80;
  --text-invert: #ffffff;
  --shadow: 0 1px 2px rgba(11, 28, 51, .06), 0 8px 24px rgba(11, 28, 51, .08);
  --shadow-sm: 0 1px 2px rgba(11, 28, 51, .08);

  --gantt-section: #14396b;
  --gantt-task: #1f6feb;
  --gantt-task-soft: #7fb0f7;
  --gantt-grid: #dfe6ef;
  --gantt-band: #f4f7fb;
  --gantt-today: #d64545;

  --radius: 10px;
  --radius-sm: 6px;
  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0a1424;
  --surface: #10203a;
  --surface-2: #16273f;
  --surface-3: #1c3050;
  --border: #24395b;
  --border-strong: #33507c;
  --text: #e7eefa;
  --text-muted: #9fb2cc;
  --ws-blue-light: #1c3050;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);

  --gantt-section: #a9cbff;
  --gantt-task: #2f7ef5;
  --gantt-task-soft: #2b5288;
  --gantt-grid: #23375a;
  --gantt-band: #13243d;
  --gantt-today: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

/* ------------------------------------------------------------------ Header */

.app-header {
  background: linear-gradient(120deg, var(--ws-navy) 0%, var(--ws-blue-dark) 100%);
  color: var(--text-invert);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-name { font-size: 17px; font-weight: 700; letter-spacing: .2px; line-height: 1.1; }
.brand-name span { font-weight: 300; }
.brand-sub { font-size: 11.5px; opacity: .72; letter-spacing: .06em; text-transform: uppercase; }

.app-nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }

.nav-btn {
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .12);
  padding: 7px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.nav-btn:hover { background: rgba(255, 255, 255, .18); }
.nav-btn[aria-selected="true"] { background: #fff; color: var(--ws-navy); border-color: #fff; font-weight: 600; }

.theme-toggle {
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  color: #fff;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 15px;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .2); }

/* ------------------------------------------------------------------- Layout */

main { padding: 22px 24px 80px; max-width: 1800px; margin: 0 auto; }
.view[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h2 { font-size: 15px; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* ----------------------------------------------------------------- Buttons */

.btn {
  font: inherit;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ws-blue); border-color: var(--ws-blue); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--ws-blue-dark); border-color: var(--ws-blue-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--ws-red); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(214, 69, 69, .12); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-icon { padding: 4px 7px; font-size: 13px; line-height: 1; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Formulare */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

input, textarea, select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ws-blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .18);
}
textarea { resize: vertical; min-height: 34px; }
::placeholder { color: var(--text-muted); opacity: .7; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.meta-grid-spaced { margin-bottom: 14px; }
.split-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* --------------------------------------------------------- Schätzungs-Assistent */

.stepper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.step {
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, color .15s, background .15s;
}
.step:hover { border-color: var(--border-strong); color: var(--text); }
.step.is-current { border-color: var(--ws-blue); color: var(--text); box-shadow: 0 0 0 2px rgba(31, 111, 235, .16); }
.step.is-done { color: var(--text); }

.step-num {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700;
  background: var(--surface-3);
  color: var(--text-muted);
}
.step.is-current .step-num { background: var(--ws-blue); color: #fff; }
.step.is-done .step-num { background: var(--ws-navy); color: #fff; }
.step.is-done .step-num::after { content: '✓'; }
.step.is-done .step-num { font-size: 0; }
.step.is-done .step-num::after { font-size: 13px; }

.step-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.step-text strong { font-size: 13.5px; font-weight: 600; }
.step-text small { font-size: 11.5px; color: var(--text-muted); }

.step-panel[hidden] { display: none; }

.step-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.step-nav .spacer { margin-left: auto; }
.step-nav-hint { font-size: 12.5px; color: var(--text-muted); }

.hint-lead { margin: 0 0 14px; max-width: 78ch; }
.hint-inset { padding: 14px 18px 0; }

.note-grid { margin-top: 18px; }
.note-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 13px 16px;
}
.note-box h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 7px; }
.note-box ul { margin: 0; padding-left: 18px; font-size: 13px; }
.note-box li { margin-bottom: 3px; }

/* -------------------------------------------------------- Drag and Drop */

tr.drag-handle-row td.cell-nr { cursor: grab; }
tr.dragging { opacity: .4; }
tr.drop-before td { box-shadow: inset 0 2px 0 var(--ws-blue); }
tr.drop-after td { box-shadow: inset 0 -2px 0 var(--ws-blue); }
td.cell-nr .drag-dots {
  display: block;
  font-size: 10px;
  line-height: 1;
  color: var(--text-muted);
  opacity: .55;
}

input[type="checkbox"] { width: auto; }
.check-row { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.hint-footnote { margin: 12px 0 0; }
.estimate-schedule { min-width: 760px; }
.col-plan { width: 190px; }
.col-duration { width: 140px; }
td.cell-static { padding-top: 8px; }

/* Angemeldete Person (Entra-SSO) */
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 999px;
  padding: 4px 5px 4px 13px;
  font-size: 12.5px;
  color: #fff;
  max-width: 320px;
}
.user-chip[hidden] { display: none; }
.user-chip .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip button {
  font: inherit;
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  background: rgba(255, 255, 255, .14);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}
.user-chip button:hover { background: rgba(255, 255, 255, .26); }

/* Anmelde-Gate: verdeckt die App, bis MSAL eine gültige Sitzung bestätigt hat */
body.auth-pending .app-header,
body.auth-pending main { display: none; }

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(120deg, var(--ws-navy) 0%, var(--ws-blue-dark) 100%);
}
.auth-gate[hidden] { display: none; }
.auth-gate-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: #fff;
  font-size: 14.5px;
  text-align: center;
  padding: 0 24px;
}
.auth-gate-box p.auth-gate-error { color: #ffb4b4; max-width: 460px; }

/* -------------------------------------------------------------- Kennzahlen */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

/* Kacheln teilen sich Hairlines statt einzeln umrandet zu sein - eine
   zusammenhaengende Flaeche statt gestapelter Einzelkarten. Die Gesamtsumme
   ist die einzige mit Akzentflaeche, alle anderen bleiben neutral. */
.kpi { padding: 12px 14px; background: var(--surface); }
.kpi.kpi-total { background: var(--ws-blue-light); }
.kpi.kpi-open .kpi-value { color: var(--ws-amber); }
.kpi-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-value { font-size: 21px; font-weight: 700; line-height: 1.25; }
.kpi-sub { font-size: 12px; color: var(--text-muted); }

/* ------------------------------------------------------------------ Tabelle */

.table-scroll { overflow-x: auto; }

table.estimate {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

/* Lange Wörter dürfen die Tabelle nicht breiter machen als den Container. */
table.estimate td, table.estimate th { overflow-wrap: anywhere; }
table.estimate input, table.estimate textarea { min-width: 0; }

/* Mehrzeilige Felder wachsen mit dem Inhalt statt zu scrollen.
   field-sizing ist seit Mitte 2026 Baseline; wo es fehlt, stellt
   autoGrow() in table.js die Höhe per JavaScript ein. */
table.estimate textarea {
  field-sizing: content;
  resize: none;
  overflow: hidden;
  min-height: 28px;
  line-height: 1.35;
}

table.estimate th {
  background: var(--ws-blue-light);
  color: var(--text);
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
}

table.estimate td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 3px 5px;
  vertical-align: top;
}

table.estimate tr.section-row > td {
  background: var(--surface-3);
  font-weight: 600;
  padding-top: 5px;
  padding-bottom: 5px;
}
:root[data-theme="dark"] table.estimate tr.section-row > td { background: var(--surface-3); }

table.estimate tr.task-row:hover > td { background: var(--surface-2); }
table.estimate tr.sum-row > td {
  background: var(--ws-navy);
  color: #fff;
  font-weight: 700;
  padding: 9px 8px;
  border-color: var(--ws-navy);
}
table.estimate tr.sum-row .sum-value { font-size: 14px; }

.col-nr { width: 46px; }
/* Bei automatischem Layout sind diese Breiten Richtwerte: der Browser füllt
   den Container vollständig und gibt der Action-Spalte den Rest. */
.col-date { width: 108px; }
.col-hours { width: 82px; }
.col-pert { width: 62px; }
.col-status { width: 104px; }
.col-resp { width: 130px; }
.col-note { width: 20%; }
.col-actions { width: 76px; }

/* PERT-Spalten sind nur im Drei-Punkt-Modus sichtbar. */
.is-hidden { display: none; }
col.col-pert.is-hidden { width: 0; }

td.cell-nr { font-weight: 600; text-align: center; padding-top: 8px; color: var(--text-muted); }
tr.section-row td.cell-nr { color: var(--text); }
td.cell-hours input { text-align: right; font-variant-numeric: tabular-nums; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

table.estimate input,
table.estimate textarea,
table.estimate select {
  border-color: transparent;
  background: transparent;
  padding: 5px 6px;
}
table.estimate input:hover,
table.estimate textarea:hover,
table.estimate select:hover { border-color: var(--border); }
table.estimate input:focus,
table.estimate textarea:focus,
table.estimate select:focus { background: var(--surface); border-color: var(--ws-blue); }

table.estimate .section-title-input { font-weight: 700; font-size: 13.5px; }
.tbd-flag { background: rgba(245, 166, 35, .22) !important; border-color: var(--ws-amber) !important; }

/* Zeilen zum Anlegen: dezent, aber klar als Aktion erkennbar */
tr.add-row > td { padding: 2px 6px; background: var(--surface-2); }
tr.add-row .btn { color: var(--ws-blue); }
tr.add-row .btn:hover { background: var(--surface-3); }
tr.add-section-row > td { padding: 5px 6px; border-top: 1px solid var(--border-strong); }
tr.add-section-row .btn { font-weight: 600; }
input.locked { color: var(--text-muted); opacity: .85; cursor: not-allowed; }
input.locked:hover { border-color: transparent; }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ------------------------------------------------------------------- Gantt */

.gantt-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.gantt-toolbar .field { flex-direction: row; align-items: center; gap: 7px; }
.gantt-toolbar .field label { text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.gantt-toolbar select { width: auto; }

.gantt-wrap { overflow-x: auto; background: var(--surface); padding: 8px 0 16px; }
.gantt-wrap svg { display: block; }

.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 18px 0; font-size: 12.5px; color: var(--text-muted); }
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-swatch { width: 22px; height: 11px; border-radius: 3px; display: inline-block; }

/* ------------------------------------------------- Gespeicherte Aufwände */

.filter-toolbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.filter-toolbar .field { flex-direction: row; align-items: center; gap: 7px; }
.filter-toolbar .field label { text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.filter-toolbar input, .filter-toolbar select { width: auto; }
.filter-toolbar input[type="search"] { min-width: 200px; }

.entry-list { display: grid; gap: 10px; }

.entry {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.entry.is-current { border-color: var(--ws-blue); box-shadow: 0 0 0 2px rgba(31, 111, 235, .14); }
.entry-main { min-width: 220px; flex: 1; }
.entry-title { font-weight: 600; font-size: 14px; }
.entry-meta { font-size: 12px; color: var(--text-muted); }
.entry-stats { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-muted); }
.entry-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.entry-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ws-blue);
  color: #fff;
  letter-spacing: .03em;
}
.badge-muted { background: var(--surface-3); color: var(--text-muted); }

.empty-state { padding: 34px 18px; text-align: center; color: var(--text-muted); }
.empty-state strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 5px; }

/* ------------------------------------------------------------------ Dialoge */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(720px, 92vw);
}
dialog::backdrop { background: rgba(7, 16, 30, .55); }
dialog .card-head { border-radius: var(--radius) var(--radius) 0 0; }
dialog .dialog-body { padding: 18px; display: grid; gap: 14px; }
dialog .dialog-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2); }
dialog textarea { min-height: 190px; font-family: "Consolas", "SF Mono", monospace; font-size: 12px; }

.hint { font-size: 12.5px; color: var(--text-muted); }

/* -------------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ws-navy);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Schwebt frei ueber der Seite statt im Dokumentfluss - kein Layout-Sprung
   beim Ein-/Ausblenden. */
.autosave-chip {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 110;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: calc(100vw - 32px);
}
.autosave-chip[hidden] { display: none; }
.autosave-chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ws-teal); flex: 0 0 auto; }
.autosave-chip-name {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

@media (max-width: 860px) {
  main { padding: 16px 12px 60px; }
  .app-header { padding: 12px 14px; }
  .app-nav { width: 100%; margin-left: 0; }
}

@media print {
  .app-header, .card-head .btn-group, .gantt-toolbar, .col-actions { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
