/**
 * ============================================================
 * styles.css — Estilos Globales v2.2
 * ============================================================
 * Tema oscuro WhatsApp con split-panel layout:
 *   Sidebar (sesiones) | Chat Panel | Messages Panel
 * ============================================================
 */

/* ==================== VARIABLES ==================== */
:root {
    --bg-primary: #0b141a;
    --bg-secondary: #111b21;
    --bg-tertiary: #1f2c34;
    --bg-hover: #2a3942;
    --bg-active: #233138;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --accent: #00a884;
    --accent-hover: #06cf9c;
    --accent-dark: #025144;
    --danger: #ea4335;
    --danger-hover: #ff5546;
    --border: #233138;
    --bubble-out: #005c4b;
    --bubble-out-darker: #004a3d;
    --bubble-in: #202c33;
    --shadow: rgba(0, 0, 0, 0.35);
    --radius: 10px;
    --radius-lg: 16px;
    --sidebar-width: 280px;
    --chat-panel-width: 340px;
    --header-height: 56px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ==================== RESET ==================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

input,
button {
    font-family: inherit;
}

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

/* ==================== LOGIN PAGE ==================== */
.login-body {
    background: linear-gradient(135deg, #0b141a 0%, #111b21 50%, #0b3d2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    position: relative;
    padding: 15px;
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: rgba(17, 27, 33, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 168, 132, 0.15);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 80px rgba(0, 168, 132, 0.08);
    animation: cardAppear 0.6s ease-out;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: white;
    box-shadow: 0 8px 24px rgba(0, 168, 132, 0.3);
}

.login-logo h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 6px;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.15);
}

.btn-login {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    margin-top: 8px;
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 168, 132, 0.35);
}

.btn-register {
    background: linear-gradient(135deg, #1f8e6e, var(--accent));
}

.auth-toggle {
    text-align: center;
    margin-top: 20px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.auth-error {
    text-align: center;
    padding: 10px;
    margin-top: 16px;
    background: rgba(234, 67, 53, 0.15);
    border: 1px solid rgba(234, 67, 53, 0.3);
    border-radius: var(--radius);
    color: #ff6b6b;
    font-size: 0.88rem;
    display: none;
}

.auth-error.show {
    display: block;
    animation: shake 0.4s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0)
    }

    25% {
        transform: translateX(-6px)
    }

    75% {
        transform: translateX(6px)
    }
}

.login-bg-circle {
    position: fixed;
    border-radius: 50%;
    opacity: 0.06;
    pointer-events: none;
    background: radial-gradient(circle, var(--accent), transparent);
}

.c1 {
    width: 500px;
    height: 500px;
    top: -150px;
    right: -100px;
}

.c2 {
    width: 400px;
    height: 400px;
    bottom: -100px;
    left: -100px;
}

.c3 {
    width: 250px;
    height: 250px;
    top: 40%;
    left: 60%;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo h1 {
    font-size: 1rem;
    font-weight: 700;
}

.btn-logout {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-logout:hover {
    color: var(--danger);
    background: rgba(234, 67, 53, 0.1);
}

/* ==================== WORKSPACE SELECTOR ==================== */
.workspace-selector {
    padding: 6px 10px;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.workspace-current {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
    color: var(--text-primary);
}

.workspace-current:hover {
    background: var(--bg-hover);
}

.workspace-current .chevron {
    margin-left: auto;
    opacity: 0.5;
}

.workspace-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 10px;
    right: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 30px var(--shadow);
    z-index: 9999;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}

.workspace-dropdown.show {
    display: block;
    animation: fadeSlideDown 0.2s;
}

@keyframes fadeSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ws-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}

.ws-item:hover {
    background: var(--bg-hover);
}

.ws-item.active {
    background: var(--accent-dark);
}

.ws-item-info {
    display: flex;
    flex-direction: column;
}

.ws-item-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.ws-item-count {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.ws-empty {
    padding: 14px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.ws-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
}

.ws-item:hover .ws-delete-btn {
    opacity: 1;
}

.ws-delete-btn:hover {
    color: var(--danger);
    background: rgba(234, 67, 53, 0.1);
}

.ws-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 1px dashed var(--border);
    background: none;
    color: var(--accent);
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.82rem;
    margin-top: 4px;
    transition: all 0.2s;
}

.ws-add-btn:hover {
    background: var(--accent-dark);
    border-color: var(--accent);
}

/* ==================== BTN ADD ACCOUNT ==================== */
.btn-add {
    margin: 8px 10px;
    padding: 9px 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    transition: all 0.2s;
}

.btn-add:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 168, 132, 0.3);
}

