/* ── Chat layout ──────────────────────────────────────────── */

body.chat-page, html { height: 100%; overflow: hidden; }

.chat-page .layout { 
    height: calc(100dvh - 56px); 
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom); 
}

.chat-mobile-menu-btn { 
    display: none; 
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 10px;
    color: inherit;
}

@media (max-width: 640px) {
    .chat-mobile-menu-btn { 
        display: block; 
    }
}

.chat-page .main-content { padding: 0 !important; overflow: hidden !important; height: 100%; display: flex; flex-direction: column; }

.chat-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* ── Sidebar ── */

.chat-sidebar {
    width: 240px;
    min-width: 240px;
    background: #12151a;
    border-right: 1px solid #2a3040;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s;
}

.chat-sidebar-header {
    padding: 12px 14px 8px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3a5a7a;
    border-bottom: 1px solid #1e2530;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-sidebar-scroll { flex: 1; overflow-y: auto; padding: 6px 0; }

.chat-search-wrap { padding: 8px 10px; }

.chat-search-input {
    width: 100%;
    height: 30px;
    padding: 0 10px;
    background: #1a2535;
    border: 1px solid #2a3040;
    color: #eee;
    font-size: 0.8rem;
    font-family: inherit;
    border-radius: 4px;
    outline: none;
}
.chat-search-input:focus { border-color: #3a5a7a; }
.chat-search-input::placeholder { color: #3a5a7a; }

.chat-category { margin-bottom: 2px; }

.chat-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 14px 3px;
    cursor: pointer;
    user-select: none;
}

.chat-category-name {
    font-size: 0.71rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7585;
}

.chat-category-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.chat-category:hover .chat-category-actions { opacity: 1; }

.chat-icon-btn {
    background: none;
    border: none;
    color: #6b7585;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 5px;
    border-radius: 3px;
    line-height: 1;
}
.chat-icon-btn:hover { background: #2a3040; color: #cdd3db; }

.chat-channel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 14px;
    cursor: pointer;
    color: #6b7585;
    font-size: 0.87rem;
}
.chat-channel:hover { background: #1a2535; color: #cdd3db; }
.chat-channel.active { background: #1e2d42; color: #eee; }
.chat-channel-icon { font-size: 0.85rem; flex-shrink: 0; }
.chat-channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-ch-del { opacity: 0; transition: opacity 0.1s; }
.chat-channel:hover .chat-ch-del { opacity: 1; }

.dm-section { border-top: 1px solid #1e2530; padding-top: 6px; margin-top: 4px; }

.dm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 14px 3px;
}

.dm-channel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 14px;
    cursor: pointer;
    color: #6b7585;
    font-size: 0.85rem;
}
.dm-channel:hover { background: #1a2535; color: #cdd3db; }
.dm-channel.active { background: #1e2d42; color: #eee; }

/* ── Speaker picker ── */

.active-speaker-bar {
    padding: 10px 12px;
    border-top: 1px solid #1e2530;
    background: #0d1117;
    position: relative;
}

.active-speaker-label {
    font-size: 0.67rem;
    color: #3a5a7a;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 5px;
}

.speaker-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1a2535;
    border: 1px solid #2a3040;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    transition: border-color 0.15s;
}
.speaker-picker:hover { border-color: #508dc7; }

.speaker-name {
    flex: 1;
    font-size: 0.82rem;
    color: #cdd3db;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.speaker-chevron { color: #3a5a7a; font-size: 0.7rem; }

.speaker-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #1a1e26;
    border: 1px solid #2a3040;
    border-radius: 6px;
    margin-bottom: 4px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}
.speaker-dropdown.open { display: block; }

.speaker-section-label {
    padding: 7px 12px 3px;
    font-size: 0.67rem;
    color: #3a5a7a;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.speaker-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #cdd3db;
}
.speaker-option:hover { background: #1e2d42; }
.speaker-option.active { background: #1e2d42; color: #eee; }

/* ── Main chat ── */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #1a1e26;
}

.chat-topbar {
    padding: 10px 18px;
    border-bottom: 1px solid #2a3040;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1a1e26;
    flex-shrink: 0;
}

.chat-topbar-icon { color: #3a5a7a; font-size: 1rem; }
.chat-topbar-name { font-size: 0.93rem; font-weight: 600; color: #eee; }
.chat-topbar-desc { font-size: 0.78rem; color: #3a5a7a; margin-left: 4px; }

.chat-mobile-menu-btn { 
    display: none; 
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 10px;
    color: inherit;
}

/* ── Messages ── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chat-msg {
    display: flex;
    gap: 12px;
    padding: 3px 6px;
    border-radius: 4px;
}
.chat-msg:hover { background: #1e2530; margin: 0 -6px; padding: 3px 6px; }

.chat-msg-av {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg-av-ph {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg-body { flex: 1; min-width: 0; }

.chat-msg-hdr {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.chat-msg-name { font-size: 0.87rem; font-weight: 600; }
.chat-msg-time { font-size: 0.71rem; color: #3a5a7a; }
.chat-msg-text { font-size: 0.87rem; color: #cdd3db; line-height: 1.5; word-break: break-word; }

.chat-msg-cont {
    padding: 1px 6px 1px 52px;
    border-radius: 4px;
}
.chat-msg-cont:hover { background: #1e2530; margin: 0 -6px; padding: 1px 6px 1px 52px; }

.chat-msg-del {
    opacity: 0;
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 0.72rem;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.chat-msg:hover .chat-msg-del,
.chat-msg-cont:hover .chat-msg-del { opacity: 1; }

/* ── Input area ── */

.chat-input-area { padding: 8px 18px 14px; flex-shrink: 0; }

.quick-swap-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.quick-swap-btn {
    background: #1a2535;
    border: 1px solid #2a3040;
    border-radius: 50%;
    padding: 2px;
    cursor: pointer;
    transition: border-color 0.15s;
    line-height: 0;
}
.quick-swap-btn:hover { border-color: #508dc7; }
.quick-swap-btn.active { border-color: #508dc7; background: #1e2d42; }

.chat-input-box {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #12151a;
    border: 1px solid #2a3040;
    border-radius: 6px;
    padding: 8px 12px;
    transition: border-color 0.15s;
}
.chat-input-box:focus-within { border-color: #3a5a7a; }

.chat-textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: #eee;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    min-height: 22px;
    max-height: 140px;
    line-height: 1.5;
}
.chat-textarea::placeholder { color: #3a5a7a; }

.chat-send-btn {
    background: #508dc7;
    border: none;
    color: #fff;
    border-radius: 4px;
    padding: 5px 14px;
    cursor: pointer;
    font-size: 0.84rem;
    font-family: inherit;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.chat-send-btn:hover { opacity: 0.85; }

/* ── Empty state ── */

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #3a5a7a;
    gap: 10px;
    text-align: center;
    padding: 40px;
}
.chat-empty-icon { font-size: 2.2rem; }
.chat-empty-title { font-size: 0.95rem; color: #6b7585; }

/* ── Modals ── */

.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
}
.chat-modal-overlay.open { display: flex; }

.chat-modal {
    background: #1a1e26;
    border: 1px solid #2a3040;
    border-radius: 8px;
    padding: 22px;
    width: 360px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-modal-title { font-size: 0.98rem; font-weight: 600; color: #eee; }
.chat-modal-label { font-size: 0.76rem; color: #6b7585; margin-bottom: 4px; }

.chat-modal input,
.chat-modal select {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    background: #12151a;
    border: 1px solid #2a3040;
    color: #eee;
    font-size: 0.87rem;
    font-family: inherit;
    border-radius: 4px;
    outline: none;
}
.chat-modal input:focus,
.chat-modal select:focus { border-color: #508dc7; }

.chat-modal-btns { display: flex; gap: 10px; justify-content: flex-end; }

.chat-btn-cancel {
    background: none;
    border: 1px solid #2a3040;
    color: #6b7585;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.84rem;
    font-family: inherit;
}
.chat-btn-cancel:hover { border-color: #3a5a7a; color: #cdd3db; }

.chat-btn-confirm {
    background: #508dc7;
    border: none;
    color: #fff;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.84rem;
    font-family: inherit;
}
.chat-btn-confirm:hover { opacity: 0.85; }

/* ── Mobile sidebar overlay ── */

.chat-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
}
.chat-sidebar-overlay.open { display: block; }

/* ── Mobile ── */

@media (max-width: 640px) {
    .chat-mobile-menu-btn { display: block; }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 0;
        z-index: 160;
        transform: translateX(-100%);
        width: 260px;
        min-width: 260px;
    }
    .chat-sidebar.mobile-open { transform: translateX(0); }
}

.chat-page .layout { 
    height: calc(100dvh - 56px); 
    overflow: hidden; 
}

.chat-mobile-menu-btn { 
    display: none; 
}

@media (max-width: 640px) {
    .chat-mobile-menu-btn { 
        display: block; 
        cursor: pointer;
    }
}