/* design/css/design.css */

/* =========================================
   1. FARBPALETTE & THEMES (Variablen)
   ========================================= */
:root {
    /* --- LIGHT MODE (Standard) --- */
    --bg-body: #d1d7db;
    --bg-app: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-chat: #efeae2;          
    --bg-header: #f0f2f5;
    --bg-input: #ffffff;
    --bg-msg-me: #d9fdd3;        
    --bg-msg-other: #ffffff;     
    
    --text-main: #111b21;
    --text-secondary: #54656f;
    --text-on-primary: #ffffff;

    --border-color: #e9edef;
    --primary: #00a884;
    --primary-hover: #008f6f;
    
    --shadow-soft: rgba(0,0,0,0.1);
    --shadow-modal: rgba(0,0,0,0.2);
    
    --overlay-bg: rgba(0, 0, 0, 0.5);
    
    /* Alerts (Neu für Contacts.php) */
    --alert-success-bg: #dcf8c6;
    --alert-success-text: #206324;
    --alert-success-border: #c2dbb2;
    
    --alert-error-bg: #f8d7da;
    --alert-error-text: #721c24;
    --alert-error-border: #f5c6cb;
    
    --scrollbar-track: transparent;
    --scrollbar-thumb: #ced0d1;
}

/* --- DARK MODE (Automatisch) --- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #0b141a;       
        --bg-app: #111b21;
        --bg-sidebar: #111b21;
        --bg-chat: #0b141a;       
        --bg-header: #202c33;
        --bg-input: #2a3942;
        --bg-msg-me: #005c4b;     
        --bg-msg-other: #202c33;  
        
        --text-main: #e9edef;
        --text-secondary: #8696a0;
        --text-on-primary: #ffffff;

        --border-color: #2f3b43;
        --primary: #00a884;       
        --primary-hover: #02906f;
        
        --shadow-soft: rgba(0,0,0,0.3);
        --shadow-modal: rgba(0,0,0,0.6);
        
        --overlay-bg: rgba(0, 0, 0, 0.8);

        /* Alerts Dark Mode */
        --alert-success-bg: #005c4b;
        --alert-success-text: #e9edef;
        --alert-success-border: #004539;
    
        --alert-error-bg: #3b1219;
        --alert-error-text: #f8b4b4;
        --alert-error-border: #5c1e26;

        --scrollbar-thumb: #374045;
    }
}

/* =========================================
   2. GLOBAL RESET & BASIS
   ========================================= */
* {
    box-sizing: border-box; 
}

body {
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb); border-radius: 3px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =========================================
   3. APP CONTAINER (Hauptanwendung)
   ========================================= */
.app-container {
    display: flex;
    width: 95vw;
    max-width: 1600px;
    height: 90vh;
    background: var(--bg-app);
    box-shadow: 0 10px 30px var(--shadow-soft);
    border-radius: 12px;
    overflow: hidden; 
    position: relative;
    border: 1px solid var(--border-color);
}

/* =========================================
   4. SIDEBAR
   ========================================= */
.sidebar {
    width: 350px; 
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0; 
}

.sidebar-header {
    height: 70px;
    padding: 0 15px;
    background: var(--bg-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.user-list {
    flex: 1;
    overflow-y: auto;
}

.user-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.1s;
    color: var(--text-main);
}

.user-item:hover, .user-item.active {
    background-color: var(--bg-header); 
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #dfe3e5; 
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 15px;
    flex-shrink: 0;
    color: #555;
}

.unread-badge {
    background-color: #25d366;
    color: #fff;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* =========================================
   5. CHAT AREA
   ========================================= */
.chat-area {
    flex: 1; 
    display: flex;
    flex-direction: column;
    background-color: var(--bg-chat);
    background-image: radial-gradient(var(--border-color) 8%, transparent 0);
    background-size: 20px 20px;
    position: relative;
    min-width: 0; 
}

.chat-header {
    height: 70px;
    padding: 0 20px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    color: var(--text-main);
    flex-shrink: 0;
}

#chat-partner-name {
    font-weight: bold;
    cursor: pointer; /* WICHTIG: Zeigt Klickbarkeit an */
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.2s;
}

#chat-partner-name:hover {
    background-color: rgba(0,0,0,0.05); /* Leichter Hover-Effekt */
}