/* ==================== SESSIONS LIST ==================== */
.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 6px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    position: relative;
}

.session-item:hover {
    background: var(--bg-hover);
}

.session-item.active {
    background: var(--bg-active);
}

.session-item .avatar {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.session-item .avatar.connected {
    background: var(--accent-dark);
    color: var(--accent-hover);
}

.session-item .info {
    flex: 1;
    min-width: 0;
}

.session-item .name {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item .phone {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.connected {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(0, 168, 132, 0.5);
}

.status-dot.disconnected {
    background: #666;
}

.status-dot.waiting_qr {
    background: #f0b429;
    animation: pulse 1.5s infinite;
}

.status-dot.initializing {
    background: #3b82f6;
    animation: pulse 1.5s infinite;
}

.status-dot.error,
.status-dot.auth_failed {
    background: var(--danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1)
    }

    50% {
        opacity: 0.5;
        transform: scale(1.3)
    }
}

.btn-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
}

.session-item:hover .btn-delete {
    opacity: 1;
}

.btn-delete:hover {
    color: var(--danger);
    background: rgba(234, 67, 53, 0.1);
}

.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.version {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.media-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.media-retry {
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: center;
    margin: 4px 0;
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.view.active {
    display: flex;
}

/* ==================== WELCOME VIEW ==================== */
.welcome {
    max-width: 500px;
    margin: auto;
    text-align: center;
    padding: 40px;
}

.welcome-icon {
    margin-bottom: 20px;
    color: var(--text-muted);
}

.welcome h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    font-weight: 300;
}

.welcome p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.btn-primary {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 168, 132, 0.3);
}

/* ==================== QR VIEW ==================== */
.qr-container {
    margin: auto;
    padding: 20px;
}

.qr-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    max-width: 440px;
    margin: auto;
    box-shadow: 0 12px 40px var(--shadow);
}

.qr-header {
    text-align: center;
    margin-bottom: 24px;
}

