/*
 * BFT Fahrten Management System — Haupt-Stylesheet
 * =================================================
 * Autor:    Balz Heusler / Oz AI Agent
 * Zuletzt aktualisiert: April 2026
 *
 * INHALTSVERZEICHNIS
 * ------------------
 *  1.  Reset & CSS-Variablen
 *  2.  App-Shell Layout  (shell.html)
 *  3.  Login-Seite       (login_form.html)
 *  4.  Adressfelder      (generic_form.py)
 *  5.  Dashboard-Uebersicht (dashboard_content.html)
 *  6.  Dashboard-Kacheln    (dashboard_module.html)
 *  7.  Statistik-Karten
 *  8.  Datentabellen     (generic_list.py)
 *  9.  Nachrichten / Alerts
 * 10.  Modale Dialoge    (generic_form.py / content.py)
 * 11.  Buttons (Standard)
 * 12.  Buttons (Klein, fuer Tabellen)
 * 13.  Badges & Status-Anzeigen
 * 14.  Links
 * 15.  Formulare (generisch)
 * 16.  Tabs
 * 17.  Info-Grid
 * 18.  Code-Block
 * 19.  Flash-Nachrichten (Toasts)
 * 20.  Debug-Info
 * 21.  Fehlerseite
 * 22.  Responsive
 *
 * FARBKONZEPT
 * -----------
 * Alle Farben und Abstaende als CSS-Variablen in :root.
 * Aenderung an einer zentralen Stelle wirkt ueberall.
 *
 * KACHEL-GROESSEN
 * ---------------
 * Standardwerte in :root (--kachel-*).
 * Rollen-spezifische Werte via <style>:root{--kachel-*:...}</style>
 * in dashboard_module.html (aus DB-Tabelle rollen).
 *
 * INLINE-STYLES
 * -------------
 * Ziel: keine inline styles in Python/HTML.
 * Noch verbleibende inline styles in content.py sind
 * dynamische f-string Werte (z.B. Farben aus DB) die
 * nicht durch CSS-Klassen ersetzt werden koennen.
 */


/* ============================================================
   1. RESET & CSS-VARIABLEN
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* --- Design-System Farben --- */
    --primary-color:   #2563eb;
    --primary-hover:   #1d4ed8;
    --secondary-color: #64748b;
    --success-color:   #10b981;
    --error-color:     #ef4444;
    --warning-color:   #f59e0b;
    --info-color:      #3b82f6;

    /* --- Hintergruende & Oberflaechen --- */
    --bg-color:      #f8fafc;
    --surface-color: #ffffff;

    /* --- Texte & Rahmen --- */
    --text-color:     #1e293b;
    --text-secondary: #64748b;
    --border-color:   #e2e8f0;

    /* --- Schatten --- */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);

    /* --- App-Shell Farben (shell.html) --- */
    --header-bg:          #ffe0e0;   /* Roetlicher Hintergrund im App-Header */
    --header-title-color: #dc143c;   /* Crimson-Rot fuer den App-Titel */
    --user-info-bg:       #fff9c4;   /* Gelber Hintergrund fuer das User-Info-Panel */
    --user-info-border:   #ffeb3b;

    /* --- Dashboard-Kacheln ---
       Standardwerte. Rollen-spezifische Ueberschreibungen via
       <style>:root{--kachel-breite: Xpx; ...}</style> in dashboard_module.html.
       Die Werte kommen aus DB-Tabelle 'rollen' (dashboard_kachel_* Felder).
    */
    --kachel-breite:              200px;
    --kachel-hoehe:               150px;
    --kachel-abstand:              16px;  /* Horizontaler Abstand zwischen Kacheln */
    --kachel-abstand-vertikal:     16px;  /* Vertikaler Abstand zwischen Zeilen */
    --kachel-icon-groesse:         40px;
    --kachel-titel-groesse:        16px;
    --kachel-beschreibung-groesse: 12px;
    --kachel-bg:            white;
    --kachel-border:        #dee2e6;
    --kachel-border-radius: 8px;

    /* --- Formular-Ueberlagerung ---
       Abstand vom oberen Rand fuer modale Formulare.
       Wird in shell.html ueberschrieben wenn
       system_einstellungen.Form-px-from-top gesetzt ist.
    */
    --form-top-offset: 56px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}


/* ============================================================
   2. APP-SHELL LAYOUT (shell.html)
   Drei-Zonen-Layout: Header -> #main-content -> Footer
   ============================================================ */

/* svh = small viewport height — behebt 100vh-Bug auf Android (Browser-Adressleiste) */
html, body { height: 100svh; overflow: hidden; }
body { display: flex; flex-direction: column; }

/* Header */
.app-header {
    background: var(--header-bg);
    color: #333;
    padding: 0.75rem 1.5rem;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}
/* 3-Spalten-Layout: Links=Logo/Titel, Mitte=Dashboard, Rechts=Login
   Jeder Bereich bekommt flex:1 damit Mitte wirklich zentriert ist */
