:root {
    --bg-main: #0B141A;
    --bg-surface: #202C33;
    --bg-card: #111B21;
    --bg-card-alt: #182229;
    --bg-hover: #202C33;
    --bg-active: #2A3942;
    --bg-input: #2A3942;
    --text-primary: #E9EDEF;
    --text-secondary: #8696A0;
    --text-muted: #667781;
    --accent: #00A884;
    --accent-hover: #008F6F;
    --accent-light: #0A332C;
    --bubble-sent: #005C4B;
    --bubble-received: #202C33;
    --bubble-sent-text: #E9EDEF;
    --bubble-received-text: #E9EDEF;
    --ticks-blue: #53BDEB;
    --danger: #EA4335;
    --danger-hover: #D93025;
    --success: #00A884;
    --border: #222D34;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

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

/* Sentinel Lockout Overlay */
.sentinel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 20, 26, 0.98);
    backdrop-filter: blur(16px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sentinel-box {
    background: #182229;
    border: 1px solid var(--danger);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 460px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(234, 67, 53, 0.25);
}

.sentinel-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.sentinel-box h2 {
    color: var(--danger);
    font-size: 20px;
    margin-bottom: 12px;
}

.sentinel-box p {
    color: #F8B4B4;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 24px;
}

/* Auth / Login Layout - WhatsApp Web Style */
.screen-container {
    width: 100%;
    height: 100%;
}

.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at 50% 30%, #111B21 0%, #0B141A 100%);
}

.login-steps {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: -12px 0 26px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #0A332C;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    padding: 38px 40px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.3s ease-out;
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.shield-logo {
    width: 48px;
    height: 48px;
    background: rgba(0, 168, 132, 0.15);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-badge span {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--accent);
}

.auth-card h2 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.auth-card .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 30px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 13px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    user-select: text;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 22px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    outline: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #FFFFFF;
}

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

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-block {
    width: 100%;
}

.alert {
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-top: 16px;
}

.alert-danger {
    background: rgba(234, 67, 53, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* Messenger Layout - WhatsApp Web Dark */
.messenger-layout {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 450px;
    min-width: 340px;
    max-width: 500px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    height: 66px;
    padding: 10px 18px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 14px;
    overflow: hidden;
}

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00A884 0%, #005C4B 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

.user-info {
    overflow: hidden;
}

.user-name {
    font-size: 15.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    font-size: 12.5px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

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

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

/* Quick Action Bar */
.chat-actions-bar {
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.action-btn:hover {
    background: var(--bg-active);
    border-color: var(--accent);
    color: var(--accent);
}

/* Filter Chips - WhatsApp Web Pill Style */
.chat-filter-chips {
    display: flex;
    gap: 8px;
    padding: 10px 18px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chip {
    padding: 6px 16px;
    border-radius: 18px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.chip:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.chip.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Chat Item List */
.chat-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-card);
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(34, 45, 52, 0.5);
    cursor: pointer;
    transition: background 0.15s;
}

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

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

.chat-item-info {
    flex: 1;
    overflow: hidden;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.chat-item-name {
    font-size: 15.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-item-snippet {
    font-size: 13.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

text-overflow: ellipsis;
}

.loading-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background-color: var(--bg-main);
    background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1.5px, transparent 1.5px);
    background-size: 24px 24px;
}

/* Network Banner */
.network-banner {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: #FF9800;
    color: #000;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #000;
    animation: pulse 1.2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.9);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
}

/* Empty State */
.empty-chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
}

.empty-icon {
    font-size: 54px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-chat-state h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-chat-state p {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 360px;
    line-height: 1.5;
}

/* Active Conversation Wrapper */
.active-chat-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.chat-header {
    height: 66px;
    padding: 10px 20px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 5;
}

.back-btn {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.active-chat-info {
    flex: 1;
    overflow: hidden;
}

.active-chat-title {
    font-size: 16.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.active-chat-subtitle {
    font-size: 12.5px;
    color: var(--accent);
    margin-top: 2px;
}

.active-chat-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-invite {
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.badge-invite:hover {
    background: var(--accent);
    color: #FFFFFF;
}

/* Messages Stream - WhatsApp Web Bubbles */
.messages-stream {
    flex: 1;
    overflow-y: auto;
    padding: 18px 28px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.messages-stream::-webkit-scrollbar {
    width: 6px;
}

.messages-stream::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.message-bubble {
    max-width: 68%;
    padding: 9px 14px 8px;
    font-size: 15px;
    line-height: 1.48;
    word-break: break-word;
    user-select: text;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.15);
    position: relative;
    animation: popIn 0.15s ease-out;
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--bubble-sent);
    color: var(--bubble-sent-text);
    border-radius: 10px 10px 2px 10px;
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--bubble-received);
    color: var(--bubble-received-text);
    border-radius: 10px 10px 10px 2px;
}

.sender-tag {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 2px;
}

.message-text {
    user-select: text;
    font-size: 15px;
    line-height: 1.5;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--text-secondary);
}

.message-bubble.sent .message-meta span:last-child {
    color: var(--ticks-blue);
    font-weight: bold;
    letter-spacing: -1px;
}

/* Chat Input Bar - WhatsApp Web Capsule */
.chat-input-bar {
    height: 68px;
    padding: 10px 20px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

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

.chat-input-bar textarea {
    flex: 1;
    height: 46px;
    max-height: 130px;
    background: var(--bg-input);
    border: none;
    border-radius: 10px;
    padding: 12px 18px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    resize: none;
    user-select: text;
    transition: background 0.2s;
}

.chat-input-bar textarea::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--accent);
    color: #FFFFFF;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.35);
}

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

.send-btn:active {
    transform: scale(0.95);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 20, 26, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    padding: 32px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease-out;
}

.modal-card h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.modal-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* Lightbox */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

/* Toast Notifications */
.toast-notify {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    z-index: 999999;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    animation: toastPop 0.2s ease-out;
    pointer-events: none;
}

@keyframes toastPop {
    from {
        opacity: 0;
        transform: translate(-50%, 10px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.97);
    }

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

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

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

.hidden {
    display: none !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    .back-btn {
        display: flex;
    }

    .chat-area {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
    }

    .chat-area.hidden-mobile {
        display: none;
    }

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

    .auth-wrapper {
        align-items: flex-start;
        padding: 28px 16px;
        overflow: auto;
    }

    .auth-card {
        padding: 28px 18px;
    }

    .chat-input-bar {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}