:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --brand: #0f766e;
  --text: #0f172a;
  --muted: #64748b;
  --bubble-ai: #e2e8f0;
  --monitor-bg: #000000;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
}

body.dark-mode {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --bubble-ai: #334155;
  --shadow: 0 10px 30px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

/* FIX: Hintergrundfarbe auch auf html setzen, damit kein weißer Balken entsteht */
html { 
    height: 100%; 
    background-color: var(--bg); 
    transition: background 0.3s;
}

body {
  min-height: 100vh;
  margin: 0;
  font: 16px/1.5 system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

.page { max-width: 1000px; margin: 0 auto; padding: 20px 15px 40px; }
.chat-container { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 20px; position: relative; z-index: 10; }

/* HEADER */
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap:10px; }
h1 { margin: 0; font-size: 1.5rem; color: var(--brand); }

.controls-right { display: flex; gap: 8px; align-items: center; }
.mode-toggle { background: transparent; border: 1px solid var(--muted); color: var(--muted); border-radius: 6px; padding: 4px 8px; cursor: pointer; color:inherit !important; border-color: currentColor !important; opacity: 0.7; }
.mode-toggle:hover { opacity: 1; }

.timer-badge {
    background: #0f172a; color: #fff; font-family: monospace; font-size: 1.3rem; padding: 5px 12px; border-radius: 6px; font-weight: bold;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    border: 2px solid #334155;
}
body.dark-mode .timer-badge { background: #f1f5f9; color: #0f172a; }

/* SETUP */
.setup-container { margin-bottom: 20px; padding: 15px; background: var(--bg); border-radius: 10px; border: 1px solid var(--muted); }
.setup-row { margin-bottom: 10px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.mb-2 { margin-bottom: 1rem; }

.control-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.role-select { height: 40px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--muted); background: var(--card); color: var(--text); }

.status-group { text-align: right; font-size: 0.9rem; color: var(--muted); display: flex; gap: 10px; align-items: center; margin-left: auto; }
.score-badge { font-weight: bold; color: var(--brand); background: var(--bubble-ai); padding: 2px 8px; border-radius: 4px; }

.spec-chip { border: 1px solid var(--muted); background: var(--card); color: var(--text); padding: 6px 12px; border-radius: 99px; cursor: pointer; font-size: 0.9rem; }
.spec-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* MONITOR */
.vitals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 4px;
    background: var(--monitor-bg);
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 4px solid #334155;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}
.vital-box { background: #111; color: #fff; padding: 8px; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80px; position: relative; border: 1px solid #333; }
.vital-label { font-size: 0.75rem; text-transform: uppercase; color: #888; font-weight: bold; margin-bottom: 4px; }
.vital-val { font-size: 1.6rem; font-weight: bold; font-family: 'Courier New', monospace; letter-spacing: -1px; }

.v-hr .vital-val { color: #4ade80; text-shadow: 0 0 5px rgba(74, 222, 128, 0.5); }
.v-spo2 .vital-val { color: #38bdf8; text-shadow: 0 0 5px rgba(56, 189, 248, 0.5); }
.v-rr .vital-val { color: #f87171; }
.v-co2 .vital-val { color: #facc15; }

@keyframes blinkRed { 0% { background: #111; } 50% { background: #7f1d1d; } 100% { background: #111; } }
.vital-box.critical { animation: blinkRed 1s infinite; border-color: #ef4444; }

/* PROGRESS & CHIPS (ZWEIZEILIGE DARSTELLUNG MIT ZENTRIERUNG) */
.progress { 
    display: flex; 
    flex-wrap: wrap; 
    /* NEU: Zentriert die Chips, wenn sie umgebrochen werden (insbesondere die zweite Reihe) */
    justify-content: center; 
    gap: 6px; 
    margin-bottom: 15px; 
    overflow-x: auto; 
    padding-bottom: 4px; 
}
/* 4S-Schema nimmt die gesamte Breite ein und erzwingt den Umbruch */
.progress .chip[data-tool="FOUR_S"] {
    width: 100%; 
    margin-bottom: 6px; 
    order: -1; /* Zwingt 4S an den Anfang, falls Flexbox-Reihenfolge durch JS beeinflusst wird */
}

.chip { 
    flex-shrink: 0; 
    font-size: 0.85rem; 
    padding: 8px 12px; 
    border-radius: 99px; 
    color: var(--muted); 
    white-space: nowrap; 
    cursor: pointer;
    min-width: 60px; 
    text-align: center;
}
.chip.done { background: #d1fae5; border-color: #10b981; color: #047857; }
body.dark-mode .chip.done { background: #064e3b; border-color: #10b981; color: #34d399; }
.chip.active { border: 2px solid var(--brand); color: var(--brand); font-weight: bold; }

/* ACTIONS (DROPDOWNS) */
.action-dropdown-container {
    padding: 5px;
}
#actionPanel {
    display: grid;
    /* Auf großen Screens: Minimum 180px, verteilt auf 6 Spalten */
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 10px;
    margin-bottom: 5px;
    padding: 10px 0;
}
.action-dropdown {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--muted);
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    height: 40px; /* Einheitliche Höhe */
}


/* SCHEMATA */
.schemata-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; padding-top: 10px; border-top: 1px solid var(--muted); }
.schema-btn { background: var(--card); border: 1px solid var(--muted); padding: 8px 14px; border-radius: 6px; cursor: pointer; color: var(--text); font-size: 0.9rem; min-width: 100px; }
.schema-btn.primary { background: var(--brand); color: white; border: none; }

/* CHAT (Protokoll) */
.queue { background: var(--bg); padding: 10px; border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--muted); display: none; }
.queue:not(:empty) { display: block; }
.queue-item { display: flex; justify-content: space-between; padding: 6px 10px; background: var(--card); border-radius: 6px; margin-bottom: 4px; color: var(--text); border: 1px solid var(--muted); }

.chat-wrap { background: var(--bg); border-radius: 12px; padding: 15px; height: 350px; overflow-y: auto; border: 1px solid var(--muted); }
.msg { background: var(--card); padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border-left: 4px solid var(--brand); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.msg div { margin-bottom: 4px; }

/* BUTTONS */
.btn { padding: 0 20px; height: 40px; border-radius: 6px; border: none; font-weight: bold; cursor: pointer; background: var(--brand); color: white; display: inline-flex; align-items: center; justify-content: center; }
.btn.secondary { background: var(--muted); }
.btn.danger { background: #dc2626; }
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.na-btn { padding: 0 20px; height: 40px; border-radius: 6px; border: none; font-weight: bold; cursor: pointer; background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* MODALS */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(3px); z-index: 2000; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--card); width: 90%; max-width: 500px; padding: 20px; border-radius: 12px; z-index: 2001; box-shadow: 0 20px 50px rgba(0,0,0,0.5); color: var(--text); border: 1px solid var(--muted); }
.modal-head { font-size: 1.2rem; font-weight: bold; margin-bottom: 15px; border-bottom: 1px solid var(--muted); padding-bottom: 10px; }
.modal-body { margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; padding: 10px; margin-top: 5px; border-radius: 6px; border: 1px solid var(--muted); background: var(--bg); color: var(--text); }
.af-ui { display: flex; justify-content: space-around; font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; }

/* EKG */
@keyframes ekgMove { 0% { stroke-dashoffset: 400; } 100% { stroke-dashoffset: 0; } }
.ekg-anim { stroke-dasharray: 400; animation: ekgMove 4s linear infinite; }

/* UTILS */
.hidden { display: none !important; }
.small { font-size: 0.85rem; }
.muted { color: var(--muted); opacity: 0.8; }

@media print {
    body { background: #fff; color: #000; }
    .chat-container, .card, .queue, .modal { box-shadow: none; border: 1px solid #ccc; }
    .setup-container, .tabs, .schemata-row, .modal-actions, .na-btn, .btn, .controls-right { display: none !important; }
    .chat-wrap { max-height: none; overflow: visible; border: none; }
    #missionTimer { border: 1px solid #000; color: #000; background: #fff; display:block !important; }
    .msg { border: 1px solid #eee; background: #fff; color: #000; }
}
/* EKG Monitor Styles */
.ekg-screen {
  background-color: #000;
  border: 4px solid #333;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}
/* Animation für die Kurven (laufen von rechts nach links) */
@keyframes dash {
  from { stroke-dashoffset: 1000; }
  to { stroke-dashoffset: 0; }
}
/* EKG Monitor Screen */
.ekg-screen {
  background-color: #000;
  border: 4px solid #333;
  border-radius: 4px;
  position: relative;
  overflow: hidden; /* Wichtig, damit man den zweiten Streifen nicht sieht */
}

/* Die neue Endlos-Animation */
@keyframes slideLeft {
  from { transform: translateX(0); }
  to { transform: translateX(-400px); } /* Verschiebt um genau eine Bildbreite */
}

.infinite-scroll {
  animation: slideLeft 4s linear infinite; /* 4s für einen Durchlauf */
}
/* Echter Monitor-Look */
.monitor-glow {
  filter: drop-shadow(0 0 2px rgba(0, 255, 0, 0.6));
}
.monitor-glow-blue {
  filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.6));
}
/* Container: Boxen müssen breit genug sein */
.vitals {
    /* minmax 135px sorgt dafür, dass die Boxen nicht zu schmal werden */
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)) !important;
}

/* --- FINALE REPARATUR: LAYOUT & ALIGNMENT --- */

/* 1. Container: Zurück zu schmaleren Boxen für "Eine Zeile"-Look */
.vitals {
    /* minmax 105px sorgt dafür, dass die Boxen nicht zu schmal werden */
    grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)) !important;
    gap: 4px !important;
    width: 100%;
}

/* 2. Die Box selbst: Flexbox für perfekte Zentrierung */
.vital-box {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important; /* Vertikal mittig */
    align-items: center !important;     /* Horizontal mittig */
    text-align: center !important;      /* Textausrichtung */
    min-height: 85px !important;
    padding: 2px !important;
    overflow: hidden !important;        /* Nichts darf rauslaufen */
}

/* 3. Der Blutdruck-Wert (RR): Dynamisch anpassen */
#vRR {
    font-size: 1.25rem !important;      /* Klein genug für "138/86" */
    letter-spacing: -0.5px !important;
    white-space: nowrap !important;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 4. Andere Werte: Standardgröße */
.vital-val {
    font-size: 1.5rem !important;
    line-height: 1.2 !important;
}

/* 5. Labels (NIBP, SPO2...): Klein und zentriert */
.vital-label {
    width: 100%;
    text-align: center;
    margin-bottom: 4px;
    font-size: 0.75rem !important;
}

/* NEU: Spezielles Styling für Kriterien-Modals (NEXUS, Polytrauma, 4S, BEFAST) */
/* Verbesserte Optik für Checkbox-Listen in Modalen */
.criteria-modal-body {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0;
}

.criteria-modal-body label {
    display: flex;
    align-items: center; /* Vertikal zentriert Checkbox und Text */
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--muted);
    cursor: pointer;
    transition: background 0.2s;
}

.criteria-modal-body label:hover {
    background: var(--bubble-ai);
}

.criteria-modal-body input[type="checkbox"] {
    width: 20px !important; /* Fixe Breite für die Box */
    height: 20px !important;
    margin: 0;
    cursor: pointer;
    accent-color: var(--brand); /* Nutzt deine Markenfarbe für den Haken */
}

/* NEU: Verbessert die Sichtbarkeit des NRS Schiebereglers */
#modalNRS input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    background: var(--bg);
    outline: none;
    opacity: 0.7;
    -webkit-transition: .2s;
    transition: opacity .2s;
    border-radius: 5px;
}

#modalNRS input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: var(--brand); /* Die Markenfarbe verwenden */
    cursor: pointer;
}

#modalNRS .nrs-val {
    margin-top: 10px;
    text-align: center;
    font-size: 1.2rem;
}
/* style.css (Am Ende hinzufügen) */

/* NEU: Styling für die Dropdown-Struktur */
.action-dropdown-container {
    padding: 5px;
}

.action-dropdown {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--muted);
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Passt das Grid-Layout so an, dass die Dropdowns ordentlich nebeneinander liegen */
#actionPanel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); /* Breitere Basis als das alte Grid */
    gap: 10px;
    margin-bottom: 5px;
    padding: 10px 0;
    /* Hintergrundfarbe entfernen, da der Bereich jetzt offen ist */
}

/* ======================================= */
/* !!! MOBILE OPTIMIERUNGEN (max-width: 600px) !!! */
/* ======================================= */
@media (max-width: 600px) {
    .page { padding: 10px; }
    .chat-container { padding: 15px; border-radius: 0; }
    
    /* HEADER: Icons und Titel in eine Zeile */
    .header-row { flex-direction: row; gap: 8px; margin-bottom: 15px; }
    h1 { font-size: 1.2rem; min-width: 150px; }
    .controls-right { margin-left: auto; }
    
    /* SETUP: Buttons verkleinern und Zeilenumbruch forcieren */
    .setup-container { padding: 10px; }
    .spec-chip { 
        font-size: 0.75rem; 
        padding: 4px 8px; 
        flex-grow: 1; /* Nehmen den verfügbaren Platz ein */
    }
    .control-group { 
        flex-direction: column; 
        align-items: stretch;
        gap: 8px; 
    }
    .control-group button, .control-group select { 
        width: 100%; 
        box-sizing: border-box; 
    }
    .status-group { 
        width: 100%;
        justify-content: space-between;
        margin-top: 10px;
    }

    /* VITALZEICHEN: Kleiner, kompakter und weniger Text */
    .vitals {
        padding: 5px;
        /* Bei 7 Elementen: minmax auf 85px reduzieren, damit sie passen */
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr)) !important; 
    }
    .vital-box { min-height: 65px !important; }
    .vital-label { font-size: 0.65rem !important; }
    .vital-val { font-size: 1.3rem !important; }
    #vRR { font-size: 1.1rem !important; }

    /* PROGRESS/SCHEMATA: Bessere Touch-Ziele und Scrollen */
    .progress { 
        gap: 4px; 
        padding-bottom: 8px; /* Mehr Platz für den Scroll-Balken */
    }
    .chip { 
        font-size: 0.8rem; 
        padding: 6px 8px; 
        min-width: 50px;
    }
    
    .schemata-row {
        gap: 6px;
        margin-bottom: 15px;
    }
    .schema-btn {
        font-size: 0.8rem;
        padding: 6px 10px;
        flex-grow: 1; /* Lassen Sie sie gleichmäßig wachsen */
    }
    
    /* DROPDOWN-AKTIONEN: Max. 2 Spalten auf kleinsten Geräten */
    #actionPanel {
        /* Passt sich auf 48% Breite an, um auf kleinem Screen 2 Spalten zu ermöglichen */
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr)); 
        gap: 6px;
        padding: 5px 0;
    }
    .action-dropdown {
        font-size: 0.95rem;
    }

    /* CHAT LOG */
    .chat-wrap { 
        height: 300px; 
    }
}
/* --- MODAL BEAUTY FIX --- */

