:root {
    color-scheme: dark;
    --bg: #0b141a;
    --panel: #111b21;
    --panel-2: #1f2c34;
    --panel-3: #202c33;
    --border: #2a3942;
    --text: #e9edef;
    --muted: #8696a0;
    --accent: #25d366;
    --accent-2: #128c7e;
    --success: #25d366;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', sans-serif; background: linear-gradient(135deg, var(--bg), #111a20); color: var(--text); min-height: 100vh; }
button, input, textarea { font: inherit; }

.app-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-panel { width: min(460px, 100%); }
.brand-mark { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.brand-mark h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.brand-mark p { margin: 2px 0 0; color: var(--muted); }
.brand-logo-wrap { justify-content: center; margin-bottom: 22px; }
.brand-logo { width: 120px; height: 120px; display: block; object-fit: contain; margin: 0 auto; }
.brand-badge { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 700; font-size: 1.15rem; box-shadow: 0 10px 30px rgba(37, 211, 102, .22); }
.brand-mark.compact .brand-badge { width: 38px; height: 38px; border-radius: 12px; font-size: 0.95rem; }
.auth-card, .sidebar, .main-panel { background: rgba(17, 27, 33, .95); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .24); }
.auth-card { padding: 28px; }
.auth-card h2 { margin-bottom: 8px; font-size: 1.45rem; }
.muted { color: var(--muted); }
.form-control { background: var(--panel-3); border: 1px solid var(--border); color: var(--text); }
.form-control:focus { background: var(--panel-3); color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 0.2rem rgba(37, 211, 102, .18); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.btn-primary:hover { filter: brightness(1.04); }
.btn-outline-light { border-color: var(--border); color: var(--text); }
.btn-outline-light:hover { background: var(--panel-2); color: var(--text); }

.chat-page { padding: 20px; }
.chat-shell { display: grid; grid-template-columns: 320px 1fr; gap: 20px; min-height: calc(100vh - 40px); height: calc(100vh - 40px); }
.sidebar { padding: 20px; display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.sidebar-top { display: flex; flex-direction: column; gap: 14px; flex-shrink: 0; }
.stat-card { padding: 12px 14px; border-radius: 14px; background: var(--panel-3); display: flex; justify-content: space-between; align-items: center; }
.stat-label { color: var(--muted); }
.section-title { font-size: .82rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-bottom: 10px; }
.member-list { display: flex; flex-direction: column; gap: 8px; padding-right: 4px; overflow-y: auto; flex: 1; min-height: 0; }
.member-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: rgba(255,255,255,.02); border-radius: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--success); }
.dot.offline { background: var(--muted); }
.main-panel { display: flex; flex-direction: column; overflow: hidden; height: 100%; }
.chat-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: linear-gradient(90deg, rgba(37, 211, 102, .08), transparent); flex-shrink: 0; }
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-header h2 { margin: 0; font-size: 1.1rem; }
.chat-header p { margin: 3px 0 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.mobile-sidebar-toggle { display: none; width: 42px; height: 42px; border: 1px solid var(--border); background: var(--panel-3); color: var(--text); border-radius: 50%; align-items: center; justify-content: center; cursor: pointer; }
.search-input { background: var(--panel-3); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 7px 12px; min-width: 180px; }
.pill { padding: 7px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: .82rem; }
.clear-chat-btn { border: 1px solid var(--border); background: var(--panel-3); color: var(--text); padding: 7px 10px; border-radius: 999px; font-size: .82rem; }
.clear-chat-btn:hover { background: var(--panel-2); }
.typing-indicator { min-height: 22px; color: var(--muted); padding: 0 24px; font-size: .86rem; }
.conversation { flex: 1; padding: 22px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; background: radial-gradient(circle at top, rgba(37, 211, 102, .05), transparent 30%); min-height: 0; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; }
.message-bubble { max-width: min(74%, 560px); padding: 12px 14px; border-radius: 16px; background: var(--panel-3); border: 1px solid var(--border); align-self: flex-start; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.message-bubble.own { align-self: flex-end; background: linear-gradient(135deg, rgba(37, 211, 102, .24), rgba(18, 140, 126, .2)); border-color: rgba(37, 211, 102, .25); }
.message-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .76rem; margin-bottom: 6px; align-items: center; }
.message-user { display: flex; align-items: center; gap: 8px; }
.avatar, .avatar-mini { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .82rem; color: white; }
.message-content { white-space: pre-wrap; line-height: 1.5; }
.message-image { width: 100%; max-width: 280px; border-radius: 12px; margin-top: 8px; object-fit: cover; }
.message-actions { display: none; gap: 8px; margin-top: 8px; }
.message-bubble.active .message-actions,
.message-bubble.own:hover .message-actions { display: flex; }
.message-action { border: 1px solid var(--border); background: transparent; color: var(--text); padding: 3px 8px; border-radius: 999px; font-size: .76rem; }
.reactions { display: flex; gap: 8px; margin-top: 8px; }
.reaction-chip { border: 1px solid var(--border); background: transparent; color: var(--text); padding: 4px 7px; border-radius: 999px; font-size: .8rem; }
.reaction-chip.active { background: rgba(37, 211, 102, .18); border-color: rgba(37, 211, 102, .35); }
.read-status { font-size: .74rem; color: var(--muted); margin-top: 6px; text-align: right; }
.composer { border-top: 1px solid var(--border); padding: 14px 18px 18px; position: relative; background: var(--panel); }
#messageForm { display: flex; gap: 10px; align-items: center; }
.attach-btn, .emoji-btn { width: 42px; height: 42px; border: 1px solid var(--border); background: var(--panel-3); border-radius: 12px; color: var(--text); display: grid; place-items: center; cursor: pointer; }
.emoji-picker { position: absolute; bottom: 88px; left: 20px; display: flex; gap: 8px; padding: 10px; background: var(--panel-3); border: 1px solid var(--border); border-radius: 14px; }
.emoji-option { border: none; background: transparent; font-size: 1.2rem; cursor: pointer; }
.image-preview { margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.image-preview img { width: 80px; height: 80px; object-fit: cover; border-radius: 12px; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.2); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--panel-3); border: 1px solid var(--border); color: var(--text); padding: 12px 14px; border-radius: 12px; box-shadow: 0 18px 32px rgba(0,0,0,.24); z-index: 50; }
.voice-call-panel { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(17,27,33,.96); border: 1px solid var(--border); padding: 14px 16px; border-radius: 14px; display: flex; align-items: center; gap: 12px; z-index: 60; box-shadow: 0 20px 45px rgba(0,0,0,.25); }
.voice-call-btn { font-size: .72rem; padding: 3px 8px; }
#voiceCallActions { display: flex; gap: 8px; }
.app-footer { text-align: center; padding: 16px; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--border); }
.app-footer a { color: var(--accent); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

@media (max-width: 920px) {
    .chat-shell { grid-template-columns: 1fr; height: auto; min-height: auto; }
    .sidebar { order: 2; max-height: 320px; }
    .main-panel { order: 1; min-height: 70vh; }
    .header-actions { flex-wrap: wrap; width: 100%; justify-content: flex-end; }
    .chat-header { padding: 16px 18px; align-items: flex-start; gap: 10px; }
    .conversation { min-height: 320px; }
}

@media (max-width: 640px) {
    .app-shell, .chat-page { padding: 0; }
    .auth-card, .sidebar, .main-panel { border-radius: 0; }
    .auth-card { padding: 20px; }
    .chat-shell { gap: 0; min-height: 100vh; }
    .sidebar { position: fixed; inset: 0 0 0 0; z-index: 80; width: 86vw; max-width: 320px; transform: translateX(-100%); transition: transform .25s ease; border-radius: 0; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); height: 100dvh; max-height: 100dvh; }
    .sidebar.open { transform: translateX(0); }
    .mobile-sidebar-toggle { display: inline-flex; }
    .chat-header { flex-direction: row; align-items: center; gap: 10px; padding: 12px 14px; }
    .chat-header h2 { font-size: 1rem; }
    .chat-header p { font-size: .84rem; }
    .header-actions { justify-content: stretch; }
    .search-input, .clear-chat-btn { width: 100%; }
    .conversation { padding: 14px; gap: 10px; background: linear-gradient(180deg, rgba(37,211,102,.04), transparent 20%); }
    .message-bubble { max-width: 88%; width: auto; padding: 10px 12px; border-radius: 14px; }
    .message-bubble.own { max-width: 88%; }
    .message-meta { font-size: .72rem; }
    #messageForm { flex-wrap: nowrap; gap: 8px; }
    .attach-btn, .emoji-btn, #messageForm button[type="submit"] { width: 42px; height: 42px; }
    #messageForm button[type="submit"] { width: auto; min-width: 72px; padding: 0 14px; }
    .composer { padding: 10px; position: sticky; bottom: 0; }
    .emoji-picker { left: 10px; right: 10px; bottom: 90px; flex-wrap: wrap; }
    .member-item { padding: 10px; }
    .voice-call-panel { left: 8px; right: 8px; bottom: 8px; transform: none; width: auto; justify-content: space-between; flex-wrap: wrap; }
    .toast { left: 8px; right: 8px; bottom: 8px; }
}
