/**
 * GroupAlarm V2 - Haupt-Stylesheet
 * Enthält Variablen, Layout-Definitionen, responsive Anpassungen und Theme-Unterstützung.
 */

:root {
    /* Layout */
    --sidebar-width: 250px;
    --header-height: 60px;

    /* Farben (Light Mode Default) */
    --primary-color: #343a40;
    --secondary-color: #007bff;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #212529;
    --text-muted: #6c757d;
    --text-on-primary: #f8f9fa;
    
    --border-color: #dee2e6;
    --sidebar-hover: #495057;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --primary-color: #1a1d21;
    --secondary-color: #375a7f;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #e9ecef;
    --text-muted: #adb5bd;
    --border-color: #333333;
    --sidebar-hover: #2c3136;
    --shadow: 0 4px 6px rgba(0,0,0,0.3);
}

/* Basis-Layout */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

/* --- SIDEBAR --- */
#sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: var(--text-on-primary);
    display: none; /* Wird nur angezeigt, wenn body.logged-in */
    flex-direction: column;
    flex-shrink: 0;
    transition: left 0.3s ease;
    z-index: 1100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

body.logged-in #sidebar {
    display: flex;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: 1px;
}

#sidebar nav {
    flex-grow: 1;
    padding-top: 10px;
    overflow-y: auto;
}

#sidebar nav a {
    display: block;
    padding: 12px 20px;
    color: var(--text-on-primary);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

#sidebar nav a:hover, 
#sidebar nav a.active {
    background-color: var(--sidebar-hover);
    border-left-color: var(--secondary-color);
}

/* Navigation Dropdown */
.nav-dropdown-content {
    display: none;
    background-color: rgba(0,0,0,0.1);
}

.nav-dropdown.open .nav-dropdown-content {
    display: block;
}

.nav-dropdown-content a {
    padding-left: 40px !important;
    font-size: 0.9rem;
    border-left: none !important;
}

.sidebar-sub-list a {
    padding-left: 55px !important;
    font-size: 0.85rem !important;
    opacity: 0.8;
}

.sidebar-sub-list a:hover {
    opacity: 1;
}

.nav-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
    opacity: 1 !important;
}

.dropdown-arrow {
    transition: transform 0.2s ease;
}

.sidebar-bottom {
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section-title {
    display: block;
    padding: 10px 20px 5px 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
    font-weight: bold;
}

.logout-link {
    color: #ff6b6b !important;
}

.theme-toggle {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    cursor: pointer;
}

.footer {
    padding: 10px;
    text-align: center;
    font-size: 0.7rem;
    opacity: 0.5;
}

/* --- MAIN CONTENT --- */
#main-content {
    flex-grow: 1;
    padding: 30px;
    overflow-y: auto;
    width: 100%;
}

h1 {
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: 300;
}

/* --- KOMPONENTEN --- */

/* Karten */
.card {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.card h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

/* Tabellen */
.status-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.status-table th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
}

.status-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

/* Buttons */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s, transform 0.1s;
    background-color: var(--secondary-color);
    color: white;
}