/* Verhindert das Quetschen in eine Zeile */
.criteria-modal-body, .befast-grid {
    display: flex !important;
    flex-direction: column !important; /* Untereinander statt nebeneinander */
    gap: 10px !important;
    padding: 15px 5px !important;
}

/* Styling für die Zeilen (Labels) */
.criteria-modal-body label, .befast-grid label {
    display: flex !important;
    align-items: center !important; /* Vertikal mittig */
    background: var(--bg);
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid var(--muted);
    cursor: pointer;
    transition: 0.2s;
    margin: 0 !important; /* Reset margins */
}

.criteria-modal-body label:hover {
    background: var(--bubble-ai);
    border-color: var(--brand);
}

/* Die Checkbox selbst verschönern */
.criteria-modal-body input[type="checkbox"], 
.befast-grid input[type="checkbox"] {
    width: 22px !important;
    height: 22px !important;
    margin-right: 15px !important; /* Abstand zum Text */
    flex-shrink: 0; /* Verhindert, dass die Box schrumpft */
    cursor: pointer;
    accent-color: var(--brand);
}

/* Speziell für das Zeit-Feld im BE-FAST */
.time-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding: 10px 15px;
    background: var(--card);
    border-radius: 10px;
    border: 1px dashed var(--brand);
}

.time-row input[type="time"] {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--muted);
    font-family: monospace;
    font-size: 1.1rem;
}
/* Schickes Layout für das Übergabe-Formular */
#modalHandover .form-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
}

#modalHandover label {
    font-weight: bold;
    color: var(--brand);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#modalHandover textarea, 
#modalHandover input {
    font-weight: normal;
    font-family: inherit;
    border: 1px solid var(--muted);
    border-radius: 8px;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
}

#modalHandover textarea:focus, 
#modalHandover input:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.2);
}
/* EKG Monitor Proportionen */
#monitorSvg {
    background-color: #000;
    display: block;
    width: 100%;
    height: 100%;
    aspect-ratio: 2 / 1; /* Verhindert Verzerrung der Kurven */
    border-radius: 4px;
}

.ekg-screen {
    border: 3px solid #444;
    background: radial-gradient(circle, #111 0%, #000 100%);
    box-shadow: inset 0 0 15px rgba(0, 255, 0, 0.1);
    margin-bottom: 10px;
}

#ekgText {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    background: #111;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #333;
}