/**
 * style.css — Dienstplan Manager v2
 * Gemeinsame Styles + Print (F2) + Fairness-Alert (F4)
 */

/* =========================================
   CSS CUSTOM PROPERTIES (DARK — DEFAULT)
   ========================================= */
:root {
    --bg:          #111827;
    --surface:     #1f2937;
    --surface2:    #374151;
    --border:      #4b5563;
    --border2:     #4b5563;
    --text:        #f9fafb;
    --text-dim:    #9ca3af;
    --text-muted:  #6b7280;
    --accent:      #3b82f6;
    --accent-hover:#2563eb;
    --success:     #10b981;
    --danger:      #ef4444;
    --warning:     #f59e0b;
    --info:        #3b82f6;
    --holiday:     rgba(239, 68, 68, 0.15);
}

/* =========================================
   LIGHT MODE
   ========================================= */
.light-mode,
[data-theme="light"] {
    --bg:         #f3f4f6;
    --surface:    #ffffff;
    --surface2:   #e5e7eb;
    --border:     #d1d5db;
    --border2:    #d1d5db;
    --text:       #111827;
    --text-dim:   #6b7280;
    --text-muted: #6b7280;
    --holiday:    rgba(239, 68, 68, 0.10);
}

/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}

/* =========================================
   SCROLLBAR
   ========================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* =========================================
   TOPNAV / NAVBAR
   ========================================= */
.topnav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    flex-shrink: 0;
    position: relative;
}

.logo {
    font-size: 18px; font-weight: 700; color: var(--text);
    text-decoration: none; display: flex; align-items: center; gap: 10px;
}

.nav-links { display: flex; gap: 8px; align-items: center; }

.nav-link {
    color: var(--text-dim); text-decoration: none;
    padding: 8px 14px; border-radius: 8px;
    font-size: 14px; font-weight: 600;
    transition: background 0.2s, color 0.2s; white-space: nowrap;
}
.nav-link:hover, .nav-link.active {
    background: rgba(59, 130, 246, 0.15); color: var(--accent);
}

.logo-placeholder {
    height: 32px; width: 100px; border: 1px dashed var(--border);
    border-radius: 6px; display: flex; align-items: center;
    justify-content: center; font-size: 11px; color: var(--text-dim); flex-shrink: 0;
}

/* =========================================
   LAYOUT: SIDEBAR + CONTENT
   ========================================= */
.main { display: flex; flex: 1; overflow: hidden; }

.sidebar {
    width: 300px; background: var(--surface); border-right: 1px solid var(--border);
    padding: 20px; display: flex; flex-direction: column; gap: 15px;
    overflow-y: auto; flex-shrink: 0;
}

.content { flex: 1; overflow-y: auto; padding: 25px; background: var(--bg); }

/* =========================================
   BUTTONS
   ========================================= */
.btn {
    padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
    cursor: pointer; border: none;
    transition: filter 0.2s, background 0.2s;
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; text-decoration: none; position: relative;
}
.btn:hover    { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.btn-primary  { background: var(--accent);  color: white; }
.btn-success  { background: var(--success); color: white; }
.btn-danger   { background: var(--danger);  color: white; }
.btn-warning  { background: var(--warning); color: black; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface2); filter: none; }

/* Spinner im Button (U1) */
.btn.loading::after {
    content: '';
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 6px;
}

/* =========================================
   FORM ELEMENTS
   ========================================= */
input, select, textarea {
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-family: inherit; font-size: 13px;
    padding: 10px; outline: none; transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 15px; }
.form-group label {
    display: block; font-size: 11px; font-weight: 700;
    color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px;
}

/* =========================================
   CARDS & SECTIONS
   ========================================= */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.section {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 24px; margin-bottom: 24px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* =========================================
   TABLES
   ========================================= */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: var(--surface2); color: var(--text-dim); text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; }

/* FAIRNESS-ALERT (F4) — Zelle rot wenn Schwellwert überschritten */
.fairness-alert {
    background: rgba(239, 68, 68, 0.15) !important;
    color: var(--danger) !important;
    font-weight: 700 !important;
    position: relative;
}
.fairness-alert::after {
    content: '⚠';
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.8;
}

/* =========================================
   TABS
   ========================================= */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
    padding: 12px 20px; background: none; border: none;
    color: var(--text-dim); cursor: pointer; font-weight: 700; font-size: 14px;
    border-bottom: 3px solid transparent; transition: color 0.2s, border-color 0.2s;
    margin-bottom: -2px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* =========================================
   MODALS
   ========================================= */
.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); z-index: 2000;
    align-items: center; justify-content: center; backdrop-filter: blur(2px);
}
.modal-content {
    background: var(--surface); padding: 30px; border-radius: 12px;
    border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    max-height: 90vh; overflow-y: auto; width: 500px; max-width: 95vw;
    animation: fadeIn 0.2s ease;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal-close {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 20px; padding: 4px; line-height: 1;
}
.modal-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--border);
}

/* =========================================
   TOAST
   ========================================= */
#toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
    padding: 12px 24px; border-radius: 8px; color: white; font-weight: 600;
    font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.3s forwards; pointer-events: auto; max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger);  }
