/* style.css - Zentrale Design-Vorgaben */

/* 1. Zentrale Farben & Schriften definieren */
:root {
    --primary-color: #0056b3;      /* Hauptfarbe (Blau) */
    --primary-hover: #003d82;      /* Button Hover-Farbe */
    --bg-color: #f4f4f9;           /* Hintergrundfarbe der Seite */
    --card-bg: #ffffff;            /* Hintergrund der Tabellen-Container */
    --text-color: #333333;         /* Hauptschriftfarbe */
    --font-family: Arial, sans-serif; /* Globale Schriftart */

    /* Weitere, bisher fest verdrahtete Farben - jetzt als Variablen, damit sie
       im Dark Mode mit umschalten */
    --search-box-bg: #e9ecef;
    --border-color: #ddd;
    --input-border: #ccc;
    --row-even-bg: #f9f9f9;
    --row-hover-bg: #f1f1f1;
    --card-border: #b8daff;
    --subtitle-color: #6c757d;

    /* Farben für die Halt-Typ Badges */
    --badge-x: #dc3545;            /* Betriebshalt (Rot) */
    --badge-l: #fd7e14;            /* Personalwechsel (Orange) */
    --badge-d: #6f42c1;            /* Durchfahrt (Violett) */
    --badge-a: #28a745;            /* Ankunft (Grün) */
}

/* 1b. Dark Mode - wird per JS (darkmode.js) als Klasse auf <html> gesetzt */
html.dark-mode {
    --primary-color: #4a9eff;
    --primary-hover: #6fb4ff;
    --bg-color: #1a1d23;
    --card-bg: #262a33;
    --text-color: #e4e6eb;

    --search-box-bg: #2f333d;
    --border-color: #3a4150;
    --input-border: #4a5164;
    --row-even-bg: #2a2e37;
    --row-hover-bg: #343a46;
    --card-border: #3a4150;
    --subtitle-color: #9aa3b0;

    /* Badges im Dark Mode etwas aufgehellt, damit sie auf dunklem Grund genug
       Kontrast behalten */
    --badge-x: #e35d6a;
    --badge-l: #ff9f43;
    --badge-d: #9a6fe0;
    --badge-a: #3ecf6c;
}

html, body {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* 2. Allgemeine Styles */
body { 
    font-family: var(--font-family); 
    background: var(--bg-color); 
    padding: 20px; 
    color: var(--text-color); 
}

.container { 
    max-width: 1400px; 
    margin: 0 auto; 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: 8px; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.1); 
}

h1, h2 { 
    color: var(--primary-color); 
}

/* Formular & Suche */
.search-box { 
    background: var(--search-box-bg); 
    padding: 20px; 
    border-radius: 5px; 
    margin-bottom: 20px; 
}

.search-input, input[type="text"] { 
    padding: 10px 15px; 
    font-size: 16px; 
    width: 350px; 
    border: 1px solid var(--input-border); 
    border-radius: 4px; 
    outline: none; 
    background: var(--card-bg);
    color: var(--text-color);
}

.search-input:focus, input[type="text"]:focus { 
    border-color: var(--primary-color); 
    box-shadow: 0 0 5px rgba(0, 86, 179, 0.3); 
}

button { 
    padding: 10px 20px; 
    font-size: 16px; 
    background: var(--primary-color); 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
}

button:hover { 
    background: var(--primary-hover); 
}

/* Tabellen-Styling */
table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 15px; 
    font-size: 14px; 
}

th, td { 
    padding: 10px; 
    text-align: left; 
    border-bottom: 1px solid var(--border-color); 
}

th { 
    background: var(--primary-color); 
    color: white; 
}

tr:nth-child(even) { 
    background: var(--row-even-bg); 
}

tr:hover { 
    background: var(--row-hover-bg); 
}

.text-center { 
    text-align: center; 
}

a.zug-link { 
    color: var(--primary-color); 
    text-decoration: none; 
    font-weight: bold; 
}

a.zug-link:hover { 
    text-decoration: underline; 
}

/* Badges für Halt-Typen */
.badge { 
    display: inline-block; 
    padding: 3px 7px; 
    border-radius: 3px; 
    font-size: 11px; 
    font-weight: bold; 
    color: #fff; 
}