.header-left   { display: flex; align-items: center; gap: 1rem; flex: 1; }
.header-center { display: flex; align-items: center; justify-content: center; gap: 0.75rem; flex: 1; }
.header-right  { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; flex: 1; }
.logo-link    { display: block; }
.app-logo     { height: 45px; cursor: pointer; transition: transform 0.2s; }
.app-logo:hover { transform: scale(1.05); }
.app-title    { font-size: 1.3rem; font-weight: 600; margin: 0; color: var(--header-title-color); }

/* User-Info Panel (oben rechts, nach Login sichtbar) */
.user-info {
    display: none; /* Wird per .active durch JavaScript eingeblendet */
    flex-direction: column; gap: 0.35rem;
    background: var(--user-info-bg);
    padding: 0.75rem 0.75rem 0.5rem;
    border-radius: 8px; border: 1px solid var(--user-info-border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative; margin-top: -3px;
}
.user-info.active { display: flex; }
.user-info-label  { font-size: 0.6rem; color: #999; font-weight: 400; margin-bottom: 0.15rem; }
.user-info-row    { display: flex; align-items: center; gap: 0.75rem; }

/* Haupt-Inhalt-Bereich (via HTMX dynamisch befuellt) */
#main-content {
    flex: 1; padding: 0;
    max-width: 100%; width: 100%; margin: 0;
    overflow-y: auto; min-height: 0;
}

/* Lade-Indikator: Inhalt wird waehrend HTMX-Request leicht ausgeblendet */
.htmx-request #main-content { opacity: 0.6; pointer-events: none; }

/* Footer */
/* Footer: 3-Spalten-Layout, spiegelt Header-Struktur */
.app-footer {
    background: #f8f9fa; padding: 0.4rem 1.5rem; color: #6c757d;
    border-top: 1px solid #dee2e6; flex-shrink: 0;
    display: flex; align-items: center;
}
.app-footer p  { margin: 0; font-size: 0.8rem; }
.footer-left   { display: flex; align-items: center; flex: 1; }
.footer-center { display: flex; align-items: center; justify-content: center; flex: 1; }
.footer-right  { display: flex; align-items: center; justify-content: flex-end; flex: 1; }


/* ============================================================
   3. LOGIN-SEITE (partials/login_form.html)
   ============================================================ */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%); }