.messages-container {
    flex: 1;
    padding: 20px 5%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: opacity 0.2s ease; 
}

.msg-row { display: flex; width: 100%; }
.msg-row.me { justify-content: flex-end; }
.msg-row.other { justify-content: flex-start; }

.msg-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 2px var(--shadow-soft);
    word-wrap: break-word; 
}

.msg-row.me .msg-bubble {
    background-color: var(--bg-msg-me);
    color: var(--text-main);
    border-top-right-radius: 0;
}

.msg-row.other .msg-bubble {
    background-color: var(--bg-msg-other);
    color: var(--text-main);
    border-top-left-radius: 0;
}

.msg-meta {
    font-size: 1rem;
    text-align: right;
    margin-top: 4px;
    color: var(--text-secondary);
    opacity: 0.8;
}

.date-badge, .system-msg {
    align-self: center;
    background-color: var(--bg-header);
    color: #fff;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 1rem;
    margin: 10px 0;
    box-shadow: 0 1px 1px var(--shadow-soft);
    text-align: center;
}

/* Input Area */
.chat-input-area {
    min-height: 70px;
    background: var(--bg-header);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 15px;
    border-radius: 8px;
    border: none;
    outline: none;
    font-size: 1rem;
    background: var(--bg-input);
    color: var(--text-main);
}

button {
    background-color: var(--primary);
    color: var(--text-on-primary);
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
    font-size: 0.95rem;
}
button:hover { opacity: 0.9; }

/* =========================================
   6. AUTH PAGES (Login / Register)
   ========================================= */
.auth-box {
    background: var(--bg-app);
    padding: 40px;
    border-radius: 12px;
    width: 90%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 10px 30px var(--shadow-modal);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-box h2 {
    margin-top: 0;
    color: var(--text-main);
    margin-bottom: 5px;
}

.auth-box input {
    width: 100%;
    padding: 12px 15px;
    margin: 5px 0 15px 0;
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s;
}

.auth-box input:focus { border-color: var(--primary); }

.auth-box button {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    font-size: 1rem;
}

.file-drop {
    border: 2px dashed var(--border-color);
    padding: 30px 20px;
    margin: 15px 0;
    cursor: pointer;
    background: var(--bg-header);
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.file-drop:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-input);
}

.file-drop.dragover {
    border-color: var(--primary);
    background: rgba(0, 168, 132, 0.1);
}

.auth-status {
    min-height: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 10px;
}

.auth-footer {
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* =========================================
   7. MODALS
   ========================================= */
#group-settings-modal, 
#group-modal, 
#confirmation-modal, 
#contacts-modal,
#image-preview-modal, 
#file-preview-modal,
#user-info-modal,
#group-info-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: var(--overlay-bg);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--bg-app);
    color: var(--text-main);
    width: 90%;
    max-width: 450px;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--shadow-modal);
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-content h3 {
    margin-top: 0;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.close-btn {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#settings-group-name, #new-group-name {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
}

#settings-members-list, 
#modal-contact-list, 
#modal-contacts-list-container {
    /* Begrenzung der Höhe auf ca. 5-6 Einträge (je nach Höhe eines Eintrags) */
    max-height: 300px; 
    
    /* Aktiviert den vertikalen Scrollbalken, wenn der Inhalt zu lang ist */
    overflow-y: auto; 
    
    /* Design-Anpassungen für den Container */
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-header); /* Leicht abgedunkelter Hintergrund */
    padding: 5px;
    margin-top: 10px; /* Etwas Abstand nach oben */
    
    /* Optional: Weiches Scrollen */
    scroll-behavior: smooth;
}

/* Sicherstellen, dass die einzelnen Einträge sauber aussehen */
#settings-members-list > div, 
#modal-contact-list > div,
#modal-contacts-list-container > div.contact-item { /* Klasse ggf. in JS anpassen */
    background: var(--bg-app);
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    border: 1px solid transparent; /* Platzhalter für Border */
}

