/* ============================================================
   styles.css - TEKA NIS-2 (Skelett)
   Design-Tokens nach ProDig-Schema (verbindlicher Standard).
   Header-Navy #1B3A6B in allen Themes (Branding-Anker).
   Vollstaendiges 6-Theme-System folgt mit Schritt 2.
   ============================================================ */

:root,
[data-theme="light"] {
  --header-bg:    #1B3A6B;
  --page-bg:      #f1f5f9;
  --card-bg:      #ffffff;
  --card-border:  #e2e8f0;
  --card-shadow:  0 1px 3px rgba(0,0,0,0.08);
  --text-main:    #1e293b;
  --text-muted:   #64748b;
  --color-blue:   #3b82f6;
  --color-orange: #f59e0b;
  --color-red:    #ef4444;
  --color-green:  #10b981;
  --color-purple: #8b5cf6;
  /* additive Komponenten-Tokens (kein Grunddesign-Eingriff) */
  --radius-input:     6px;
  --radius-card:      8px;
  --radius-container: 12px;
  --transition:       0.15s ease;
}

[data-theme="dark"] {
  /* --header-bg bleibt Navy: Branding-Anker ueber alle Themes */
  --page-bg:     #0f172a;
  --card-bg:     #1e293b;
  --card-border: #334155;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.4);
  --text-main:   #e2e8f0;
  --text-muted:  #94a3b8;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--page-bg);
  color: var(--text-main);
}

/* FOUC-Guard (analog ProDig) */
body { opacity: 0; transition: opacity 0.2s; }
body.ready { opacity: 1; }

/* ---------- Login-Screen ---------- */
#login-screen {
  display: none;
  position: fixed; inset: 0;
  align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(27,58,107,0.15), transparent),
    var(--page-bg);
}
.login-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.12);
  padding: 36px 32px;
  width: 340px; max-width: 90vw;
  text-align: center;
}
.login-logo-wrap {
  background: var(--header-bg);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
  display: flex; align-items: center; justify-content: center;
}
.login-logo-wrap img { height: 36px; filter: brightness(0) invert(1); }
.login-card h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 6px; }
.login-card p  { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 20px; }
#btn-login {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--color-blue); color: #fff;
  border: none; border-radius: 10px;
  padding: 11px 16px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: filter 0.15s;
}
#btn-login:hover { filter: brightness(1.08); }
.login-error { color: var(--color-red); font-size: 0.85rem; margin-top: 12px; min-height: 1em; }

/* ---------- Ladebildschirm ---------- */
#loading-screen {
  display: none;
  position: fixed; inset: 0;
  flex-direction: column; align-items: center; justify-content: center;
  background: var(--page-bg); gap: 16px;
}
.loader-logo-wrap {
  background: var(--header-bg); border-radius: 14px; padding: 20px;
}
.loader-logo-wrap img { height: 40px; filter: brightness(0) invert(1); }
.loader-text { color: var(--text-muted); font-size: 0.9rem; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--card-border); border-top-color: var(--color-blue);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App-Shell ---------- */
#app-wrapper { display: none; flex-direction: column; height: 100vh; }

.header {
  height: 64px;
  background-color: var(--header-bg);
  border-radius: 12px;
  margin: 10px 24px 0 24px;
  padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  color: #fff;
}
.header .title { display: flex; align-items: center; gap: 12px; }
.header .title img { height: 32px; filter: brightness(0) invert(1); }
.header .title span { font-size: 18px; font-weight: 700; }

.header-right { display: flex; align-items: center; gap: 12px; }
#app-version { font-size: 12px; color: rgba(255,255,255,0.7); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 8px;
  background: transparent; border: none; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px; transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.18); }
.avatar-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); overflow: hidden;
  background: rgba(255,255,255,0.15);
  cursor: pointer; padding: 0;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* ============================================================
   Ab hier: Komponenten fuer die Ansichten (Schritt 2).
   Aus Mockup v22 portiert, auf die bestehenden Tokens umgeschrieben.
   Grunddesign (Tokens/Header/Login/Loader/Theme) bleibt unveraendert.
   ============================================================ */

/* ---------- Main / Toolbar / Content ---------- */
#app-wrapper > main {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 10px;
  margin: 10px 24px 24px 24px;
}
.toolbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.toolbar-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.toolbar-info  { font-size: 12px; color: var(--text-muted); margin-left: auto; }

