/* ########## ALLGEMEIN ########## */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #333; /* Fallback */
    color: #fff;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ########## CHAT-LAYOUT ########## */
.chat-layout {
    display: flex;
    width: 100%;
    height: 100%;
    background-color: #111;
}

/* ########## 1. SIDEBAR (LINKS) ########## */
.chat-sidebar {
    width: 300px;
    background-color: #222;
    border-right: 1px solid #444;
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid #444;
}
.header-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
}
#search-input {
    flex-grow: 1;
    padding: 8px 12px;
    background-color: #444;
    border: 1px solid #555;
    border-radius: 20px;
    color: #fff;
}
#new-chat-btn {
    background-color: #00aaff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 1.5rem;
    line-height: 28px;
    cursor: pointer;
}

.chat-list {
    flex-grow: 1;
    overflow-y: auto;
    margin-top: 10px;
}
/* Scrollbar-Styling (optional) */
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background-color: #444; border-radius: 3px; }

.chat-list-item {
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    transition: background-color 0.2s;
}
.chat-list-item:hover {
    background-color: #333;
}
.chat-list-item.active {
    background-color: #00aaff;
    font-weight: bold;
}
.chat-list-item.pinned {
    /* TODO: Styling für gepinnte Chats (z.B. Hintergrund) */
    background-color: #2a2a2a; 
}
.chat-list-item .pin-icon {
    font-size: 0.7rem;
    color: #fffc00;
    margin-left: auto;
    /* TODO: 'Gepinnt'-Icon (z.B. 📌) */
}

.chat-avatar img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}
.chat-info {
    flex-grow: 1;
    overflow: hidden; /* Verhindert Text-Umbruch-Probleme */
}
.chat-info-name {
    font-weight: bold;
    color: #fff;
}
.chat-list-item.active .chat-info-name {
    color: #fff;
}
.chat-info-lastmsg {
    font-size: 0.9rem;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-info-timestamp {
    font-size: 0.8rem;
    color: #888;
    margin-left: auto;
    white-space: nowrap;
}

/* Lade-Spinner */
.loading-spinner {
    border: 4px solid #444;
    border-top: 4px solid #00aaff;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ########## 2. CHAT-FENSTER (RECHTS) ########## */
.chat-window {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-image: url('../bg.webp'); /* Geht einen Ordner hoch (../) */
    background-size: cover;
    background-position: center;
}

.chat-header {
    padding: 10px 20px;
    background-color: rgba(0,0,0, 0.5);
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.2rem;
    font-weight: bold;
}
.chat-header-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}
.chat-header-actions {
    /* TODO: Icons für Anruf etc. */
}

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-color: rgba(0,0,0, 0.3); /* Dunkler Overlay für Lesbarkeit */
}
/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background-color: #555; border-radius: 4px; }

/* Platzhalter, wenn kein Chat aktiv ist */
.chat-placeholder {
    margin: auto;
    text-align: center;
    color: #aaa;
}

/* Chat-Blasen */
.message-bubble {
    max-width: 60%;
    padding: 10px 15px;
    border-radius: 20px;
    margin-bottom: 10px;
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    word-break: break-word;
}
.message-bubble strong { display: block; font-size: 0.8rem; margin-bottom: 2px; color: #ccc; }
.message-bubble span { margin-right: 10px; }

.message-bubble.other { background-color: #444; color: #fff; align-self: flex-start; }
.message-bubble.other strong { color: #00aaff; }

.message-bubble.self { background-color: #555; color: #fff; align-self: flex-end; flex-direction: row-reverse; }
.message-bubble.self strong { color: #fffc00; }
.message-bubble.self span { margin-right: 0; margin-left: 10px; }

/* Aktionen (Löschen/Bearbeiten) */
.msg-actions { display: flex; gap: 5px; }
.msg-actions button { background: none; border: none; color: #fff; cursor: pointer; font-size: 1rem; opacity: 0; transition: opacity 0.2s; }
.message-bubble.self:hover .msg-actions button { opacity: 0.7; }
.message-bubble.self .msg-actions button:hover { opacity: 1; }

/* Lesebestätigung (TODO) */
.read-receipt {
    font-size: 0.8rem;
    color: #aaa;
    align-self: flex-end; /* Nur für .self-Nachrichten */
    margin-top: -8px;
    margin-bottom: 10px;
    margin-right: 5px;
}
.read-receipt.read { color: #00aaff; }

/* Tipp-Anzeige (Punkte) */
.typing-indicator-container {
    padding-left: 20px;
    height: 30px;
    box-sizing: border-box;
    display: none; /* Wird von JS gesteuert */
    background-color: rgba(0,0,0, 0.3);
}
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}
.message-bubble.typing-indicator {
    padding: 10px 15px;
    margin-bottom: 0;
}
.message-bubble.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #aaa;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.message-bubble.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.message-bubble.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

/* Eingabe-Bereich */
.chat-input-area {
    padding: 15px;
    background-color: #222;
    border-top: 1px solid #444;
    display: flex;
}
#message-input {
    flex-grow: 1;
    padding: 12px;
    background-color: #444;
    border: 1px solid #555;
    border-radius: 20px;
    color: #fff;
    margin-right: 10px;
}
#message-input:disabled { background-color: #333; }
#send-button {
    padding: 12px 20px;
    background-color: #00aaff;
    border: none;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    cursor: pointer;
}
#send-button:disabled { background-color: #555; }

/* ########## 3. MODAL (Neuer Chat) ########## */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0, 0.7);
    display: none; /* Wird von JS gesteuert */
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal-content {
    background-color: #222;
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
}
#user-search-input {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 15px;
    background-color: #444;
    border: 1px solid #555;
    border-radius: 5px;
    color: #fff;
}
#user-search-results {
    max-height: 300px;
    overflow-y: auto;
}
#close-modal-btn {
    margin-top: 15px;
    padding: 10px;
    width: 100%;
    background-color: #555;
    border: none;
    border-radius: 5px;
    color: white;
    cursor: pointer;
}