/* Chat Page */
.chat-main {
    margin-top: 80px;
    min-height: calc(100vh - 80px);
    padding: 2rem 0;
    background:
        radial-gradient(circle at 0% 0%, rgba(74, 144, 226, 0.12), transparent 35%),
        linear-gradient(180deg, #f8fbff 0%, #f2f7ff 100%);
}

.chat-intro {
    text-align: center;
    margin-bottom: 1.5rem;
}

.chat-intro h1 {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    color: #1f2937;
    margin-bottom: 0.5rem;
}

.chat-intro p {
    color: #64748b;
}

.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1rem;
    min-height: 72vh;
}

.chat-sidebar {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.sidebar-card,
.chat-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.sidebar-head {
    padding: 1rem;
    border-bottom: 1px solid #eef2f7;
}

.sidebar-head h3 {
    font-size: 1rem;
    color: #334155;
}

.rooms-list,
.online-users {
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
}

.room-item {
    width: 100%;
    border: none;
    background: transparent;
    border-radius: 12px;
    text-align: left;
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.room-item:hover {
    background: #f1f5ff;
}

.room-item.active {
    background: #e9f2ff;
    border: 1px solid rgba(74, 144, 226, 0.25);
}

.room-item-main {
    min-width: 0;
}

.room-item-title {
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-item-desc {
    color: #64748b;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    align-self: center;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    line-height: 1;
    padding: 0.4rem 0.48rem;
    border-radius: 999px;
    font-weight: 600;
}

.online-user {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.6rem;
    border-radius: 10px;
}

.online-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.online-name {
    font-size: 0.9rem;
    color: #334155;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    min-height: 72vh;
}

.chat-header-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #eef2f7;
}

.chat-header-panel h2 {
    font-size: 1.15rem;
    color: #1f2937;
}

.chat-header-panel p {
    color: #64748b;
    font-size: 0.9rem;
}

.chat-meta {
    font-size: 0.85rem;
    color: #4A90E2;
    background: #edf5ff;
    border-radius: 999px;
    padding: 0.4rem 0.7rem;
    white-space: nowrap;
}

.messages {
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    position: relative;
}

.message-row.mine {
    margin-left: auto;
    align-items: flex-end;
}

.message-bubble {
    border-radius: 14px;
    padding: 0.6rem 0.8rem;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

.message-reply-preview {
    font-size: 0.78rem;
    color: #475569;
    background: rgba(148, 163, 184, 0.14);
    border-left: 3px solid #94a3b8;
    border-radius: 8px;
    padding: 0.38rem 0.5rem;
    margin-bottom: 0.35rem;
}

.message-reply-preview strong {
    color: #334155;
}

.message-row.mine .message-bubble {
    background: #e9f2ff;
    border-color: rgba(74, 144, 226, 0.25);
}

.message-author {
    font-size: 0.78rem;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.message-text {
    color: #1f2937;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-text .mention {
    color: #2563eb;
    font-weight: 600;
    background: #e7f0ff;
    border-radius: 6px;
    padding: 0 0.2rem;
}

.message-time {
    margin-top: 0.25rem;
    font-size: 0.72rem;
    color: #94a3b8;
}

.message-actions {
    margin-top: 0.2rem;
    display: flex;
    gap: 0.35rem;
}

.msg-action {
    border: 1px solid #dbe5f1;
    background: #fff;
    color: #64748b;
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    cursor: pointer;
}

.msg-action:hover {
    border-color: #4A90E2;
    color: #4A90E2;
}

.replying-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    margin: 0.6rem 1rem 0;
    border: 1px solid #dbe5f1;
    background: #f8fbff;
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
}

.replying-content {
    min-width: 0;
    display: grid;
}

.replying-content strong {
    color: #334155;
    font-size: 0.82rem;
}

.replying-content span {
    color: #64748b;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.replying-close {
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
}

.chat-composer {
    align-items: center;
    grid-template-columns: auto 1fr auto;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border: 1px solid #dbe5f1;
    background: #fff;
    color: #64748b;
    border-radius: 50%;
    cursor: pointer;
}

.btn-icon:hover {
    border-color: #4A90E2;
    color: #4A90E2;
}

.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 1rem 0.6rem;
    padding: 0.55rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
}

.emoji-item {
    width: 32px;
    height: 32px;
    border: none;
    background: #f8fafc;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
}

.emoji-item:hover {
    background: #e9f2ff;
}

.chat-composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.65rem;
    padding: 0.9rem 1rem;
    border-top: 1px solid #eef2f7;
}

.chat-composer input {
    border: 2px solid #dbe5f1;
    border-radius: 999px;
    padding: 0.8rem 1rem;
    font-size: 0.95rem;
}

.chat-composer input:focus {
    outline: none;
    border-color: #4A90E2;
}

.chat-hint {
    color: #94a3b8;
    font-size: 0.8rem;
    padding: 0 1rem 1rem;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: #94a3b8;
}

.chat-empty i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.notification-toast {
    position: fixed;
    right: 20px;
    top: 95px;
    z-index: 9999;
    background: #111827;
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    opacity: 0;
    transform: translateY(-6px);
    transition: all 0.25s ease;
}

.notification-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.notification-toast.success { background: #16a34a; }
.notification-toast.error { background: #dc2626; }
.notification-toast.warning { background: #d97706; }

@media (max-width: 992px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        grid-template-columns: 1fr 1fr;
    }

    .rooms-list,
    .online-users {
        max-height: 240px;
    }
}

@media (max-width: 768px) {
    .chat-main {
        padding: 1rem 0;
    }

    .chat-sidebar {
        grid-template-columns: 1fr;
    }

    .chat-panel {
        min-height: 68vh;
    }

    .message-row {
        max-width: 92%;
    }

    .chat-header-panel {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 560px) {
    .chat-composer {
        grid-template-columns: auto 1fr;
    }

    .chat-composer .btn {
        grid-column: 1 / -1;
        width: 100%;
        justify-content: center;
    }
}
/* V3: Search, Images, Pins */
.chat-header-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.search-input {
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9rem;
    min-width: 180px;
}

.search-empty {
    text-align: center;
    color: #9ca3af;
    padding: 2rem;
}

.image-preview {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.75rem;
    background: #f3f4f6;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.image-preview img {
    max-height: 80px;
    max-width: 120px;
    border-radius: 6px;
    object-fit: cover;
}

.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    margin: 0.5rem 0;
    object-fit: cover;
}

.pinned-messages {
    background: #fff7ed;
    border-left: 4px solid #ea580c;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
}

.pinned-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #ea580c;
}

.pinned-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.pinned-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.5rem;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.pinned-item:hover {
    background: #fef3c7;
}

.pinned-sender {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.85rem;
}

.pinned-text {
    color: #6b7280;
    font-size: 0.85rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pinned-marker {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ea580c;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
}

.message-row {
    position: relative;
}

.btn-icon-small {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.btn-icon-small:hover {
    color: #1f2937;
}