.view-tabs {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  background: var(--page-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-input); padding: 3px;
}
.view-tab {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 13px; border-radius: 4px; font-family: inherit;
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: var(--transition);
}
.view-tab:hover { background: var(--card-bg); color: var(--text-main); }
.view-tab.active { background: var(--color-blue); color: #fff; }

#content { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
/* Kinder duerfen nicht schrumpfen, sonst staucht Flex lange Tabellen und #content scrollt nicht */
#content > * { flex-shrink: 0; }
.view-head { flex-shrink: 0; }
.view-head h2 { font-size: 18px; font-weight: 700; margin: 0 0 2px; }
.view-head .sub { font-size: 12px; color: var(--text-muted); margin: 0; }

/* ---------- KPI-Karten ---------- */
.kpi-bar { display: flex; gap: 12px; flex-shrink: 0; flex-wrap: wrap; }
.kpi-card {
  flex: 1; min-width: 160px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--card-shadow);
}
.kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.kpi-info { flex: 1; min-width: 0; }
.kpi-value { font-size: 1.4rem; font-weight: 800; line-height: 1.2; }
.kpi-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 0.65rem; color: var(--text-muted); opacity: 0.7; }

/* ---------- Hinweis-Box ---------- */
.note {
  border: 1px solid var(--card-border); border-left: 4px solid var(--color-blue);
  border-radius: var(--radius-card); background: var(--card-bg);
  padding: 10px 14px; font-size: 12px; line-height: 1.5;
}
.note.warn { border-left-color: var(--color-orange); }
.note .bi { margin-right: 4px; }
.note .bi-info-circle-fill { color: var(--color-blue); }
.note.warn .bi { color: var(--color-orange); }

/* ---------- Datentabelle ---------- */
.table-wrapper {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-container); box-shadow: var(--card-shadow); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--text-muted);
  padding: 10px 14px; border-bottom: 1px solid var(--card-border); white-space: nowrap;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--card-border); vertical-align: top; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.wrap, .data-table th.wrap { white-space: normal; }
.data-table tr.group td {
  background: var(--page-bg); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.3px; color: var(--text-muted); white-space: normal;
}
.data-table tr.m-row:hover td { background: rgba(59,130,246,0.04); }

