@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    --paper: #F5F6F4;
    --surface: #FFFFFF;
    --graphite: #1F2A33;
    --steel: #5B6B76;
    --steel-light: #8E9AA3;
    --hairline: #DDE1DE;
    --teal: #0E7C7B;
    --teal-light: #E1F1F0;
    --family: #6B4FA0;
    --family-light: #EDE7F6;
    --amber: #C9862C;
    --amber-light: #FBF0DE;
    --green: #3F7D58;
    --orange: #D9622E;
    --orange-light: #FBEAE3;
    --blue: #1D63D1;
    --blue-light: #E8F1FA;
}

* { box-sizing: border-box; }
body {
    font-family: 'IBM Plex Sans', -apple-system, Segoe UI, Arial, sans-serif;
    margin: 0;
    background: var(--paper);
    color: var(--graphite);
    font-size: 14px;
}
.mono { font-family: 'IBM Plex Mono', monospace; }

header {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border-bottom: 1px solid var(--hairline);
    padding: 14px 28px; flex-wrap: wrap; gap: 10px 14px;
}
.header-right { flex-wrap: wrap; }
header .logo {
    color: var(--graphite); font-weight: 600; text-decoration: none; font-size: 15px;
}
header .logo .sub { color: var(--steel); font-weight: 400; }
header .active-project {
    background: var(--teal, #0FB5AE); color: #fff; font-weight: 600; font-size: 12.5px;
    padding: 4px 12px; border-radius: 20px; text-decoration: none; white-space: nowrap;
}
header .active-project:hover { filter: brightness(0.95); }
/* DocuSign-Kennzeichen: blaues „DS" für signierte/genehmigte (unveränderbare) Dokumente. */
.ds-badge {
    display: inline-block; background: #1246A0; color: #fff; font-size: 10px; font-weight: 700;
    padding: 2px 6px; border-radius: 4px; letter-spacing: 0.5px; vertical-align: middle;
}
.topnav { display: flex; gap: 22px; font-size: 13px; }
.topnav a { color: var(--steel); text-decoration: none; }
.topnav a.active { color: var(--graphite); font-weight: 500; }
.topnav-changes {
    font-size: 13px; color: var(--steel); text-decoration: none; padding: 4px 10px;
    border: 1px solid var(--hairline); border-radius: 14px; background: var(--surface);
}
.topnav-changes.active, .topnav-changes:hover { color: var(--graphite); border-color: var(--teal); }

main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
h1 { font-size: 21px; font-weight: 600; margin: 0 0 6px; }
h1 small { color: var(--steel); font-weight: 400; font-size: 14px; }
h2 { font-size: 15px; font-weight: 600; }

.button {
    display: inline-block; background: var(--teal); color: #fff;
    padding: 8px 16px; border-radius: 4px; text-decoration: none;
    margin: 4px 6px 4px 0; font-size: 13px; font-weight: 500; border: none; cursor: pointer;
}
.button.secondary { background: var(--surface); color: var(--graphite); border: 1px solid var(--hairline); }
button {
    background: var(--teal); color: #fff; padding: 8px 16px; border-radius: 4px;
    border: none; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 500;
}
button.secondary { background: var(--surface); color: var(--graphite); border: 1px solid var(--hairline); }
.link-button { background: none; border: none; color: var(--orange); text-decoration: underline; cursor: pointer; padding: 0; }

.list-table { width: 100%; border-collapse: collapse; background: var(--surface); margin-top: 12px; border: 1px solid var(--hairline); }
.list-table th, .list-table td { border-bottom: 1px solid var(--hairline); padding: 10px 12px; text-align: left; font-size: 13px; vertical-align: top; }
.list-table.small td, .list-table.small th { font-size: 12px; padding: 6px 10px; }
.list-table th { background: var(--paper); color: var(--steel); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.critical-row { background: #FCEBEB; }
.deviation-row { background: var(--amber-light); }

.form-box { background: var(--surface); padding: 20px; border-radius: 6px; max-width: 700px; border: 1px solid var(--hairline); }
.form-box label { display: block; margin-bottom: 14px; font-weight: 500; font-size: 13px; }
.form-box input, .form-box select, .form-box textarea {
    display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
    border: 1px solid var(--hairline); border-radius: 4px; font-weight: normal;
    font-family: inherit; font-size: 13px; background: var(--paper);
}
fieldset { border: 1px solid var(--hairline); margin-bottom: 12px; padding: 10px; border-radius: 6px; }
legend { font-weight: 500; font-size: 12.5px; color: var(--steel); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.card-eyebrow { font-size: 11px; color: var(--teal); font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.page-section-title { font-size: 14px; font-weight: 600; color: var(--steel); text-transform: uppercase; letter-spacing: 0.06em; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--hairline); }
.page-section-title:first-of-type { margin-top: 8px; }
.eq-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--hairline); margin: 16px 0 20px; }
.eq-tab { background: none; border: none; padding: 10px 16px; font-size: 14px; font-weight: 500; color: var(--steel); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.eq-tab.active { color: var(--teal); border-bottom-color: var(--teal); }
.eq-tab:hover { color: var(--graphite); }

/* Mobile PWA (Nachweis-Erfassung, siehe blueprints/mobile.py) - grosse Touch-Ziele, minimales
   Chrome, kein Desktop-Navigations-Overhead */
.mobile-body { margin: 0; background: var(--paper); }
.mobile-header { background: var(--teal); color: #fff; padding: 16px 20px; position: sticky; top: 0; z-index: 10; }
.mobile-header-title { font-size: 18px; font-weight: 600; }
.mobile-main { padding: 16px; max-width: 600px; margin: 0 auto; }
.mobile-search { width: 100%; padding: 14px 16px; font-size: 16px; border: 1px solid var(--hairline); border-radius: 10px; margin-bottom: 14px; box-sizing: border-box; }
.mobile-list-item { display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--hairline); border-radius: 10px; padding: 16px; margin-bottom: 10px; font-size: 16px; text-decoration: none; color: var(--graphite); box-sizing: border-box; }
.mobile-list-item .mobile-item-sub { display: block; font-size: 13px; color: var(--steel); margin-top: 4px; }
.mobile-list-item.done { border-left: 5px solid #3F7D58; }
.mobile-list-item.open { border-left: 5px solid #C9862C; }
.mobile-camera-btn { display: block; width: 100%; padding: 16px; font-size: 17px; font-weight: 600; background: var(--orange); color: #fff; border: none; border-radius: 10px; text-align: center; margin-top: 8px; }
.mobile-back-link { display: inline-block; margin-bottom: 14px; color: var(--teal); text-decoration: none; font-size: 15px; }
.card { background: var(--surface); padding: 18px; border-radius: 6px; border: 1px solid var(--hairline); }
.hint { color: var(--steel); font-size: 12.5px; }
.scope-list { padding-left: 18px; }
.badge { background: var(--paper); border: 1px solid var(--hairline); padding: 2px 8px; border-radius: 4px; font-size: 11px; vertical-align: middle; }
.flash {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 11px 14px; border-radius: 6px; margin-bottom: 10px; font-size: 13px;
    border: 1px solid transparent; transition: opacity .4s ease;
}
.flash .flash-msg { flex: 1; }
.flash::before { font-weight: 700; flex-shrink: 0; line-height: 1.35; }
.flash-close {
    background: none; border: none; color: inherit; cursor: pointer;
    font-size: 18px; line-height: 1; opacity: .55; padding: 0 2px; margin: -2px -4px 0 0;
}
.flash-close:hover { opacity: 1; }
.flash.flash-fade { opacity: 0; }
.flash-success { background: var(--teal-light); color: #085041; border-color: #B7DED9; }
.flash-success::before { content: "✓"; }
.flash-error { background: #FCEBEB; color: #791F1F; border-color: #F0C9C9; }
.flash-error::before { content: "✕"; }
.flash-warning { background: var(--amber-light); color: #633806; border-color: #EAD1A0; }
.flash-warning::before { content: "⚠"; }
.flash-info, .flash-message { background: var(--blue-light); color: #123A6B; border-color: #C3D9F2; }
.flash-info::before, .flash-message::before { content: "ℹ"; }
.sra-table textarea, .sra-table select { width: 100%; font-size: 12.5px; }
.matrix-table th, .matrix-table td { text-align: center; }
.matrix-table td:first-child, .matrix-table th:first-child { text-align: left; }
.matrix-table td a { font-weight: 500; }

/* Equipment-Tag: Signatur-Element, ueberall wo eine ID/Kennung auftaucht */
.eq-tag {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface); border: 1px solid var(--hairline); border-radius: 4px;
    padding: 3px 10px 3px 8px; font-size: 12px; font-weight: 500;
}
.eq-tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--steel-light); flex-shrink: 0; }
.eq-tag.vmp { background: var(--graphite); color: #fff; border-color: var(--graphite); }
.eq-tag.vmp::before { background: var(--teal); }

/* Status-Zellen: generiert (orange) / hochgeladen (blau) / Quelle (beige) / Family Approach (tuerkis gestrichelt) */
.cell-generated { background: var(--orange); color: #fff; }
.cell-generated a { color: #fff; font-weight: 600; text-decoration: underline; }
.cell-generated a::before { content: "● "; }
.cell-uploaded { background: var(--blue); color: #fff; }
.cell-uploaded a { color: #fff; font-weight: 600; text-decoration: underline; }
.cell-uploaded a::before { content: "▲ "; }
.cell-source { background: #F4EDE9; }
.matrix-source-row td { font-size: 11px; vertical-align: top; }
.matrix-generated-row td { border-bottom: none; }
.matrix-source-row td { border-top: none; }
.source-file-entry { white-space: normal; word-break: break-word; padding: 2px 0; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 3px; }
.legend-swatch.cell-generated { background: var(--orange); }
.legend-swatch.cell-uploaded { background: var(--blue); }
.legend-swatch.cell-source { background: #F4EDE9; border: 1px solid #d8c9c0; }

/* Follow-up-Excel Status-Zeile (informativer Soll-Ist-Abgleich) */
.matrix-followup-row td { font-size: 11px; padding-top: 2px; }
.badge-approved { background: #EAF3DE; color: #173404; }
.badge-approved::before { content: "✓ "; }
.badge-progress { background: var(--amber-light); color: #633806; }
.badge-progress::before { content: "◐ "; }

/* Family Approach: Verweis auf gemeinsames Mutterdokument statt "-" - eigene Farbe (Violett),
   bewusst getrennt von der Marken-/Interaktionsfarbe Türkis (Buttons, Nav, Links) */
.cell-inherited { background: var(--family-light); border: 1px dashed var(--family); color: var(--family); }
.cell-inherited a { color: var(--family); font-weight: 600; }
.cell-inherited a::before { content: "◆ "; }
.legend-swatch.cell-inherited { background: var(--family-light); border: 1px dashed var(--family); }

/* Excel-Pending: laut Follow-up-Excel existiert das Dokument bereits irgendwo, ist aber noch
   nicht in der App (weder generiert noch hochgeladen) - hellblau als "hol das noch rein"-Hinweis,
   bewusst unterscheidbar vom kraeftigen dunklen Blau fuer "bereits hochgeladen" */
.cell-excel-pending { background: #DCEEFB; border: 1px dashed var(--blue); color: #1D4E89; }
.cell-excel-conflict { background: #FCEBEB; border: 2px solid #C0392B; color: #7A1F17; font-weight: 600; }
.legend-swatch.cell-excel-pending { background: #DCEEFB; border: 1px dashed var(--blue); }

.stale-warn { position: relative; cursor: help; display: inline-block; }
.matrix-equipment-end td { border-bottom: 3px solid var(--graphite) !important; }
.stale-tooltip {
    display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
    transform: translateX(-50%); width: 230px; background: var(--graphite); color: #fff;
    font-weight: 400; font-size: 11.5px; line-height: 1.5; padding: 9px 11px;
    border-radius: 6px; text-align: left; z-index: 20; white-space: normal;
}
.stale-tooltip::after {
    content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border: 5px solid transparent; border-top-color: var(--graphite);
}
.stale-tooltip a { color: #8FD9D8; }
.stale-warn:hover .stale-tooltip { display: block; }
.matrix-table td { position: relative; overflow: visible; }

/* Dokumentenbaum (SVG) */
.doc-tree-svg { width: 100%; height: auto; min-width: 600px; }
.doc-tree-svg a { cursor: pointer; }

/* Drag & Drop Datei-Upload (siehe static/dragdrop.js) */
.dropzone {
    border: 2px dashed var(--hairline); border-radius: 6px; padding: 10px;
    background: var(--paper); transition: background 0.15s, border-color 0.15s; margin: 4px 0 10px 0;
}
.dropzone.dragover { border-color: var(--teal); background: var(--teal-light); }
.dropzone.has-file { border-style: solid; border-color: var(--teal); }
.dropzone input[type="file"] { display: block; width: 100%; cursor: pointer; }
.dropzone-label { margin-top: 6px; font-size: 12px; color: var(--steel); }

/* ============================================================================================
   Responsivitaet – die Haupt-App war bisher rein Desktop (keine Breakpoints). Diese Regeln
   lassen Kopfzeile und Inhalte auf Tablet/Handy sinnvoll umbrechen, ohne die Desktop-Ansicht
   zu veraendern. (Die separate Nachweis-PWA unter /mobile bleibt unberuehrt.)
   ============================================================================================ */

/* Tablet und schmaler: Kopfzeile darf umbrechen statt horizontal zu ueberlaufen. */
@media (max-width: 900px) {
    header { flex-wrap: wrap; padding: 10px 14px; gap: 8px 12px; }
    header > div:last-child { flex-wrap: wrap; gap: 8px 10px; justify-content: flex-start; }
    .phase-nav { order: 6; width: 100%; }
    main { margin: 18px auto; padding: 0 12px; }
    /* groessere Touch-Ziele */
    .topnav-changes { padding: 8px 12px; }
    .lang-switch .lang-opt { padding: 8px 11px; }
}

/* Breite Tabellen (Listen + Dokument-Matrix) auf schmalen Screens horizontal scrollbar machen,
   statt sie abzuschneiden. block+overflow verwandelt die Tabelle in einen Scroll-Container. */
@media (max-width: 768px) {
    .list-table, .matrix-table {
        display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    .doc-tree-svg { min-width: 520px; }
}

/* Handy: kompaktere Kopfzeile, volle Breite fuer Suche, groessere Tap-Flaechen. */
@media (max-width: 560px) {
    header { padding: 10px 12px; }
    header .header-left { width: 100%; }
    header > div:last-child { width: 100%; gap: 8px; }
    header form[action$="global_search"], header form[action*="global_search"] { flex: 1 1 100%; }
    header form[action*="global_search"] input { width: 100% !important; }
    header select[name="model"] { max-width: 100%; }
    .button, button { padding: 10px 16px; }
    h1 { font-size: 19px; }
    .page-section-title { margin-top: 20px; }
    /* Formular-Eingaben in iOS nicht zoomen lassen (>=16px) */
    .form-box input, .form-box select, .form-box textarea { font-size: 16px; }
}

/* ============================================================================================
   Zugaenglichkeit & Politur (Schritt 6). Bewusst KEIN Dark Mode: die Oberflaeche enthaelt ~350
   fest verdrahtete Inline-Farben in ~29 Templates; ein reines Token-Remapping wuerde gemischte,
   kaputte Hell/Dunkel-Seiten erzeugen. Ein sauberer Dark Mode braucht zuerst einen Farb-Token-
   Refactor (separater Schritt). Hier nur risikoarme, tokenbasierte Verbesserungen.
   ============================================================================================ */

/* Sichtbarer Tastatur-Fokus (nur bei Tastaturnavigation, nicht bei Mausklick). */
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 3px; }
a:focus-visible, button:focus-visible, .button:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* Sanftes Scrollen fuer In-Page-Anker; Reduced-Motion respektieren. */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; animation: none !important; }
}

/* Duenne, dezente Scrollleisten fuer die horizontal scrollbaren Tabellen/Diagramme –
   macht auf Trackpad/Desktop sichtbar, dass seitlich mehr Inhalt steht. */
.list-table, .matrix-table, [style*="overflow-x"] { scrollbar-width: thin; scrollbar-color: var(--steel-light) transparent; }
.list-table::-webkit-scrollbar, .matrix-table::-webkit-scrollbar,
[style*="overflow-x"]::-webkit-scrollbar { height: 8px; }
.list-table::-webkit-scrollbar-thumb, .matrix-table::-webkit-scrollbar-thumb,
[style*="overflow-x"]::-webkit-scrollbar-thumb { background: var(--steel-light); border-radius: 4px; }

/* Zeilen-Hover nur auf neutralen Zellen (semantische Statusfarben bleiben unberuehrt). */
.list-table tbody tr:hover td:not([class]) { background: var(--teal-light); }