.toast.warning { background: var(--warning); color: black; }
.toast.info    { background: var(--info);    }

/* =========================================
   BADGES
   ========================================= */
.badge { padding: 4px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; display: inline-block; text-transform: uppercase; letter-spacing: 0.5px; }
.badge-role { background: var(--surface2); color: var(--accent); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; margin-right: 4px; }

.badge-disp  { background: rgba(249,115,22,.2);  color: #f97316; border: 1px solid rgba(249,115,22,.4); }
.badge-id    { background: rgba(168,85,247,.2);   color: #a855f7; border: 1px solid rgba(168,85,247,.4); }
.badge-opti  { background: rgba(34,197,94,.2);   color: #22c55e; border: 1px solid rgba(34,197,94,.4); }
.badge-fpl   { background: rgba(236,72,153,.2);  color: #ec4899; border: 1px solid rgba(236,72,153,.4); }
.badge-plt   { background: rgba(234,179,8,.2);   color: #eab308; border: 1px solid rgba(234,179,8,.4); }
.badge-hydm  { background: rgba(20,184,166,.2);  color: #14b8a6; border: 1px solid rgba(20,184,166,.4); }
.badge-blue  { background: rgba(59,130,246,.2);  color: var(--accent);  border: 1px solid rgba(59,130,246,.4); }
.badge-yellow{ background: rgba(245,158,11,.2);  color: var(--warning); border: 1px solid rgba(245,158,11,.4); }
.badge-red   { background: rgba(239,68,68,.2);   color: var(--danger);  border: 1px solid rgba(239,68,68,.4); }
.badge-green { background: rgba(16,185,129,.2);  color: var(--success); border: 1px solid rgba(16,185,129,.4); }
.badge-gray  { background: rgba(156,163,175,.2); color: var(--text-dim);border: 1px solid rgba(156,163,175,.4); }

/* =========================================
   LOADING BAR
   ========================================= */
.loader { height: 3px; background: var(--accent); width: 0%; position: fixed; top: 0; left: 0; transition: width 0.3s; z-index: 9999; }

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeIn  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* =========================================
   TOOLBAR
   ========================================= */
.toolbar {
    display: flex; gap: 15px; align-items: center; flex-wrap: wrap;
    background: var(--surface2); padding: 15px 20px; border-bottom: 1px solid var(--border);
}

/* =========================================
   MOBILE RESPONSIVE (U8 Basis — Hamburger kommt aus utils.js)
   ========================================= */
@media (max-width: 768px) {
    .topnav { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
    .nav-link { padding: 6px 10px; font-size: 12px; }
    .sidebar { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
    .main { flex-direction: column; }
    .modal-content { width: 95vw; padding: 20px; }
    .toolbar { padding: 12px; gap: 8px; }
}

/* =========================================
   PRINT-STILE (F2)
   Aktiviert durch window.print() oder Strg+P
   ========================================= */
@media print {
    /* Alles ausblenden was nicht zum Plan gehört */
    .topnav, .sidebar, .toolbar, #toast-container,
    .modal, .sb-btn, .btn, .dropdown,
    #offline-banner, .refresh-badge, #nav-burger { display: none !important; }

    /* Vollbreite Kalender */
    body  { background: white !important; color: black !important; font-size: 10px; }
    .main { flex-direction: column; overflow: visible; height: auto; }
    .content { overflow: visible; padding: 0; }
    .cal-area { overflow: visible; padding: 0; }

    /* Kalender-Tabelle schwarz/weiß */
    .cal-table { border: 1px solid #ccc !important; width: 100% !important; min-width: unset !important; }
    .cal-table th, .cal-table td { border: 1px solid #ccc !important; padding: 2px 4px !important; font-size: 9px !important; height: auto !important; }
    .service-label { background: #eee !important; color: black !important; }
    .kw-header { background: #ddd !important; color: black !important; }

    /* Farben beibehalten (wichtig für Dienstart-Farben) */
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    /* Seitenumbruch zwischen Kalenderwochen verhindern */
    .cal-table { page-break-inside: avoid; }

    /* Druck-Header */
    body::before {
        content: 'Dienstplan Manager — ' attr(data-print-title);
        display: block; font-size: 16px; font-weight: bold;
        margin-bottom: 12px; padding-bottom: 8px;
        border-bottom: 2px solid black;
    }
}

/* =========================================
   SELECT OPTION — Dark/Light Mode Fix
   Browser rendert <option> oft mit System-Default
   Explizit setzen damit es im Dark Mode lesbar ist
   ========================================= */
[data-theme="dark"] select option {
    background-color: #1e2433;
    color: #e2e8f0;
}
[data-theme="dark"] select {
    color-scheme: dark;
}
[data-theme="light"] select option {
    background-color: #ffffff;
    color: #111827;
}
[data-theme="light"] select {
    color-scheme: light;
}

/* =========================================
   ROLE-GATED NAV-LINKS (data-role)
   Hidden by default; initNavbar() zeigt sie für die richtige Rolle.
   Verhindert Flash-of-Admin-Links beim Seitenaufbau.
   ========================================= */
[data-role] { display: none !important; }