/* ---------- Inline-Helfer ---------- */
.mk-anf { font-weight: 600; }
.mono { font-family: 'Consolas', monospace; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.link { color: var(--color-blue); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }
.empty { color: var(--text-muted); opacity: 0.7; font-style: italic; }
.progress-txt { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* ---------- Status-Badge (Maßnahme) ---------- */
.status-badge {
  padding: 4px 14px; border-radius: 20px; font-size: 0.78rem; font-weight: 700;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.sb-erf   { background: rgba(134,239,172,0.35); color: #15803d; }
.sb-teil  { background: rgba(253,186,116,0.35); color: #9a3412; }
.sb-offen { background: rgba(147,197,253,0.40); color: #1d4ed8; }

/* ---------- Aufklappbare Maßnahmen + Unteraufgaben ---------- */
.m-toggle { display: flex; align-items: flex-start; gap: 6px; cursor: pointer; user-select: none; }
.m-toggle .chev { transition: transform 0.15s ease; color: var(--text-muted); margin-top: 1px; }
.m-toggle.open .chev { transform: rotate(90deg); }
.m-detail td { background: var(--page-bg); }
.subtasks { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 4px 22px; }
.st-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.subtask {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border: 1px solid var(--card-border); border-radius: var(--radius-card); background: var(--card-bg);
}
.subtask .st-title { flex: 1; font-size: 12px; }
.subtask .st-card { font-size: 0.7rem; white-space: nowrap; }
.task-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 700; cursor: pointer; white-space: nowrap; transition: var(--transition);
}
.task-pill:hover { filter: brightness(0.96); }
.tp-offen    { background: rgba(147,197,253,0.40); color: #1d4ed8; }
.tp-bearb    { background: rgba(125,211,252,0.45); color: #0369a1; }
.tp-erledigt { background: rgba(134,239,172,0.40); color: #15803d; }
.add-task-row { padding-left: 2px; }
.add-task { font-size: 0.72rem; }

/* ---------- Label-Chip ---------- */
.label-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  background: var(--page-bg); border: 1px solid var(--card-border); color: var(--text-main);
}

/* ---------- Mini-Eingabe (Unteraufgabe hinzufuegen) ---------- */
.chip-input { display: inline-flex; align-items: center; gap: 5px; }
.chip-input input { padding: 4px 10px; height: 28px; border: 1px solid var(--card-border); border-radius: var(--radius-input); font-family: inherit; font-size: 0.78rem; background: var(--card-bg); color: var(--text-main); }
.cell-btn {
  border: 1px solid var(--card-border); background: var(--card-bg); color: var(--text-main);
  border-radius: var(--radius-input); width: 28px; height: 28px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: var(--transition);
}
.cell-btn:hover { background: var(--page-bg); }

/* ---------- Sekundaer-Button ---------- */
.btn-secondary {
  border: 1px solid var(--card-border); background: var(--card-bg); color: var(--text-main);
  border-radius: var(--radius-input); padding: 6px 12px; font-family: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: var(--transition);
}
.btn-secondary:hover { background: var(--page-bg); }

/* ---------- Platzhalter fuer noch nicht gebaute Ansichten ---------- */
.placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 8px; padding: 60px 20px; text-align: center; }
.placeholder .bi { font-size: 38px; opacity: 0.35; }
.placeholder .pv-title { font-size: 15px; font-weight: 600; color: var(--text-main); }

/* ---------- Toasts (im Mockup aus teka-base, hier app-lokal) ---------- */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
  background: var(--card-bg); color: var(--text-main);
  border: 1px solid var(--card-border); border-left: 4px solid var(--color-blue);
  border-radius: var(--radius-card); box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 10px 14px; font-size: 13px; max-width: 340px;
  opacity: 1; transform: translateX(0); transition: opacity .3s ease, transform .3s ease;
}
.toast-warning { border-left-color: var(--color-orange); }
.toast-fadeout { opacity: 0; transform: translateX(20px); }

/* ---------- Risikoklassen-Badges (Risiken / Intervalle) ---------- */
.rk { display: inline-flex; align-items: center; gap: 5px; padding: 4px 12px; border-radius: 20px; font-size: 0.74rem; font-weight: 700; white-space: nowrap; }
.rk-niedrig  { background: rgba(134,239,172,0.35); color: #15803d; }
.rk-mittel   { background: rgba(254,240,138,0.55); color: #854d0e; }
.rk-hoch     { background: rgba(253,186,116,0.50); color: #9a3412; }
.rk-kritisch { background: rgba(239,68,68,0.30);  color: #b91c1c; }

/* ============================================================
   Schritt 2c: Nutzer-Popup, Konfig-Modals, Berichtswesen,
   Statistiken, Formularfelder. Aus Mockup v22, auf Tokens.
   ============================================================ */

/* ---------- Basis Eingabefelder ---------- */
input[type="text"], input[type="email"], input[type="number"], input[type="date"], select {
  font-family: inherit; font-size: 13px; color: var(--text-main);
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-input); padding: 6px 10px; height: 34px;
}
input:focus, select:focus { outline: none; border-color: var(--color-blue); }
select { cursor: pointer; }

/* ---------- Primaer-Button ---------- */
.btn-primary {
  border: none; background: var(--color-blue); color: #fff;
  border-radius: var(--radius-input); padding: 7px 14px; font-family: inherit;
  font-size: 12px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: filter var(--transition);
}
.btn-primary:hover { filter: brightness(1.08); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Nutzer-Popup ---------- */
.popup {
  display: none; position: fixed; top: 86px; right: 24px; z-index: 1500;
  width: 340px; max-width: 92vw; max-height: 80vh; overflow-y: auto;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-container); box-shadow: 0 16px 48px rgba(0,0,0,0.18);
  padding: 16px 18px;
}
.popup.open { display: block; }
.popup h4 { font-size: 12px; font-weight: 700; margin: 14px 0 6px; color: var(--text-main); }
.popup h4:first-child { margin-top: 0; }
.popup input { width: 100%; }
.popup-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-top: 4px;
  border: 1px solid var(--card-border); border-radius: var(--radius-card);
  font-size: 12px; cursor: pointer; transition: var(--transition);
}
.popup-item:hover { background: var(--page-bg); border-color: var(--color-blue); }
.label-chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 32px; }
.label-chip .chip-remove { cursor: pointer; font-size: 0.8rem; opacity: 0.6; }
.label-chip .chip-remove:hover { opacity: 1; color: var(--color-red); }
.label-chip.add { border-style: dashed; cursor: pointer; opacity: 0.75; }
.label-chip.add:hover { opacity: 1; border-color: var(--color-blue); }

/* ---------- Modals (native <dialog>) ---------- */
dialog.modal {
  border: 1px solid var(--card-border); border-radius: var(--radius-container);
  background: var(--card-bg); color: var(--text-main);
  padding: 22px 24px; width: 460px; max-width: 92vw; box-shadow: 0 24px 64px rgba(0,0,0,0.30);
}
dialog.modal.modal-wide { width: 640px; }
dialog.modal::backdrop { background: rgba(15,23,42,0.45); }
dialog.modal h3 { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.modal-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 12px 0 0; }
.modal-label input { display: block; width: 120px; margin-top: 4px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.measure-list { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.measure-art { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin-top: 8px; }
.measure-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--card-border); border-radius: var(--radius-card); background: var(--page-bg); }
.measure-item .mi-anf { flex: 1; font-size: 12px; }
.measure-add { border-top: 1px solid var(--card-border); padding-top: 12px; }
.ri-ws { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.ri-ws select { padding: 2px 6px; height: 26px; }
.cell-btn--ghost { border-color: transparent; color: var(--text-muted); }
.cell-btn--ghost:hover { color: var(--color-red); background: var(--page-bg); }

/* ---------- Formular-Bausteine (Berichtswesen) ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.box.intern { border-top: 3px solid var(--color-blue); }
.box.extern { border-top: 3px solid var(--color-orange); }
.fieldset { display: flex; flex-direction: column; gap: 10px; }
.frow { display: flex; gap: 10px; flex-wrap: wrap; }
.frow > div { flex: 1; min-width: 140px; }
.flabel { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 4px; }
.frow select, .frow input { width: 100%; }

/* ---------- Freigabe-Gate ---------- */
.gate { display: flex; gap: 10px; flex-wrap: wrap; }
.gate-step { flex: 1; min-width: 150px; border: 1px solid var(--card-border); border-radius: var(--radius-card); padding: 12px; background: var(--page-bg); }
.gate-num { width: 22px; height: 22px; border-radius: 50%; background: var(--color-blue); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 7px; }
.gate-step.final .gate-num { background: var(--color-green); }
.gate-step .gt { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.gate-step .gd { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

/* ---------- Statistiken ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 860px) { .stat-grid { grid-template-columns: 1fr; } }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-row .bl { width: 110px; font-size: 12px; color: var(--text-main); flex-shrink: 0; }
.bar-track { flex: 1; height: 18px; background: var(--page-bg); border: 1px solid var(--card-border); border-radius: 9px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 9px; transition: width 0.3s ease; }
.bar-val { width: 30px; text-align: right; font-size: 12px; font-weight: 700; }

/* --- Lieferanten: Filterleiste + Kritikalitaet-Dropdown --- */
.lief-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; flex-wrap: wrap; }
.lief-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-main); cursor: pointer; }
.lief-select { padding: 5px 10px; border: 1px solid var(--card-border); border-radius: var(--radius-input); background: var(--card-bg); color: var(--text-main); font-family: inherit; font-size: 13px; cursor: pointer; }
.lief-select:focus { outline: none; border-color: var(--color-blue); }
.lief-date { padding: 4px 10px; border: 1px solid var(--card-border); border-radius: var(--radius-input); background: var(--card-bg); color: var(--text-main); font-family: inherit; font-size: 13px; }
.lief-date:focus, .lief-select:focus { outline: none; border-color: var(--color-blue); }
.vf-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.vf-input { padding: 6px 12px; border: 1px solid var(--card-border); border-radius: var(--radius-input); background: var(--card-bg); color: var(--text-main); font-family: inherit; font-size: 13px; min-width: 240px; }
.vf-input:focus { outline: none; border-color: var(--color-blue); }
.vf-del { color: #b91c1c; cursor: pointer; font-size: 12px; }
.vf-desc { width: 100%; min-height: 48px; margin-top: 6px; padding: 6px 8px; border: 1px solid var(--card-border); border-radius: var(--radius-input); background: var(--card-bg); color: var(--text-main); font-family: inherit; font-size: 12px; line-height: 1.4; resize: vertical; }
.vf-desc:focus { outline: none; border-color: var(--color-blue); }
