/* ==========================================================================
   Feuerwehr Status- und Einsatz-Logger — Design-System
   Mobile-first, Light/Dark-Theme über [data-theme], Sidebar-Shell-Layout.
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --bg-elevated: #ffffff;
    --bg-sunken: #eceef1;
    --border: #e2e5ea;
    --text: #1a1d21;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --accent-contrast: #ffffff;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;

    --status-1: #16a34a;
    --status-2: #16a34a;
    --status-3: #d97706;
    --status-4: #dc2626;
    --status-5: #2563eb;
    --status-6: #6b7280;
    --status-unknown: #9aa2ad;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 4px 12px rgba(16, 24, 40, 0.12);

    --sidebar-width: 240px;
    --sidebar-width-collapsed: 64px;
    --topbar-mobile-height: 56px;
}

:root[data-theme="dark"] {
    --bg: #0f1115;
    --bg-elevated: #181b20;
    --bg-sunken: #0b0d10;
    --border: #2a2e35;
    --text: #e8eaed;
    --text-muted: #9aa2ad;
    --accent: #3b82f6;
    --accent-contrast: #ffffff;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --status-1: #22c55e;
    --status-2: #22c55e;
    --status-3: #f59e0b;
    --status-4: #ef4444;
    --status-5: #3b82f6;
    --status-6: #6b7280;
    --status-unknown: #6b7280;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    font-size: clamp(0.875rem, 0.8rem + 0.25vw, 1rem);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
h1, h2, h3 { line-height: 1.25; font-weight: 600; }

/* ==========================================================================
   App-Shell: Sidebar + Main-Bereich
   ========================================================================== */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease, width 0.2s ease;
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}
.sidebar-brand {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-close-btn {
    display: inline-flex;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-nav a:hover { background: var(--bg-sunken); text-decoration: none; color: var(--text); }
.sidebar-nav a.active { background: var(--accent); color: var(--accent-contrast); }
.sidebar-nav .icon { flex: 0 0 auto; width: 20px; height: 20px; }
.sidebar-nav-label { overflow: hidden; text-overflow: ellipsis; }
.sidebar-divider { height: 1px; background: var(--border); margin: 8px 4px; }

.sidebar-footer {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-toggle-row { display: flex; gap: 8px; margin-top: 10px; }

.theme-toggle, .sidebar-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
}
.theme-toggle:hover, .sidebar-collapse-btn:hover { background: var(--bg-sunken); color: var(--text); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline-flex; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}
.sidebar-backdrop.open { display: block; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar-mobile {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--topbar-mobile-height);
    padding: 0 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.mobile-menu-btn {
    display: inline-flex;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}
.topbar-mobile-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 16px; flex: 1; }

@media (min-width: 1024px) {
    .sidebar { transform: translateX(0); }
    .sidebar.collapsed { width: var(--sidebar-width-collapsed); }
    .sidebar.collapsed .sidebar-brand,
    .sidebar.collapsed .sidebar-nav-label,
    .sidebar.collapsed .sidebar-user span,
    .sidebar.collapsed .sidebar-close-btn { display: none; }
    .sidebar.collapsed .sidebar-nav a { justify-content: center; }
    .app-main { margin-left: var(--sidebar-width); transition: margin-left 0.2s ease; }
    .app-main.sidebar-collapsed { margin-left: var(--sidebar-width-collapsed); }
    .topbar-mobile { display: none; }
    .content { padding: 24px 32px; }
}

@media (min-width: 1920px) {
    .content { padding: 28px 48px; }
}

/* ==========================================================================
   Layout-Hilfsklassen
   ========================================================================== */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

/* Übersicht/Gesamtbild: ab Desktop bildschirmfüllend ohne Leerraum darunter;
   auf Tablet/Handy normaler Seitenfluss (kein erzwungenes 100vh-Layout). */
.dashboard { display: flex; flex-direction: column; gap: 14px; }
.dashboard-top {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}
.dashboard-map { display: flex; flex-direction: column; min-height: 280px; }
.dashboard-map .panel-body { flex: 1; min-height: 280px; }
#mini-map { height: 100%; min-height: 280px; }

.gesamtbild-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 8px;
}

@media (min-width: 1024px) {
    .dashboard { height: calc(100vh - 110px); }
    .dashboard-top { flex: 1 1 55%; min-height: 220px; }
    .dashboard-top .panel { height: 100%; }
    .dashboard-map { flex: 1 1 45%; }
    .dashboard-map .panel-body { max-height: none; }
    .gesamtbild-grid { height: calc(100vh - 80px); grid-auto-rows: 1fr; }
}

@media (min-width: 1920px) {
    .grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
    .gesamtbild-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

/* ==========================================================================
   Panels / Karten
   ========================================================================== */

.panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.panel-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    font-weight: 600;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: 0 0 auto;
}
.panel-body { padding: 14px 16px; max-height: 420px; overflow: auto; flex: 1; min-height: 0; }
.dashboard-top .panel-body { max-height: none; }
.gb-card { font-size: 0.85em; }
.gb-card .panel-header { padding: 8px 12px; font-size: 0.95em; }
.gb-card .panel-body { padding: 8px 12px; max-height: none; }

/* ==========================================================================
   Tabellen
   ========================================================================== */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
table td, table th {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
table th { color: var(--text-muted); font-weight: 500; font-size: 0.85em; }
table tr:hover td { background: var(--bg-sunken); }

/* ==========================================================================
   Status-Anzeigen
   ========================================================================== */

.status-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    font-size: 0.7em;
    font-weight: bold;
    color: #fff;
    flex: 0 0 auto;
}
.status-dot--unknown { background: var(--status-unknown); }
.status-1 { background: var(--status-1); }
.status-2 { background: var(--status-2); }
.status-3 { background: var(--status-3); }
.status-4 { background: var(--status-4); }
.status-5 { background: var(--status-5); }
.status-6 { background: var(--status-6); }

.ds-block { margin-bottom: 8px; }
.ds-name { color: var(--text-muted); font-size: 0.85em; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.ds-fahrzeuge { display: flex; flex-wrap: wrap; gap: 4px; }
.fz-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px 8px 2px 2px;
    color: var(--text);
    font-size: 0.85em;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fz-chip:hover { border-color: var(--accent); text-decoration: none; }
.fz-chip .status-dot { width: 14px; height: 14px; font-size: 0.65em; margin-right: 0; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
}
.badge--muted { background: var(--text-muted); }
.badge--success { background: var(--success); }
.badge--danger { background: var(--danger); }

.sync-health { font-size: 0.85em; color: var(--text-muted); margin-bottom: 12px; }
.sync-health.warn { color: var(--warning); font-weight: 600; }

/* ==========================================================================
   Karten (Leaflet)
   ========================================================================== */

#map { width: 100%; height: 60vh; min-height: 320px; border-radius: var(--radius); }
#mini-map { width: 100%; min-height: 220px; border-radius: var(--radius); }

/* ==========================================================================
   Formulare / Buttons
   ========================================================================== */

form.inline { display: inline; }
.toolbar { margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

input[type="text"], input[type="password"], input[type="date"], input[type="datetime-local"],
select, textarea {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    min-height: 40px;
}
input:focus, select:focus, textarea:focus, button:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    min-height: 40px;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent-contrast);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button.secondary, .btn.secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.error { color: var(--danger); }
.flash-ok { color: var(--success); }
.muted { color: var(--text-muted); }

/* ==========================================================================
   Login
   ========================================================================== */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.login-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 360px;
}
.login-box h1 { font-size: 1.1em; margin-top: 0; }
.login-box label { display: block; margin-bottom: 14px; }
.login-box input { width: 100%; margin-top: 4px; }
.login-box button { width: 100%; margin-top: 6px; }

/* Mobile-Touch-Komfort: groessere Tippflaechen unterhalb des Desktop-Breakpoints */
@media (max-width: 1023px) {
    button, .btn, input, select { min-height: 44px; }
    .sidebar-nav a { padding: 12px; }
}