.login-container { width: 100%; max-width: 400px; padding: 2rem; }
.login-box       { background: white; padding: 2rem; border-radius: 0.5rem; box-shadow: var(--shadow-lg); }
.login-header    { text-align: center; margin-bottom: 2rem; }
.login-header h1 { color: var(--primary-color); font-size: 1.75rem; margin-bottom: 0.5rem; }
.login-header p  { color: var(--text-secondary); font-size: 0.875rem; }
.login-form      { display: flex; flex-direction: column; gap: 1rem; }
.login-footer    { text-align: center; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border-color); }
.login-footer p  { color: var(--text-secondary); font-size: 0.75rem; }

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-weight: 500; font-size: 0.875rem; color: var(--text-color); }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group select,
.form-group textarea {
    padding: 0.625rem; border: 1px solid var(--border-color);
    border-radius: 0.375rem; font-size: 0.875rem; transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none; border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.checkbox-label         { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.password-input-wrapper { position: relative; display: flex; align-items: center; }
.password-input-wrapper input { padding-right: 2.5rem; width: 100%; }
.password-toggle {
    position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; padding: 0.25rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; opacity: 0.6; transition: opacity 0.2s;
}
.password-toggle:hover { opacity: 1; }
.password-toggle:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; border-radius: 0.25rem; }


/* ============================================================
   4. ADRESSFELDER (generic_form.py -> address_standard Layout)
   Spezielle Grid-Layouts fuer Schweizer Adressen
   ============================================================ */
.address-layout       { display: flex; flex-direction: column; gap: 0.4rem; }
.address-row          { display: grid; gap: 0.4rem; }
.address-row-full     { grid-template-columns: 1fr; }
.address-row-street   { grid-template-columns: 8fr 1fr; }
.address-row-street > div:last-child label { text-align: right; white-space: nowrap; }
.address-row-street > div:last-child input { text-align: right; }
.address-row-location { grid-template-columns: 1.5fr 1.5fr 7fr; }

/* === Google Places Autocomplete (bft-google-places.js) === */
.gp-search-wrapper {
    position: relative;
    margin-bottom: 0.6rem;
}
.gp-search-input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 1.8rem;
    border: 1px solid #007bff;
    border-radius: 4px;
    font-size: 0.875rem;
    background: #f0f8ff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='%23007bff'%3E%3Cpath d='M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5S10.62 6.5 12 6.5s2.5 1.12 2.5 2.5S13.38 11.5 12 11.5z'/%3E%3C/svg%3E") no-repeat 0.4rem center;
}
.gp-search-input:focus { outline: none; border-color: #0056b3; }
.gp-dropdown {
    position: absolute;
    z-index: 2000;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
    display: none;
}
.gp-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gp-option--hover, .gp-option:hover { background: #e8f0fe; }

/* === PLZ / Land Autocomplete Dropdowns (bft-address.js) === */
.plz-option, .land-option {
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.8rem;
    background: white;
}
.plz-option--hover, .land-option--hover,
.plz-option:hover, .land-option:hover { background: #f0f8ff; }
.plz-logik-badge { color: #28a745; font-size: 0.7rem; margin-left: 0.4rem; }

/* Autocomplete-Container Basisstil */
[id*="-autocomplete"] {
    position: absolute;
    z-index: 1000;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    display: none;
}

/* Laender-Dropdown: Nur ISO-Code in geschlossenem Zustand, voller Text in Optionen */
select[name="land"] { text-align: center; font-weight: 500; }
select[name="land"] option { text-align: left; padding: 0.5rem; font-weight: normal; }
select[name="land"]:focus option,
select[name="land"][size] option { min-width: 250px; }


/* ============================================================
   5. DASHBOARD-UEBERSICHT (partials/dashboard_content.html)
   Kompakte Kacheln fuer den Admin-Bereich (feste Groesse)
   ============================================================ */

/* Grid-Container; Spaltenanzahl wird inline gesetzt (z.B. repeat(5,1fr)) */
.table-buttons-grid { display: grid; gap: 0.75rem; }

/* Kompakte Kachel (Admin-Dashboard) */
.table-button {
    background: white; border: 2px solid #dee2e6;
    border-radius: 6px; padding: 0.75rem 0.5rem;
    text-align: center; cursor: pointer; transition: all 0.3s;
}
.table-button .button-icon { font-size: 2.2rem; margin-bottom: 0.35rem; }
.table-button h4           { color: #1e3c72; margin: 0; font-size: 0.85rem; line-height: 1.2; }
.table-button:hover        { border-color: #2a5298; box-shadow: 0 4px 12px rgba(42,82,152,0.15); transform: translateY(-2px); }
.table-button:active       { transform: translateY(0); }

/* Abschnitt-Container (um Gruppen von Inhalten) */
.admin-section       { background: var(--surface-color); border-radius: 1rem; padding: 2rem; box-shadow: var(--shadow-md); }
.section-title       { font-size: 2rem; font-weight: 700; color: var(--text-color); margin-bottom: 0.5rem; }
.section-description { color: var(--text-secondary); font-size: 1rem; margin-bottom: 2rem; }

/* Benutzerinformations-Karte */
.user-info-container { background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%); border-radius: 1rem; padding: 2rem; box-shadow: var(--shadow-lg); color: white; }
.user-info-header    { display: flex; align-items: center; gap: 1.5rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid rgba(255,255,255,0.2); }
.user-avatar         { width: 80px; height: 80px; background: rgba(255,255,255,0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; backdrop-filter: blur(10px); border: 3px solid rgba(255,255,255,0.3); }
.avatar-initials     { text-transform: uppercase; }
.user-details        { flex: 1; }
.user-name           { font-size: 1.75rem; font-weight: 700; margin: 0 0 0.25rem 0; }
.user-role           { font-size: 1rem; opacity: 0.9; margin: 0; font-weight: 500; }
.user-info-grid      { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; }
.info-item           { display: flex; flex-direction: column; gap: 0.5rem; }
.info-label          { font-size: 0.875rem; opacity: 0.8; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.info-value          { font-size: 1.125rem; font-weight: 600; }
.status-badge        { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 0.375rem; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.status-active       { background: rgba(16,185,129,0.2); color: white; border: 1px solid rgba(255,255,255,0.3); }
.button-content      { flex: 1; }
.button-content h3   { font-size: 1.25rem; font-weight: 700; color: var(--text-color); margin: 0 0 0.25rem 0; }
.button-content p    { font-size: 0.875rem; color: var(--text-secondary); margin: 0; }


/* ============================================================
   6. DASHBOARD-KACHELN (partials/dashboard_module.html)
   Groessen ueber CSS-Variablen gesteuert.
   Rollen-spezifische Werte ueberschreiben :root-Defaults via
   <style>:root{--kachel-breite:Xpx;...}</style> im Template.
   ============================================================ */

/* Scrollbarer Wrapper fuer das Kachel-Grid */
.dashboard-scroll    { height: 100%; overflow-y: auto; padding: 1.5rem; }
.dashboard-container { display: flex; flex-direction: column; padding: 0; margin: 0; }

/* Zeile mit Kacheln (Abstand aus CSS-Variable) */
.dashboard-row { display: flex; gap: var(--kachel-abstand); flex-wrap: wrap; margin-bottom: var(--kachel-abstand-vertikal); }

/* Kachel (aktiv) - alle Groessen aus CSS-Variablen */
.dashboard-kachel {
    background: var(--kachel-bg);
    border: 2px solid var(--kachel-border);
    border-radius: var(--kachel-border-radius);
    padding: 1.5rem; cursor: pointer; transition: all 0.3s;
    width: var(--kachel-breite); height: var(--kachel-hoehe);
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0; gap: 0.75rem; position: relative;
}
.dashboard-kachel:hover  { border-color: #2a5298; box-shadow: 0 6px 16px rgba(42,82,152,0.2); transform: translateY(-4px); }
.dashboard-kachel:active { transform: translateY(-2px); }

/* Leerer Platzhalter (Modul K00 = Abstandshalter) */
.dashboard-kachel-empty {
    background: transparent; border: 2px dashed #e9ecef;
    border-radius: var(--kachel-border-radius);
    width: var(--kachel-breite); height: var(--kachel-hoehe);
    flex-shrink: 0;
}

/* Icon-Position (Klasse aus rolle.dashboard_icon_position gesetzt) */
.kachel-icon-top    { flex-direction: column; text-align: center; }
.kachel-icon-bottom { flex-direction: column-reverse; text-align: center; }
.kachel-icon-left   { flex-direction: row; text-align: left; }
.kachel-icon-right  { flex-direction: row-reverse; text-align: left; }

/* Kachel-Inhalte (Groessen aus CSS-Variablen) */
.kachel-icon        { font-size: var(--kachel-icon-groesse); line-height: 1; transition: transform 0.3s; }
.kachel-icon img    { width: var(--kachel-icon-groesse); height: var(--kachel-icon-groesse); object-fit: contain; display: block; }
.kachel-title       { color: #1e3c72; margin: 0 0 0.25rem 0; font-size: var(--kachel-titel-groesse); font-weight: 600; line-height: 1.3; }
.kachel-description { color: #6c757d; font-size: var(--kachel-beschreibung-groesse); margin: 0; line-height: 1.2; }
.kachel-text        { display: flex; flex-direction: column; justify-content: center; }
.kachel-empty-text  { text-align: center; padding: 3rem; background: #f8f9fa; border-radius: 8px; border: 2px dashed #dee2e6; }
.kachel-modul-id    { position: absolute; top: 0.25rem; left: 0.5rem; font-size: 0.65rem; color: #adb5bd; font-weight: 400; }

/* Hover-Animation auf Icon */
.dashboard-kachel:hover .kachel-icon { transform: scale(1.1); }


/* ============================================================
   7. STATISTIK-KARTEN (partials/dashboard_fahrer.html etc.)
   ============================================================ */
.stats-grid   { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.stat-card    { background: var(--surface-color); padding: 1.5rem; border-radius: 0.75rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); display: flex; align-items: center; gap: 1rem; transition: all 0.3s ease; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.stat-icon    { font-size: 2.5rem; opacity: 0.8; }
.stat-content { flex: 1; }
.stat-card h3 { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.5rem; font-weight: 500; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--primary-color); }


/* ============================================================
   8. DATENTABELLEN (generic_list.py)
   Verwendung: <table class="data-table">
   .td-actions = Aktions-Spalte (Bearbeiten/Loeschen)
   ============================================================ */
.data-table          { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); font-size: 0.9rem; }
.data-table thead    { position: sticky; top: 0; background: #f8f9fa; z-index: 10; }
.data-table th       { padding: 0.75rem; text-align: left; border-bottom: 2px solid #dee2e6; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table td       { padding: 0.6rem; border-bottom: 1px solid #dee2e6; }
.data-table tr:hover { background: #f8f9fa; }
.td-actions          { padding: 0.6rem; white-space: nowrap; }
.td-actions-inner    { display: inline-flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
/* Alle Aktions-Buttons gleich gross (Desktop) */
.td-actions-inner .btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 110px;
    height: 28px;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    line-height: 1;
    text-align: center;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    box-sizing: border-box;
}

/* Aeltere Tabellen-Wrapper */
.table-container { background: var(--surface-color); border-radius: 0.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); overflow: hidden; }
.table-header    { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.table-header h3 { font-size: 1.125rem; color: var(--text-color); }


/* ============================================================
   9. NACHRICHTEN / ALERTS
   Verwendung in Python:  html += '<div class="msg-error">Fehler</div>'
   Verwendung in Jinja2:  <div class="msg-error">{{ message }}</div>
   ============================================================ */
.msg-error    { padding: 1rem; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; }
.msg-warning  { padding: 1rem; background: #fff3cd; color: #856404; border: 1px solid #ffeeba; border-radius: 4px; }
.msg-success  { padding: 1rem; background: #d4edda; color: #155724; border: 1px solid #c3e6cb; border-radius: 4px; }
.msg-info     { padding: 1rem; background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; border-radius: 4px; }
.msg-error-sm { padding: 0.5rem 0.75rem; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; font-size: 0.9rem; }


/* ============================================================
   10. MODALE DIALOGE (generic_form.py / content.py)
   .modal-overlay      = voller Bildschirm mit dunklem Hintergrund (z=1000)
   .modal-overlay-top  = Modal mit Abstand fuer sticky Header  (z=2000)
   .modal-container    = weisser Dialog-Container (max 900px)
   .modal-container-wide = breiter Dialog (max 1100px)
   .modal-close-btn    = Abbrechen-Button oben rechts
   .modal-form-name    = kleiner Titel oben links (Formular-Name)
   ============================================================ */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay-top {
    position: fixed; top: var(--form-top-offset, 0); left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.modal-container      { background: white; padding: 2rem; border-radius: 8px; max-width: 900px; width: 90%; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-container-wide { background: white; padding: 1.5rem; border-radius: 8px; max-width: 1100px; width: 95%; overflow-y: auto; position: relative; }
.modal-close-btn      { position: absolute; top: 0.5rem; right: 0.5rem; padding: 0.25rem 0.75rem; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.modal-form-name      { position: absolute; top: 0.5rem; left: 1rem; font-size: 0.75rem; color: #6c757d; }


/* ============================================================
   11. BUTTONS (Standard, normale Groesse)
   Verwendung: class="btn btn-primary"
   ============================================================ */
.btn           { padding: 0.5rem 1rem; border: none; border-radius: 0.375rem; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: all 0.2s; text-decoration: none; display: inline-block; }
.btn-primary   { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary-color); color: white; }
.btn-secondary:hover { background: #5a6268; }
.btn-success   { background: var(--success-color); color: white; }
.btn-danger    { background: var(--error-color); color: white; }
.btn-block     { width: 100%; }
.btn-logout    { padding: 0.5rem 1rem; background: var(--error-color); color: white; border: none; border-radius: 0.375rem; font-size: 0.875rem; cursor: pointer; transition: background 0.2s; }
.btn-logout:hover { background: #dc2626; }


/* ============================================================
   12. BUTTONS (Klein, fuer Tabellen-Zeilen)
   Kombinieren: class="btn-sm btn-primary-sm"
   btn-sm    = Standard-Padding (mit margin-right)
   btn-sm-md = etwas breiter (ohne margin-right)
   ============================================================ */
.btn-sm    { padding: 0.25rem 0.5rem; border: none; border-radius: 4px; cursor: pointer; font-size: 0.8rem; display: inline-block; }
.btn-sm-md { padding: 0.25rem 0.75rem; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; display: inline-block; }
.btn-primary-sm   { background: #007bff; color: white; }
.btn-secondary-sm { background: #6c757d; color: white; }
.btn-danger-sm    { background: #dc3545; color: white; }
.btn-success-sm   { background: #28a745; color: white; }
.btn-warning-sm   { background: #ffc107; color: #000; }
.btn-info-sm      { background: #17a2b8; color: white; }
.btn-primary-sm:hover   { background: #0069d9; }
.btn-secondary-sm:hover { background: #5a6268; }
.btn-danger-sm:hover    { background: #c82333; }
.btn-success-sm:hover   { background: #218838; }


/* ============================================================
   13. BADGES & STATUS-ANZEIGEN (generic_list.py)
   Verwendung: <span class="badge badge-success">Aktiv</span>
   .badge-toggle = anklickbar (Aktiv/Inaktiv umschalten via HTMX)
   ============================================================ */
.badge           { padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.75rem; color: white; display: inline-block; }
.badge-success   { background: #28a745; }
.badge-danger    { background: #dc3545; }
.badge-warning   { background: #ffc107; color: #000; }
.badge-secondary { background: #6c757d; }
.badge-toggle    { cursor: pointer; }
/* Aktions-Badges fuer Aenderungsprotokoll (CREATE / UPDATE / DELETE) */
.badge-create    { background: #28a745; color: white; }
.badge-update    { background: #007bff; color: white; }
.badge-delete    { background: #dc3545; color: white; }
.badge-insert    { background: #28a745; color: white; }

/* === Diff-Ansicht (Aenderungsprotokoll Feldvergleich) ===
   .diff-row           = Basis-Zeile (unveraendert)
   .diff-row-changed   = Zeile mit Aenderung (gelb)
   .diff-row-json      = JSON-Feld mit Aenderung (blau)
   .diff-value         = Wert-Box (alt/neu)
   .diff-value-old     = Alter Wert (hellrot)
   .diff-value-new     = Neuer Wert (hellgruen)
*/
.diff-row          { background: #f8f9fa; border: 2px solid #dee2e6; border-radius: 4px; padding: 0.75rem; }
.diff-row-changed  { background: #fff3cd; border: 2px solid #ffc107; border-radius: 4px; padding: 0.75rem; }
.diff-row-json     { background: #e3f2fd; border: 2px solid #2196f3; border-radius: 4px; padding: 0.75rem; }
.diff-field-name   { font-weight: 600; color: #495057; margin-bottom: 0.5rem; font-size: 0.95rem; }
.diff-grid         { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.diff-label        { font-size: 0.8rem; color: #6c757d; margin-bottom: 0.25rem; }
.diff-value        { padding: 0.5rem; border-radius: 3px; border: 1px solid #dee2e6; word-break: break-word; background: white; }
.diff-value-old    { background: #ffebee; }
.diff-value-new    { background: #e8f5e9; }


/* ============================================================
   14. LINKS
   Verwendung: <a class="link-primary">Text</a>
   ============================================================ */
.link-primary       { color: #007bff; text-decoration: none; font-weight: 500; cursor: pointer; }
.link-primary:hover { text-decoration: underline; }


/* ============================================================
   15. FORMULARE (generisch, generic_form.py)
   .form-input  = Standard-Input / Select / Textarea
   .form-label  = Label ueber dem Feld
   .form-field  = Wrapper-Div um Label + Input
   ============================================================ */
.form-input        { width: 100%; padding: 0.5rem; border: 1px solid #dee2e6; border-radius: 4px; font-size: 0.875rem; }
.form-input:focus  { outline: none; border-color: #2563eb; }
.form-label        { display: block; margin-bottom: 0.25rem; font-weight: 500; color: #334155; font-size: 0.875rem; }
.form-field        { margin-bottom: 0.4rem; }


/* ============================================================
   16. TABS
   Verwendung: <div class="tab-bar"><button class="tab-btn">Tab</button></div>
   Aktiver Tab: .tab-btn.active oder data-Attribut per JavaScript
   ============================================================ */
.tab-bar { border-bottom: 2px solid #dee2e6; margin-bottom: 1rem; display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tab-btn { padding: 0.5rem 0.75rem; background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; font-weight: 500; color: #495057; transition: all 0.2s; font-size: 0.9rem; margin-bottom: -2px; }
.tab-btn.active,
.tab-btn[aria-selected="true"] { color: #1e3c72; border-bottom-color: #1e3c72; }


/* ============================================================
   17. INFO-GRID (Detail-Ansicht)
   Zweispaltige Label/Wert-Tabelle
   Verwendung: <div class="info-grid"><strong>Log-ID:</strong><span>123</span>...
   ============================================================ */
.info-grid { display: grid; grid-template-columns: 150px 1fr; gap: 0.5rem; font-size: 0.9rem; color: #666; margin-bottom: 1.5rem; background: #f8f9fa; padding: 1rem; border-radius: 4px; }


/* ============================================================
   18. CODE-BLOCK
   Verwendung: <pre class="code-block">...</pre>
   ============================================================ */
.code-block { background: #f8f9fa; padding: 1rem; border-radius: 4px; overflow-x: auto; font-size: 0.85rem; font-family: 'Courier New', Courier, monospace; white-space: pre-wrap; word-wrap: break-word; }


/* ============================================================
   19. FLASH-NACHRICHTEN (Toasts, utils.py showNotification)
   Erscheinen animiert oben rechts
   ============================================================ */
.flash-messages    { position: fixed; top: 80px; right: 20px; z-index: 1000; max-width: 400px; }
.flash             { padding: 1rem; margin-bottom: 0.5rem; border-radius: 0.375rem; box-shadow: var(--shadow-lg); display: flex; justify-content: space-between; align-items: center; animation: slideIn 0.3s ease-out; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.flash-success     { background: #d1fae5; color: #065f46; border-left: 4px solid var(--success-color); }
.flash-error       { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--error-color); }
.flash-warning     { background: #fef3c7; color: #92400e; border-left: 4px solid var(--warning-color); }
.flash-info        { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--info-color); }
.flash-close       { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: inherit; opacity: 0.5; }
.flash-close:hover { opacity: 1; }


/* ============================================================
   20. DEBUG-INFO
   Sichtbarkeit server-seitig gesteuert (utils/debug.py).
   Python rendert diese Elemente NUR wenn
   system_einstellungen.debug-info = 'Ja'.
   -> Kein JavaScript-Toggle noetig!
   .debug-hint       = inline (z.B. Feldname in Label)
   .debug-hint-block = block  (z.B. Route oben links in Liste/Formular)
   ============================================================ */
.debug-hint       { color: #6c757d; font-size: 0.75rem; font-weight: 400; opacity: 0.9; margin-left: 0.5rem; display: inline; }
.debug-hint-block { color: #6c757d; font-size: 0.75rem; font-weight: 400; opacity: 0.9; margin-bottom: 0.25rem; display: block; }


/* ============================================================
   21. FEHLERSEITE (templates/error.html)
   ============================================================ */
.error-page          { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 200px); }
.error-container     { text-align: center; }
.error-container h1  { font-size: 6rem; color: var(--primary-color); margin-bottom: 1rem; }
.error-container h2  { font-size: 1.5rem; color: var(--text-color); margin-bottom: 1rem; }
.error-container p   { color: var(--text-secondary); margin-bottom: 2rem; }
.footer              { text-align: center; padding: 2rem; background: var(--surface-color); border-top: 1px solid var(--border-color); color: var(--text-secondary); font-size: 0.875rem; }


/* ============================================================
   23. FAHRTEN-FORMULAR GRID-LAYOUTS
   Desktop-Werte als CSS-Klassen – responsive Overrides in § 22.
   HTML-Struktur ist identisch auf Desktop und Smartphone:
   Nur CSS unterscheidet die Darstellung.
   ============================================================ */

/* Basisdaten: Datum | Wochentag | Uhrzeit | Status */
.bft-grid-basisdaten {
    display: grid;
    grid-template-columns: 1fr auto 1fr 1.2fr;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 1rem;
}

/* Wegpunkt-Hauptgrid: Links (Typ/Zeit/Personen) | Mitte (Adresse) | Rechts (Route) */
.bft-grid-wegpunkt {
    display: grid;
    grid-template-columns: 280px 1fr 180px;
    gap: 1rem;
}

/* Wegpunkt-Innengrid: Datum | Wochentag | Uhrzeit */
.bft-grid-wp-datetime {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.4rem;
    align-items: end;
}

/* Wegpunkt-Mittelspalte: Adresse + Ein/Aussteigen */
.bft-wp-middle-col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Wegpunkt-Spalte rechts: Google Route-Info */
.bft-wegpunkt-col3 {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Adress-Innengrid: Land | PLZ | Ort */
.bft-grid-address-lpo {
    display: grid;
    grid-template-columns: 70px 90px 1fr;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

/* Metriken: Gefahrene KM | Auslagen */
.bft-grid-metriken {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}


/* ============================================================
   22. RESPONSIVE
   Desktop: > 480px — kein einziger Desktop-Style wird veraendert
   Mobile:  ≤ 480px — Galaxy Z Flip 7 Hauptscreen Portrait ~360-390px
   Cover:   ≤ 300px — Flip 7 Cover-Screen ~260px
   ============================================================ */

/* --- Mobile-only Elemente: auf Desktop IMMER versteckt ---
   !important verhindert Override durch spaetere CSS-Regeln
   oder Inline-Styles. Nur @media (max-width:480px) hebt das auf.
   ----------------------------------------------------------- */
.mobile-header-bar  { display: none !important; }
.mobile-menu-panel  { display: none !important; }
.bottom-nav         { display: none !important; }

/* --- Bottom Navigation Basis-Styles --- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 56px; z-index: 600;
    background: var(--header-bg);
    border-top: 2px solid rgba(220,20,60,0.2);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.12);
    align-items: stretch;
}
.bottom-nav-btn {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    background: none; border: none; cursor: pointer;
    font-size: 0.6rem; font-weight: 600; color: #555;
    border-right: 1px solid rgba(0,0,0,0.08);
    min-height: 48px; padding: 0.25rem;
    transition: background 0.15s;
}
.bottom-nav-btn:last-child  { border-right: none; }
.bottom-nav-btn:active       { background: rgba(0,0,0,0.08); }
.bottom-nav-btn-icon         { font-size: 1.25rem; line-height: 1; }

/* --- Mobile Menu Drawer --- */
.mobile-menu-panel {
    position: fixed;
    top: 48px; left: 0; right: 0; /* direkt unter mobile-header-bar */
    background: var(--user-info-bg);
    border-bottom: 2px solid var(--user-info-border);
    padding: 1rem;
    z-index: 9999;
    transform: translateY(-120%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1),
                visibility 0s linear 0.25s;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    /* Wenn geschlossen: unsichtbar + nicht klickbar */
    visibility: hidden;
    pointer-events: none;
}
.mobile-menu-panel.open {
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1),
                visibility 0s linear 0s;
}
.mobile-menu-close {
    position: absolute; top: 0.5rem; right: 0.75rem;
    background: none; border: none;
    font-size: 1.4rem; cursor: pointer; color: #666;
    padding: 0.25rem;
}

/* ============================================================
   BREAKPOINT < 480px — Galaxy Z Flip 7 Hauptscreen
   ============================================================ */
@media (max-width: 480px) {

    /* --- Viewport Fix --- */
    html, body { height: 100svh; }

    /* --- Desktop-Header und Footer verstecken --- */
    .app-header { display: none !important; }
    .app-footer { display: none !important; }

    /* --- Mobile UI einblenden (ueberschreibt das desktop display:none !important) --- */
    .mobile-header-bar { display: flex !important; }
    .mobile-menu-panel { display: block !important; } /* transition aktiv */
    .bottom-nav        { display: flex !important; }

    /* --- Hauptinhalt: scrollbar + Platz fuer Bottom-Nav --- */
    #main-content {
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 60px;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Dashboard: 2-Spalten-Grid statt Flex-Rows --- */
    .dashboard-scroll { padding: 0.6rem; }
    .dashboard-container { gap: 0.5rem; }
    .dashboard-row {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
        flex: unset !important;
        margin-bottom: 0 !important;
    }
    .dashboard-kachel {
        width: 100% !important;
        height: auto !important;
        min-height: 90px !important;
        padding: 0.6rem !important;
        flex-direction: column !important;
        text-align: center !important;
    }
    .dashboard-kachel-empty { width: 100% !important; height: 90px !important; }
    .kachel-icon        { font-size: 1.6rem !important; }
    .kachel-title       { font-size: 0.72rem !important; }
    .kachel-description { font-size: 0.62rem !important; }
    .kachel-modul-id    { font-size: 0.55rem !important; }

    /* --- Login-Seite --- */
    .login-page      { padding: 0; align-items: flex-start; }
    .login-container { padding: 1rem; max-width: 100%; }
    .login-box       { padding: 1.25rem; border-radius: 8px; }
    .login-header h1 { font-size: 1.3rem; }

    /* --- Datentabellen: Expandierbare Aktionszeile --- */
    .data-table             { font-size: 0.75rem; }
    .data-table th,
    .data-table td          { padding: 0.35rem 0.4rem; }

    /* Aktionen-Spalte (Header + Zellen) ausblenden */
    .data-table thead th:last-child { display: none; }
    .data-table tbody td.td-actions { display: none; }

    /* Zeilen sind klickbar */
    .data-table tbody tr:not(.action-subrow) { cursor: pointer; }
    .data-table tbody tr.is-open             { background: #eef4ff !important; }

    /* Sub-Zeile: Buttons auf Screenbreite begrenzt (Tabelle darf breiter sein) */
    .action-subrow td {
        padding: 0.5rem 0.4rem;
        background: #eef4ff;
        border-bottom: 2px solid #c7d9f5;
    }
    .action-subrow .td-actions-inner {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        width: calc(100vw - 1.6rem);
        max-width: calc(100vw - 1.6rem);
    }
    /* Icon-Button: Emoji oben, Label unten, gleiche Grösse */
    .btn-action {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 0.5rem 0.25rem !important;
        font-size: 1.4rem !important;
        min-height: 56px;
        min-width: 0;
        border-radius: 8px !important;
        margin: 0 !important;
        box-sizing: border-box;
    }
    /* Status-Badge: gleiche Grösse wie andere Buttons im Grid */
    .btn-action.badge {
        min-height: 56px;
        font-size: 1.4rem !important;
        padding: 0.5rem 0.25rem !important;
    }
    .btn-action-label {
        font-size: 0.65rem;
        font-weight: 600;
        line-height: 1;
        letter-spacing: 0.02em;
    }

    /* --- Modale Formulare: Vollbild (Stufe 2) --- */
    .modal-overlay,
    .modal-overlay-top {
        align-items: flex-start !important;
        padding: 0 !important;
    }
    .modal-container,
    .modal-container-wide {
        width:  100vw !important;
        max-width: 100vw !important;
        height: calc(100svh - 48px) !important;
        max-height: none !important;
        border-radius: 0 !important;
        padding: 0.75rem !important;
        margin: 0 !important;
        overflow-y: auto !important;
    }

    /* --- Flash-Nachrichten nach unten (über Bottom-Nav) --- */
    .flash-messages {
        top: auto; bottom: 64px;
        left: 8px; right: 8px;
        max-width: none;
    }

    /* --- Tabs: horizontal scrollbar --- */
    .tab-bar { overflow-x: auto; flex-wrap: nowrap; }
    .tab-btn { white-space: nowrap; font-size: 0.78rem; padding: 0.35rem 0.55rem; }

    /* --- Buttons in Tabellen: Touch-freundlich --- */
    .btn-sm, .btn-sm-md { padding: 0.35rem 0.6rem; font-size: 0.75rem; }

    /* --- Fahrten-Formular: Responsive Grids (§ 23) --- */
    /* Modal: Vollbild, kein Rand */
    .bft-form-modal-inner {
        padding: 0.75rem !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
        max-height: calc(100svh - 48px) !important;
    }
    /* Basisdaten: 2-spaltig (Datum | Uhrzeit), Wochentag versteckt */
    .bft-grid-basisdaten    { grid-template-columns: 1fr 1fr; }
    #weekday-display,
    [id^="wp-weekday-"]     { display: none; }
    .bft-status-field       { grid-column: 1 / -1; }  /* Status volle Breite */
    /* Wegpunkt: alle Spalten untereinander */
    .bft-grid-wegpunkt      { grid-template-columns: 1fr; }
    /* Alle Panels gleich breit: max-width:75% der Mittelspalten-Kinder aufheben */
    .bft-wp-middle-col > * { max-width: 100% !important; width: 100% !important; }
    /* Land kürzer, PLZ kürzer → mehr Platz für Ort */
    .bft-grid-address-lpo   { grid-template-columns: 45px 70px 1fr; }
    .bft-grid-wp-datetime   { grid-template-columns: 1fr 1fr; }
    /* Metriken: einspaltig */
    .bft-grid-metriken      { grid-template-columns: 1fr; }
}

/* ============================================================
   BREAKPOINT < 300px — Galaxy Z Flip 7 Cover-Screen (~260px)
   ============================================================ */
@media (max-width: 300px) {
    /* 1-Spalte auf dem winzigen Cover-Screen */
    .dashboard-row {
        grid-template-columns: 1fr !important;
    }
    .dashboard-kachel { min-height: 72px !important; }
    .kachel-icon      { font-size: 1.3rem !important; }
}