.qr-header h2 {
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.qr-header p {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.qr-display {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    margin-bottom: 24px;
}

.qr-display img {
    max-width: 260px;
    border-radius: 8px;
}

.qr-loading {
    text-align: center;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.qr-loading p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.qr-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.step-num {
    width: 28px;
    height: 28px;
    background: var(--accent-dark);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* ==================== CONVERSATION SPLIT LAYOUT ==================== */
.conversation-split {
    display: flex;
    flex: 1;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* --- Chat Panel (Left) --- */
.chat-panel {
    width: var(--chat-panel-width);
    min-width: var(--chat-panel-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-panel-header {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

.chat-panel-title {
    flex: 1;
    min-width: 0;
    margin: 0 10px;
}

.chat-panel-title h2 {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chats-phone {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
}

.chat-panel-search {
    padding: 8px 10px;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.chat-panel-search .search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.chat-panel-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    background: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.82rem;
    outline: none;
    transition: all 0.2s;
}

.chat-panel-search input:focus {
    border-color: var(--accent);
}

.chat-panel-search input::placeholder {
    color: var(--text-muted);
}

.chat-panel-list {
    flex: 1;
    overflow-y: auto;
}

/* Chat items (compact) */
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid rgba(134, 150, 160, 0.06);
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-active);
}

.chat-avatar-pic {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

.chat-avatar-pic span {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

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

.chat-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-last-msg {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-meta {
    text-align: right;
    flex-shrink: 0;
}

.chat-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-unread {
    background: var(--accent);
    color: white;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    display: inline-block;
}

/* --- Messages Panel (Right) --- */
.messages-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
}

/* Empty state */
.messages-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    background-image:
        radial-gradient(circle at 20% 30%, rgba(0, 168, 132, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 168, 132, 0.02) 0%, transparent 50%);
}

.messages-empty-content {
    text-align: center;
    padding: 40px;
}

.messages-empty-content h3 {
    font-size: 1.2rem;
    font-weight: 300;
    margin-top: 16px;
    color: var(--text-secondary);
}

.messages-empty-content p {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 8px;
}

/* Active chat view */
.messages-active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.messages-header {
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

.messages-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-active);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

.messages-header-avatar span {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.messages-header-info {
    flex: 1;
    min-width: 0;
}

.messages-header-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.messages-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.messages-header-badge {
    padding: 3px 10px;
    background: rgba(0, 168, 132, 0.12);
    border: 1px solid rgba(0, 168, 132, 0.25);
    border-radius: 12px;
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 500;
    white-space: nowrap;
}

/* Messages list */
.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 14px 60px;
    background: var(--bg-primary);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(0, 168, 132, 0.025) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(0, 168, 132, 0.015) 0%, transparent 50%);
}

/* Date divider */
.date-divider {
    text-align: center;
    margin: 18px 0 12px;
}

.date-divider span {
    background: rgba(31, 44, 52, 0.92);
    padding: 5px 14px;
    border-radius: 8px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: capitalize;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ==================== MESSAGE BUBBLES (premium) ==================== */
.message-bubble {
    max-width: 65%;
    padding: 6px 8px 4px;
    margin: 2px 0;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: msgAppear 0.12s ease-out;
    width: fit-content;
}

@keyframes msgAppear {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
}

.message-bubble.outgoing {
    background: var(--bubble-out);
    margin-left: auto;
    border-top-right-radius: 2px;
}

.message-bubble.outgoing+.message-bubble.outgoing {
    border-top-right-radius: 8px;
}

.message-bubble.incoming {
    background: var(--bubble-in);
    margin-right: auto;
    border-top-left-radius: 2px;
}

.message-bubble.incoming+.message-bubble.incoming {
    border-top-left-radius: 8px;
}

.msg-time {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.45);
    text-align: right;
    margin-top: 2px;
    padding-left: 12px;
    display: flex;
    justify-content: flex-end;
    gap: 3px;
}

.message-bubble a {
    color: #53bdeb;
    word-break: break-all;
}

/* ==================== GROUP SENDER & MENTIONS ==================== */
.msg-sender {
    font-size: 0.73rem;
    font-weight: 700;
    margin-bottom: 2px;
    letter-spacing: 0.3px;
}

.mention-tag {
    background: rgba(83, 189, 235, 0.2);
    color: #53bdeb;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85em;
}

/* ==================== REVOKED (DELETED) MESSAGES ==================== */
.message-bubble.revoked {
    background: rgba(231, 76, 60, 0.12) !important;
    border-left: 3px solid #e74c3c;
    position: relative;
    opacity: 0.85;
}

.message-bubble.revoked>div:not(.msg-time):not(.revoked-badge):not(.media-container) {
    font-style: italic;
    color: var(--text-secondary);
}

.revoked-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.15);
    padding: 3px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    width: fit-content;
}

.revoked-badge::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #e74c3c;
    animation: revokedPulse 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes revokedPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

.message-bubble.revoked .msg-time {
    color: rgba(231, 76, 60, 0.6);
}

/* ==================== VIEW ONCE (TEMPORARY PHOTO) ==================== */
.view-once-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    width: fit-content;
}

.view-once-tag {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
    padding: 3px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    width: fit-content;
}

/* ==================== MEDIA IN MESSAGES ==================== */
.msg-image {
    max-width: 300px;
    max-height: 280px;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s;
    display: block;
    object-fit: cover;
    margin: 2px 0;
}

.msg-image:hover {
    transform: scale(1.02);
}

.msg-video {
    max-width: 320px;
    max-height: 260px;
    border-radius: 6px;
    background: #000;
    margin: 2px 0;
}

.msg-audio {
    width: 250px;
    max-width: 100%;
    height: 36px;
    filter: invert(1) hue-rotate(180deg) brightness(0.85);
}

.msg-caption {
    margin-top: 4px;
    font-size: 0.86rem;
    color: var(--text-primary);
}

.msg-file {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    transition: background 0.15s;
    min-width: 180px;
}

.msg-file:hover {
    background: rgba(255, 255, 255, 0.1);
}

.msg-doc-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.download-icon {
    font-size: 0.8rem;
    margin-left: auto;
}

/* Image full overlay */
.image-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: zoom-out;
    animation: fadeIn 0.2s;
}

.image-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 6px;
    object-fit: contain;
}

.img-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.img-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ==================== LOADING / EMPTY ==================== */
.loading-chats {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 160px;
    gap: 10px;
}

.loading-chats p {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 160px;
    color: var(--text-muted);
    font-size: 0.85rem;
    gap: 8px;
}

/* ==================== MODALS ==================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.2s;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 50px var(--shadow);
    animation: modalPop 0.3s;
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
}

.modal-sm {
    max-width: 360px;
}

.modal-header {
    padding: 20px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.modal-body {
    padding: 20px 24px;
}

.modal-body label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-field {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-field:focus {
    border-color: var(--accent);
}

.modal-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 12px;
}

.modal-footer {
    padding: 16px 24px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.btn-danger {
    padding: 10px 20px;
    background: var(--danger);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

/* ==================== TOAST ==================== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    padding: 10px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    font-size: 0.85rem;
    box-shadow: 0 8px 24px var(--shadow);
    animation: slideIn 0.3s;
    min-width: 200px;
}

.toast.error {
    border-left-color: var(--danger);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(60px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==================== MOBILE ==================== */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    box-shadow: 0 4px 12px var(--shadow);
}

/* ==================== MOBILE ELEMENTS (hidden on desktop) ==================== */
.btn-back-mobile {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-back-mobile:hover {
    background: var(--bg-hover);
}

.btn-menu-mobile {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-menu-mobile:hover {
    background: var(--bg-hover);
}

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

.mobile-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    box-shadow: 0 4px 12px var(--shadow);
}

/* ==================== TABLET (900px) ==================== */
@media (max-width: 900px) {
    .chat-panel {
        width: 280px;
        min-width: 280px;
    }

    .messages-list {
        padding: 12px 20px;
    }

    .message-bubble {
        max-width: 75%;
    }
}

/* ==================== MOBILE (768px) ==================== */
@media (max-width: 768px) {

    /* Sidebar slides out */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: 12px 0 40px var(--shadow);
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open~.sidebar-overlay {
        display: block;
    }

    /* Support workspace dropdown overflowing outside sidebar on small screens */
    .sidebar.open {
        overflow: visible;
    }

    /* Show mobile buttons */
    .btn-back-mobile {
        display: flex;
    }

    .btn-menu-mobile {
        display: flex;
    }

    /* Show desktop mobile toggle only when NOT in chat panel (used on Welcome/QR views) */
    .mobile-toggle {
        display: flex;
    }

    /* Hide the global floating toggle when chat-panel is active to avoid double buttons */
    #conversationView.active~.mobile-toggle,
    .view.active#conversationView~.mobile-toggle {
        display: none !important;
        /* Managed by .btn-menu-mobile inside chat panel header */
    }

    /* Conversation split: full-screen panels that swap via display */
    .conversation-split {
        flex-direction: column;
        position: relative;
    }

    /* Chat panel: shows by default on mobile, full screen */
    .chat-panel {
        width: 100%;
        min-width: 100%;
        flex: 1;
        border-right: none;
        display: flex;
    }

    /* Messages panel: hidden by default on mobile */
    .messages-panel {
        display: none;
        width: 100%;
        flex: 1;
    }

    /* When a chat is open: hide chat list, show messages full screen */
    .conversation-split.chat-open .chat-panel {
        display: none;
    }

    .conversation-split.chat-open .messages-panel {
        display: flex;
    }

    /* Messages area adjustments */
    .messages-list {
        padding: 10px 12px;
    }

    .message-bubble {
        max-width: 88%;
        font-size: 0.92rem;
    }

    .messages-header {
        padding: 8px 12px;
    }

    /* Chat items: larger tap targets */
    .chat-item {
        padding: 12px 14px;
    }

    .chat-avatar-pic {
        width: 48px;
        height: 48px;
    }

    .chat-name {
        font-size: 0.95rem;
    }

    /* Search */
    .chat-panel-search input {
        padding: 10px 12px 10px 38px;
        font-size: 0.88rem;
    }

    /* Welcome text */
    .welcome {
        padding: 30px 20px;
    }

    .welcome h2 {
        font-size: 1.2rem;
    }

    /* QR adjustments */
    .qr-card {
        padding: 24px 18px;
    }

    .qr-display {
        min-height: 220px;
        padding: 16px;
    }

    .qr-display img {
        max-width: 200px;
    }

    /* Modals */
    .modal {
        width: 95%;
        max-width: 360px;
    }

    /* Image overlay */
    .image-overlay img {
        max-width: 95vw;
        max-height: 85vh;
    }

    /* Media in messages */
    .msg-image {
        max-height: 220px;
    }

    .msg-video {
        max-height: 200px;
    }

    .msg-audio {
        max-width: 220px;
    }
}

/* ==================== SMALL PHONES (480px) ==================== */
@media (max-width: 480px) {
    :root {
        --sidebar-width: 260px;
    }

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

    .messages-list {
        padding: 8px 8px;
    }

    .messages-header-badge {
        display: none;
    }

    .chat-panel-header {
        padding: 8px 10px;
    }

    .login-card {
        padding: 28px 20px;
    }

    .login-logo-icon {
        width: 56px;
        height: 56px;
    }

    .login-logo h1 {
        font-size: 1.3rem;
    }
}