button:hover { opacity: 0.9; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-small { padding: 5px 10px; font-size: 0.8rem; }
.btn-success { background-color: var(--success-color); }
.btn-danger { background-color: var(--danger-color); }
.btn-primary { background-color: var(--secondary-color); }

/* Formular-Elemente */
input[type="text"], 
input[type="password"], 
select, 
textarea {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin-bottom: 15px;
    font-family: inherit;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

/* Badges & Status-Indikatoren */
.status-online { color: var(--success-color); font-weight: bold; }
.status-offline { color: var(--danger-color); font-weight: bold; }

.code-badge {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

[data-theme="dark"] .code-badge { background: rgba(255,255,255,0.1); }

/* --- DASHBOARD & PROFIL --- */
.status-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.status-label {
    font-weight: 600;
    color: var(--text-muted);
}

/* --- TOGGLE SWITCH --- */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--success-color);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--success-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- MODALS --- */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(3px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
}

.close:hover { color: var(--text-color); }

/* --- VORSCHLAGSSYSTEM --- */
.suggestions-container { position: relative; }

.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 2100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
}

.suggestion-item {
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active { background-color: var(--bg-color); }
.suggestion-name { font-weight: 600; }
.suggestion-phone { color: var(--text-muted); font-size: 0.85rem; }

/* --- RESPONSIVE / MOBILE --- */
#mobile-header {
    display: none;
    height: var(--header-height);
    background-color: var(--primary-color);
    color: var(--text-on-primary);
    padding: 0 20px;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1050;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#hamburger-menu {
    background: none;
    font-size: 24px;
    padding: 0;
    margin-right: 15px;
}

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0; bottom: 0;
        left: -250px;
        width: 250px;
        display: flex !important;
    }

    #sidebar.show { left: 0; }

    #mobile-header { display: flex; }

    #main-content {
        padding: 80px 15px 20px 15px !important;
    }

    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1090;
    }

    #sidebar-overlay.show { display: block; }
}

/* --- CHAT --- */
.chat-card {
    display: flex;
    flex-direction: column;
    height: 500px;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-all;
    position: relative;
}

.chat-message-received {
    align-self: flex-start;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
}

.chat-message-sent {
    align-self: flex-end;
    background-color: var(--secondary-color);
    color: white;
}

.message-meta {
    font-size: 0.75rem;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.chat-message-sent .message-meta {
    color: rgba(255, 255, 255, 0.8);
}

.chat-message-received .message-meta {
    color: var(--text-muted);
}

.chat-input-area {
    display: flex;
    gap: 10px;
}

.chat-input-area input {
    flex-grow: 1;
    margin-bottom: 0 !important;
}

/* Hilfsklassen */
.error-msg { color: var(--danger-color); margin-bottom: 15px; font-weight: bold; display: none; }
.success-msg { color: var(--success-color); margin-bottom: 15px; font-weight: bold; display: none; }
.text-muted { color: var(--text-muted); }
.permission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 20px; }
.permission-item { font-size: 0.85rem; display: flex; align-items: center; gap: 5px; }
.fab { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; border-radius: 50%; font-size: 24px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }

input[type="text"], input[type="password"], input[type="number"] {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--body-text);
    margin-bottom: 10px;
}

button {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.3s;
}

button:hover {
    opacity: 0.8;
}

.tray {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}
.tray-header {
    background-color: var(--secondary-color);
    color: white;
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}
.tray-content {
    background-color: var(--card-bg);
    padding: 20px;
    display: none;
}
.tray.open .tray-content {
    display: block;
}
.tray-arrow {
    transition: transform 0.3s;
}
.tray.open .tray-arrow {
    transform: rotate(180deg);
}
.error-msg {
    color: #dc3545;
    margin: 10px 0;
    display: none;
}
.success-msg {
    color: #28a745;
    margin: 10px 0;
    display: none;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background-color: var(--secondary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    border: none;
    z-index: 100;
}
.fab:hover {
    transform: scale(1.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}
.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 550px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
    animation: modal-anim 0.3s;
}

@keyframes modal-anim {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.modal input {
    margin-bottom: 15px !important;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--body-text);
}
.close {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.close:hover {
    color: var(--body-text);
}

.permission-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 15px 0;
}
.permission-item {
    display: flex;
    align-items: center;
}
.permission-item input {
    margin-right: 10px;
}

/* Custom Suggestions */
.suggestions-container {
    position: relative;
    width: 100%;
}

.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 4px 4px;
    z-index: 1100;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    display: none;
}

.suggestion-item {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    color: var(--body-text);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover, .suggestion-item.active {
    background-color: var(--sidebar-hover);
}

.suggestion-item .suggestion-name {
    font-weight: bold;
    display: block;
}

.suggestion-item .suggestion-phone {
    font-size: 0.85em;
    color: var(--text-muted);
}