.badge-default { background: #6c757d; }
.badge-X { background: var(--badge-x); }
.badge-L { background: var(--badge-l); }
.badge-D { background: var(--badge-d); }
.badge-A { background: var(--badge-a); }

/* ============================================= */
/* Schiebeschalter (gemeinsames Design für Dark Mode, Umleiter anzeigen und
   DEV-Modus - Ein-/Ausschaltlogik in darkmode.js bzw. der jeweiligen Seite) */
/* ============================================= */
.toggle-item { display: flex; align-items: center; }
.toggle-label { font-size: 13px; color: var(--text-color); margin-right: 8px; white-space: nowrap; }

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    vertical-align: middle;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider {
    position: absolute; cursor: pointer; inset: 0;
    background-color: #ccc;
    border-radius: 24px;
    transition: 0.2s;
}
.toggle-switch .slider::before {
    position: absolute; content: "";
    height: 18px; width: 18px; left: 3px; bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.2s;
}
.toggle-switch input:checked + .slider { background-color: var(--primary-color); }
.toggle-switch input:checked + .slider::before { transform: translateX(20px); }

/* ============================================= */
/* Login-/Benutzer-Leiste: Startseite ganz links, Schiebeschalter (Dark Mode,
   Umleiter anzeigen, DEV-Modus) mittig, "Eingeloggt als X | Verwaltung |
   Abmelden" bzw. "Login"-Button ganz rechts - alles in einer Reihe,
   gemeinsames Muster für mehrere Seiten */
/* ============================================= */
.top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 16px;
    padding: 15px 25px;
    font-size: 14px;
}
.top-bar a { text-decoration: none; }
.top-bar-left { justify-self: start; display: flex; align-items: center; }
.top-bar-center { justify-self: center; display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.top-bar-right { justify-self: end; display: flex; align-items: center; }

.btn-login {
    background: var(--primary-color);
    color: white;
    padding: 7px 16px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 13px;
}
.btn-login:hover { background: var(--primary-hover); }

.user-info { font-size: 14px; color: var(--text-color); }

.btn-logout {
    background: #dc3545; color: white; text-decoration: none;
    padding: 7px 14px; border-radius: 4px; font-size: 13px; font-weight: bold;
    margin-left: 8px;
}
.btn-logout:hover { background: #bd2130; }

.btn-admin {
    background: #6c757d; color: white; text-decoration: none;
    padding: 7px 14px; border-radius: 4px; font-size: 13px;
    margin-left: 8px;
}
.btn-admin:hover { background: #5a6268; }

/* ============================================= */
/* DEV-Modus / Steuerbezirk-Spalten umschalten (abfrage.php, bfo.php) */
/* ============================================= */
.btn-dev {
    background-color: #dc3545; color: white; border: none;
    padding: 4px 10px; font-size: 12px; font-weight: bold; border-radius: 4px;
    cursor: pointer; margin-left: 12px; vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.btn-dev:hover { background-color: #bd2130; }

.btn-sb {
    background-color: var(--primary-color); color: white; border: none;
    padding: 4px 10px; font-size: 12px; font-weight: bold; border-radius: 4px;
    cursor: pointer; margin-left: 6px; vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.btn-sb:hover { background-color: var(--primary-hover); }

.dev-col { display: none; }
body.show-dev .dev-col { display: table-cell; }

.dev-bulk-bar { display: none; margin-bottom: 10px; }
body.show-dev .dev-bulk-bar { display: block; }
.btn-dev-bulk {
    background-color: #dc3545; color: white; border: none;
    padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 14px;
}
.btn-dev-bulk:hover { background-color: #bd2130; }

.btn-analyse {
    display: inline-block; background-color: #6f42c1; color: white; text-decoration: none;
    padding: 8px 16px; border-radius: 4px; font-weight: bold; font-size: 14px; vertical-align: middle;
}

/* Verkleinerte Variante für den Einsatz in der Kopfzeile (top-bar-center),
   damit die Größe zu den übrigen Buttons dort passt (abfrage.php) */
.btn-top-action {
    padding: 7px 14px !important;
    font-size: 13px !important;
}
.btn-analyse:hover { background-color: #59339d; }

.sb-col { display: none; }
body.show-sb .sb-col { display: table-cell; }

/* ============================================= */
/* Zugnummer-Autocomplete (abfrage.php, analyse.php) */
/* ============================================= */
.search-box form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-box label { width: 100%; margin-bottom: 5px; }

.autocomplete-wrapper { position: relative; width: 180px; }
.autocomplete-wrapper input { width: 100%; box-sizing: border-box; padding: 6px 10px; height: 38px; }
.search-box button { height: 38px; white-space: nowrap; }

.autocomplete-results {
    position: absolute; top: 100%; left: 0; width: 260px;
    background: var(--card-bg); border: 1px solid var(--primary-color); border-top: none;
    border-radius: 0 0 6px 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000; max-height: 280px; overflow-y: auto; display: none;
}
.autocomplete-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border-color); text-align: left; }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.selected { background-color: var(--row-hover-bg); }
.autocomplete-item .train-title { font-weight: bold; color: var(--primary-color); font-size: 14px; }
.autocomplete-item .train-route { font-size: 12px; color: var(--subtitle-color); margin-top: 2px; }

/* ============================================= */
/* örtliche Anweisung: Button, Badge, Popup-Modal (abfrage.php, bfo.php) */
/* ============================================= */
.btn-oeano {
    background: #cfe2ff; color: #084298; border: 1px solid #9ec5fe;
    padding: 2px 7px; border-radius: 4px; font-size: 12px; font-weight: bold;
    cursor: pointer; display: inline-block; margin-right: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    vertical-align: middle;
}
.btn-oeano:hover { background: #b6d4fe; }

.badge-lpw {
    background: #d1e7dd; color: #0f5132; border: 1px solid #a3cfbb;
    padding: 2px 7px; border-radius: 4px; font-size: 12px; font-weight: bold;
    display: inline-block; cursor: default; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    vertical-align: middle;
}

dialog#anweisungModal { border: none; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.4); padding: 0; max-width: 650px; width: 90%; margin: auto; background: var(--card-bg); color: var(--text-color); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-header { background: var(--primary-color); color: white; padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; color: white; font-size: 24px; font-weight: bold; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; font-family: monospace; font-size: 13px; white-space: pre-wrap; background: var(--card-bg); max-height: 70vh; overflow-y: auto; color: var(--text-color); }
.modal-body a.zug-link { color: var(--primary-color); font-weight: bold; text-decoration: underline; }
.modal-body a.zug-link:hover { color: var(--primary-hover); background-color: var(--row-hover-bg); }

/* ============================================= */
/* Gattungs-Badge (abfrage.php, bfo.php, analyse.php) */
/* ============================================= */
.badge-gattung {
    display: inline-block; padding: 2px 7px; border-radius: 4px; font-weight: bold;
    text-align: center; min-width: 36px; box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    box-sizing: border-box; vertical-align: middle; line-height: 1;
}
.badge-gattung-default { background-color: #6c757d; color: #ffffff; }

/* ============================================= */
/* Alert-/Hinweisboxen (viele Seiten) */
/* ============================================= */
.alert-success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.alert-warning { background-color: #fff3cd; color: #856404; border: 1px solid #ffeba8; padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.alert-info { background-color: #cfe2ff; color: #084298; border: 1px solid #9ec5fe; padding: 10px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
html.dark-mode .alert-success { background-color: #16301f; color: #8fd4a6; border-color: #1f5132; }
html.dark-mode .alert-warning { background-color: #3a2f0a; color: #ffd873; border-color: #5c4a10; }
html.dark-mode .alert-info { background-color: #0d2a4a; color: #9ec5fe; border-color: #134272; }

.region-link { display: inline-block; background: #856404; color: white; text-decoration: none; padding: 3px 10px; border-radius: 4px; font-size: 13px; font-weight: bold; margin-left: 6px; }
.region-link:hover { background: #6b5003; }

.station-bfo-link { color: var(--primary-color); text-decoration: underline; font-weight: normal; }
.station-bfo-link:hover { color: var(--primary-hover); background-color: var(--row-hover-bg); border-radius: 3px; }

/* Hervorgehobene Tabellenzeile (z.B. angesprungener Zug in bfo.php) */
.highlight-row td {
    background-color: #fff8d6 !important;
    border-top: 1px solid #ffe885 !important;
    border-bottom: 1px solid #ffe885 !important;
}
.highlight-row:hover td { background-color: #ffecb3 !important; }
html.dark-mode .highlight-row td {
    background-color: #4a3f0a !important;
    border-top: 1px solid #6b5a10 !important;
    border-bottom: 1px solid #6b5a10 !important;
}
html.dark-mode .highlight-row:hover td { background-color: #5c4a10 !important; }

/* Kleine, hervorgehobene Box innerhalb einer Alert-Box (z.B. "Zweiter Zuglauf
   gefunden"-Vorschau in abfrage.php/analyse.php) */
.nested-highlight-box {
    margin-top: 8px; padding: 8px 10px;
    background: #fffbe8; border: 1px dashed #e0c460; border-radius: 4px;
}
html.dark-mode .nested-highlight-box {
    background: #2b2408; border-color: #5c4a10;
}
/* ============================================= */
/* Gemeinsame Kopfleiste (header.php): Zahnrad-Einstellungsmenü */
/* ============================================= */
.top-bar-v2 { display: flex; justify-content: space-between; align-items: center; }
.top-bar-v2 .top-bar-right { gap: 8px; }
.top-bar-v2 .btn-admin, .top-bar-v2 .btn-login { margin-left: 0; }
.btn-dev-top {
    background: #dc3545; color: white; border: none; cursor: pointer;
    padding: 7px 14px; border-radius: 4px; font-size: 13px; font-weight: bold;
}
.btn-dev-top:hover { background: #bd2130; }
.btn-dev-top.active { background: #7a0f1a; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.settings-wrap { position: relative; }
.btn-gear {
    background: #6c757d; color: white; border: none; cursor: pointer;
    width: 34px; height: 32px; border-radius: 4px; font-size: 19px; line-height: 1; padding: 0;
}
.btn-gear:hover { background: #5a6268; }
.settings-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 1000;
    min-width: 260px; padding: 8px 0;
    background: var(--card-bg, #fff); color: var(--text-color);
    border: 1px solid var(--border-color, #ccc); border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.settings-menu[hidden] { display: none; }
.settings-user { padding: 6px 14px 8px; font-size: 13px; border-bottom: 1px solid var(--border-color, #ddd); margin-bottom: 4px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 7px 14px; }
.settings-row .toggle-label { margin-right: 0; }
.settings-row-jahr .jahr-wahl { margin: 0 !important; flex-wrap: wrap; }
.settings-logout {
    display: block; margin: 6px 14px 4px; padding: 7px 14px; text-align: center;
    background: #dc3545; color: white; border-radius: 4px; font-size: 13px; font-weight: bold;
}
.settings-logout:hover { background: #bd2130; }

/* Beschädigte Zeichen (U+FFFD) deutlich hervorheben */
.defekt { background: #dc3545; color: #fff; font-weight: bold; padding: 0 3px; border-radius: 3px; box-shadow: 0 0 0 1px #7a0f1a; }
td.zeichen-defekt, .korr-btn.zeichen-defekt { background: #ffd0cc !important; outline: 2px solid #dc3545; }
html.dark-mode td.zeichen-defekt, html.dark-mode .korr-btn.zeichen-defekt { background: #5a1f1c !important; }

/* Fahrplanjahr-Auswahl direkt an Zug bzw. Bahnhof (abfrage.php / bfo.php); jedes Jahr hat über --jh (Farbton) seine eigene Farbe */
.jahr-btn, .jahr-chip, .jahr-tag { --jh: 210; --jc: hsl(var(--jh) 68% 38%); }
html.dark-mode .jahr-btn, html.dark-mode .jahr-chip, html.dark-mode .jahr-tag { --jc: hsl(var(--jh) 72% 66%); }
.jahr-leiste { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 16px; font-size: 14px; }
.jahr-btn { display: inline-block; padding: 4px 14px; border: 2px solid var(--jc); border-radius: 16px; text-decoration: none; color: var(--jc); background: var(--card-bg); font-weight: bold; }
.jahr-btn:hover { background: var(--row-hover-bg); }
.jahr-btn.aktiv { background: var(--jc); color: #fff; }
html.dark-mode .jahr-btn.aktiv { color: #111; }
.jahr-tag { display: inline-block; padding: 2px 12px; border-radius: 12px; background: var(--jc); color: #fff; font-weight: bold; }
html.dark-mode .jahr-tag { color: #111; }
.ergebnis-tabelle { width: 100%; border-collapse: collapse; margin: 10px 0 20px; background: var(--card-bg); }
.ergebnis-tabelle th, .ergebnis-tabelle td { padding: 8px 12px; border-bottom: 1px solid var(--border-color); text-align: left; }
.ergebnis-tabelle tr:hover td { background: var(--row-hover-bg); }
.ergebnis-tabelle tr.jahr-zeile td:first-child { border-left: 6px solid var(--jc, #888); }
.ergebnis-tabelle tr.jahr-zeile { --jh: 210; --jc: hsl(var(--jh) 68% 38%); }
html.dark-mode .ergebnis-tabelle tr.jahr-zeile { --jc: hsl(var(--jh) 72% 66%); }
.autocomplete-item .jahr-chip { display: inline-block; font-size: 11px; font-weight: bold; padding: 1px 8px; margin-left: 8px; border-radius: 10px; background: var(--jc); color: #fff; }
html.dark-mode .autocomplete-item .jahr-chip { color: #111; }