/* Hover-Effekt für bessere UX */
#settings-members-list > div:hover, 
#modal-contact-list > div:hover,
#modal-contacts-list-container > div:hover {
    background-color: var(--bg-input);
    border-color: var(--border-color);
    cursor: pointer;
}

/* =========================================
   8. MOBILE RESPONSIVENESS
   ========================================= */
@media (max-width: 768px) {
    .app-container { width: 100%; height: 100%; border-radius: 0; border: none; }
    .sidebar { width: 100%; border-right: none; }
    .chat-area { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 100; display: none; }
    .app-container.chat-active .chat-area { display: flex; }
    .app-container.chat-active .sidebar { display: none; }
    #mobile-back-btn { display: inline-block !important; background: transparent; color: var(--text-secondary); font-size: 1.5rem; padding: 0 10px 0 0; }
    .chat-input-area { position: sticky; bottom: 0; }
}

.hidden { display: none !important; }

/* =========================================
   9. CONTACTS PAGE
   ========================================= */
.contacts-container {
    width: 450px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 50px;
    /* Damit es nicht am oberen Rand klebt, wenn man nicht den flex-center Body nutzt,
       oder als Zusatzabstand auf Mobile */
    margin-top: 30px; 
}

.card {
    background: var(--bg-app);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px var(--shadow-soft);
    border: 1px solid var(--border-color);
}

.card h3 {
    margin-top: 0;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.nav-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: bold;
    display: inline-block;
    margin-bottom: 10px;
}

/* Alerts */
.alert {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
    font-size: 0.9em;
}
.alert.success {
    background: var(--alert-success-bg);
    color: var(--alert-success-text);
    border: 1px solid var(--alert-success-border);
}
.alert.error {
    background: var(--alert-error-bg);
    color: var(--alert-error-text);
    border: 1px solid var(--alert-error-border);
}

/* Code Box */
.code-display {
    font-family: monospace;
    font-size: 1.5em;
    text-align: center;
    background: var(--bg-header);
    padding: 15px;
    letter-spacing: 2px;
    border-radius: 5px;
    margin: 15px 0;
    border: 1px dashed var(--border-color);
    color: var(--text-main);
    user-select: all;
}

.btn-small {
    font-size: 0.8em;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    cursor: pointer;
    border-radius: 3px;
    color: var(--text-secondary);
}
.btn-small:hover {
    background: var(--bg-header);
}

/* Forms */
.add-form { display: flex; gap: 10px; }
.add-form input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--bg-input);
    color: var(--text-main);
}
.add-form button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}
.add-form button:hover { background: var(--primary-hover); }

/* Contact List Rows */
.contact-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: inherit;
    transition: background-color 0.1s;
}
.contact-row:last-child { border-bottom: none; }
.contact-row:hover { background-color: var(--bg-header); }

.contact-name { flex: 1; font-weight: 500; color: var(--text-main); }
.chat-icon { color: var(--primary); font-size: 1.2em; }

.tick-icon {
    font-size: 0.75rem;
    display: inline-block;
    /* width: 30px; /* Platz reservieren damit es nicht springt */
}

/* Vorschauleiste über dem Input */
.reply-preview {
    background: rgba(0,0,0,0.05);
    border-left: 4px solid var(--primary);
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(5px);
    margin: 0 10px; /* Kleiner Abstand zu den Rändern */
    border-radius: 5px 5px 0 0;
}

/* Das Zitat IN der Nachricht */
.quoted-msg-bubble {
    background: rgba(0,0,0,0.06);
    border-left: 4px solid var(--primary); /* Grüner Balken wie bei WhatsApp */
    padding: 5px 8px;
    border-radius: 4px;
    margin-bottom: 5px;
    font-size: 0.85em;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.quoted-author {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 2px;
}

/* Button zum Antworten an jeder Nachricht */
.btn-reply-action {
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    font-size: 1.2em;
    margin-left: 5px;
    color: var(--text-secondary);
    background: none;
    padding: 0;
}

/* Button anzeigen beim Hovern (Desktop) */
.msg-row:hover .btn-reply-action {
    opacity: 1;
}

/* Auf Mobile immer leicht sichtbar oder via Touch bedienbar */
@media (max-width: 768px) {
    .btn-reply-action { opacity: 0.5; }
}