:root {
    --bg-color: #f4f4f9;
    --text-color: #333;
    --card-bg: #fff;
    --border-color: #ddd;
    --primary-color: #007bff;
    --danger-color: #dc3545;
    --bubble-self: #d1e7dd;
    --bubble-other: #e2e3e5;
    --header-bg: #fff;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --border-color: #333;
    --primary-color: #3f8cff;
    --danger-color: #ff5e5e;
    --bubble-self: #004d40;
    --bubble-other: #424242;
    --header-bg: #1e1e1e;
}

* { box-sizing: border-box; font-family: sans-serif; }

body { 
    margin: 0; 
    background: var(--bg-color); 
    color: var(--text-color); 
    height: 100dvh; 
    overflow: hidden; 
}

.view { display: none; height: 100%; flex-direction: column; align-items: center; justify-content: center; }
.view.active { display: flex; }

/* Setup & Join Cards */
.card {
    background: var(--card-bg); padding: 30px; border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); width: 100%; max-width: 400px;
    text-align: center; border: 1px solid var(--border-color);
}
input {
    width: 100%; padding: 10px; margin: 10px 0; border: 1px solid var(--border-color);
    border-radius: 4px; background: var(--bg-color); color: var(--text-color);
}
button {
    padding: 10px 15px; border: none; border-radius: 4px; background: var(--primary-color);
    color: white; cursor: pointer; font-weight: bold; width: 100%; margin-top: 5px;
}
button:hover { opacity: 0.9; }
button.danger { background: var(--danger-color); }

/* Chat Layout */
#chat-view { 
    width: 100%; height: 100%; 
    align-items: stretch; justify-content: flex-start; 
    position: relative;
}

header {
    flex-shrink: 0; 
    display: flex; flex-direction: column; gap: 10px;
    padding: 10px 20px; background: var(--header-bg); border-bottom: 1px solid var(--border-color);
}
.header-controls {
    display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 8px;
}
.header-controls button { width: auto; margin: 0; padding: 6px 12px; font-size: 0.85rem; flex: 1 1 auto; }
.header-status { font-size: 0.9rem; align-self: flex-start; }

main#chat-container {
    flex: 1 1 auto; 
    overflow-y: auto; 
    padding: 20px; display: flex; flex-direction: column;
    transition: filter 0.3s;
}
main#chat-container.blurred { filter: blur(8px); pointer-events: none; }

#messages { display: flex; flex-direction: column; gap: 10px; }

.message {
    max-width: 80%; padding: 10px 15px; border-radius: 12px;
    word-wrap: break-word; position: relative; cursor: pointer;
    transition: background-color 0.2s;
}
.message:active { filter: brightness(0.9); }
.message.self { align-self: flex-end; background: var(--bubble-self); border-bottom-right-radius: 2px; }
.message.other { align-self: flex-start; background: var(--bubble-other); border-bottom-left-radius: 2px; }
.message-header { font-size: 0.75rem; font-weight: bold; margin-bottom: 4px; opacity: 0.8; }
.message-status { font-size: 0.7rem; float: right; margin-top: 5px; opacity: 0.7; margin-left: 10px; }

/* Metadata Panel (Time / Seen By / Sent To) */
.message-details {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(128,128,128,0.3);
    font-size: 0.75rem;
    opacity: 0.8;
    line-height: 1.4;
}
.message-details.hidden { display: none; }
.recipient-list { font-style: italic; }

footer { 
    flex-shrink: 0; 
    padding: 15px; background: var(--header-bg); border-top: 1px solid var(--border-color); 
}
textarea {
    width: 100%; height: 60px; resize: none; padding: 10px;
    border: 1px solid var(--border-color); border-radius: 4px;
    background: var(--bg-color); color: var(--text-color);
    font-size: 16px;
}

/* Scroll Button */
#scroll-to-bottom {
    position: absolute;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px; 
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border-radius: 50%;
    font-size: 1.2rem;
    z-index: 10;
    transition: opacity 0.2s;
}
#scroll-to-bottom.hidden { display: none; }

/* Modals */
.modal-bg {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-bg.hidden { display: none; }
.modal-card { background: var(--card-bg); padding: 25px; border-radius: 8px; max-width: 400px; width: 90%; text-align: center; }
#modal-actions { margin-top: 20px; display: flex; justify-content: center; gap: 10px; }
.share-input-group input { text-align: center; font-family: monospace; font-size: 0.9rem; }
