@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* WaMax Light Theme Design System Tokens */
:root {
    --brand: #0755D9;
    --brand-hover: #0647B7;
    --brand-subtle: rgba(7, 85, 217, 0.08);
    --brand-border: rgba(7, 85, 217, 0.2);

    /* Light Theme Default Surface & Text */
    --whatsapp-green: #0755D9;            /* Primary brand color (Cobalt) */
    --whatsapp-green-dark: #0647B7;
    --whatsapp-green-light: #2563EB;
    --whatsapp-bg: #F7F9FC;               /* Canvas background */
    --whatsapp-panel-bg: #FFFFFF;          /* Card & Sidebar surface */
    --whatsapp-chat-bg: #F8FAFC;           /* Main content workspace */
    --whatsapp-message-out: #E0ECFF;       /* Outgoing message bubble */
    --whatsapp-message-in: #F1F5F9;        /* Incoming message bubble */
    --whatsapp-text: #101C30;              /* Primary text */
    --whatsapp-text-secondary: #526175;    /* Muted text */
    --whatsapp-border: #CBD5E1;            /* Clean borders */
    --whatsapp-hover: #F1F5F9;             /* Hover background */
    --whatsapp-blue: #0284C7;
    --whatsapp-purple: #7C3AED;
    --whatsapp-orange: #D97706;
    --whatsapp-red: #DC2626;

    /* Status Indicators */
    --status-wa-connected: #15803D;
    --status-wa-bg: #DCFCE7;
    --radius-card: 16px;
    --radius-control: 10px;
    --shadow-sm: 0 1px 3px rgba(16, 28, 48, 0.06);
    --shadow-md: 0 4px 14px rgba(16, 28, 48, 0.08);
    --shadow-lg: 0 12px 28px rgba(16, 28, 48, 0.12);
}

/* Dark Theme Support */
[data-theme="dark"] {
    --brand: #2563EB;
    --brand-hover: #1D4ED8;
    --brand-subtle: rgba(37, 99, 235, 0.15);
    --brand-border: rgba(37, 99, 235, 0.3);

    --whatsapp-green: #2563EB;
    --whatsapp-green-dark: #1D4ED8;
    --whatsapp-green-light: #38BDF8;
    --whatsapp-bg: #0B1220;
    --whatsapp-panel-bg: #0F172A;
    --whatsapp-chat-bg: #070B14;
    --whatsapp-message-out: #1E3A8A;
    --whatsapp-message-in: #1E293B;
    --whatsapp-text: #F8FAFC;
    --whatsapp-text-secondary: #94A3B8;
    --whatsapp-border: #334155;
    --whatsapp-hover: #1E293B;
    --whatsapp-blue: #38BDF8;
    --whatsapp-purple: #A855F7;
    --whatsapp-orange: #F59E0B;
    --whatsapp-red: #EF4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--whatsapp-bg);
    color: var(--whatsapp-text);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: var(--whatsapp-text);
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar Styles */
.sidebar {
    width: 380px;
    background: var(--whatsapp-panel-bg);
    border-right: 1px solid var(--whatsapp-border);
    display: flex;
    flex-direction: column;
    min-width: 300px;
}

.sidebar-header {
    padding: 10px 16px;
    background: var(--whatsapp-panel-bg);
    border-bottom: 1px solid var(--whatsapp-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.profile {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.profile-pic {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--brand-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--brand);
    flex-shrink: 0;
    overflow: hidden;
}

.profile-pic img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.profile-info {
    overflow: hidden;
}

.profile-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-info p {
    margin: 2px 0 0 0;
    font-size: 13px;
    color: var(--whatsapp-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--whatsapp-text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--whatsapp-hover);
    color: var(--whatsapp-text);
}

.sidebar-menu {
    padding: 12px 0;
    border-bottom: 1px solid var(--whatsapp-border);
    overflow-y: auto;
    max-height: 52vh;
}

.menu-section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--whatsapp-text-secondary);
    opacity: 0.7;
    padding: 12px 20px 4px 20px;
    user-select: none;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 9px 20px;
    color: var(--whatsapp-text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    font-weight: 500;
    font-size: 14px;
}

.menu-item:hover {
    background: var(--whatsapp-hover);
    color: var(--whatsapp-text);
}

/* Mobile Topbar & Off-canvas Drawer */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--whatsapp-panel-bg);
    border-bottom: 1px solid var(--whatsapp-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-brand img {
    width: 24px;
    height: 24px;
}

.mobile-brand span {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: var(--whatsapp-text);
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--whatsapp-text);
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.mobile-menu-btn:hover {
    background: var(--whatsapp-hover);
}

.mobile-close-btn {
    display: none;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 28, 48, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.menu-item.active {
    background: var(--brand-subtle);
    border-left: 3px solid var(--brand);
    color: var(--brand);
    font-weight: 600;
}

.menu-item i {
    width: 24px;
    text-align: center;
    font-size: 18px;
    color: inherit;
    flex-shrink: 0;
}

.menu-item.active i {
    color: var(--brand);
}

.menu-item span {
    font-size: 15px;
    font-weight: 500;
}

.sidebar-sessions {
    padding: 20px 16px;
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.session-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.session-header h4 {
    margin: 0;
    color: var(--whatsapp-text-secondary);
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

#sessions-list {
    flex-grow: 1;
    overflow-y: auto;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 5px;
    transition: background 0.2s;
    cursor: pointer;
    position: relative;
}

.session-item:hover {
    background: var(--whatsapp-hover);
}

.session-item.loading {
    justify-content: center;
    opacity: 0.7;
}

.session-item.empty {
    justify-content: center;
    color: var(--whatsapp-text-secondary);
    text-align: center;
    padding: 20px;
}

.session-item.empty i {
    font-size: 24px;
    margin-bottom: 10px;
    display: block;
}

.session-item.empty span {
    font-size: 14px;
}

.session-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.session-info {
    flex-grow: 1;
    overflow: hidden;
}

.session-info strong {
    display: block;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-info small {
    font-size: 12px;
    color: var(--whatsapp-text-secondary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-ready {
    color: var(--status-wa-connected);
    font-size: 12px;
    font-weight: 600;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--whatsapp-border);
    background: var(--whatsapp-panel-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--whatsapp-text-secondary);
}

.server-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.connected {
    background: var(--status-wa-connected);
    box-shadow: 0 0 6px rgba(21, 128, 61, 0.5);
}

.status-indicator.disconnected {
    background: var(--whatsapp-red);
}

.version {
    background: var(--whatsapp-hover);
    border: 1px solid var(--whatsapp-border);
    color: var(--whatsapp-text-secondary);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--whatsapp-chat-bg);
    display: flex;
    flex-direction: column;
}

.content-header {
    margin-bottom: 30px;
}

.content-header h1 {
    margin: 0 0 5px 0;
    color: var(--whatsapp-text);
    font-size: 28px;
    font-weight: 300;
    display: flex;
    align-items: center;
    gap: 10px;
}

.content-header h1 i {
    color: var(--whatsapp-green);
}

.subtitle {
    color: var(--whatsapp-text-secondary);
    font-size: 14px;
    margin: 0 0 20px 0;
}

.header-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--whatsapp-panel-bg);
    border-radius: var(--radius-card);
    padding: 22px 20px;
    border: 1px solid var(--whatsapp-border);
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px -5px rgba(7, 85, 217, 0.12), 0 8px 10px -6px rgba(16, 28, 48, 0.04);
    border-color: var(--brand-border);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin: 0 auto 14px auto;
    transition: transform 0.2s var(--ease);
}

.stat-card:hover .stat-icon {
    transform: scale(1.08);
}

.stat-icon.green { background: rgba(21, 128, 61, 0.12); color: var(--status-wa-connected); }
.stat-icon.blue { background: rgba(7, 85, 217, 0.12); color: var(--brand); }
.stat-icon.purple { background: rgba(124, 58, 237, 0.12); color: var(--whatsapp-purple); }
.stat-icon.orange { background: rgba(217, 119, 6, 0.12); color: var(--whatsapp-orange); }

.stat-card h3 {
    margin: 0 0 4px 0;
    font-size: 30px;
    font-weight: 700;
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: var(--whatsapp-text);
}

.stat-card p {
    margin: 0;
    color: var(--whatsapp-text-secondary);
    font-size: 13px;
    font-weight: 500;
}

/* Quick Actions */
.quick-actions {
    margin-bottom: 30px;
}

.quick-actions h2 {
    margin: 0 0 20px 0;
    color: var(--whatsapp-text);
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.action-card {
    background: var(--whatsapp-panel-bg);
    border-radius: var(--radius-card);
    padding: 24px;
    text-decoration: none;
    color: var(--whatsapp-text);
    border: 1px solid var(--whatsapp-border);
    transition: transform 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
    cursor: pointer;
    text-align: center;
    display: block;
    box-shadow: var(--shadow-sm);
}

.action-card:hover {
    background: var(--whatsapp-panel-bg);
    border-color: var(--brand);
    transform: translateY(-3px);
    box-shadow: 0 12px 24px -6px rgba(7, 85, 217, 0.15);
}

.action-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    background: var(--brand-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--brand);
    margin: 0 auto 16px auto;
    transition: transform 0.2s var(--ease);
}

.action-card:hover .action-icon {
    transform: scale(1.08);
}

.action-card h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--whatsapp-text);
}

.action-card p {
    margin: 0;
    color: var(--whatsapp-text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

/* Recent Sessions */
.recent-sessions {
    margin-bottom: 30px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    margin: 0;
    color: var(--whatsapp-text);
    font-size: 20px;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-actions {
    display: flex;
    gap: 10px;
}

.sessions-table {
    background: var(--whatsapp-panel-bg);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--whatsapp-border);
    overflow-x: auto;
}

.sessions-table table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.sessions-table th {
    background: var(--whatsapp-hover);
    padding: 15px;
    text-align: left;
    font-weight: 500;
    color: var(--whatsapp-text-secondary);
    font-size: 14px;
    border-bottom: 1px solid var(--whatsapp-border);
    white-space: nowrap;
}

.sessions-table td {
    padding: 15px;
    border-bottom: 1px solid var(--whatsapp-border);
    color: var(--whatsapp-text);
    vertical-align: middle;
}

.sessions-table tr:last-child td {
    border-bottom: none;
}

.sessions-table tr:hover td {
    background: var(--whatsapp-hover);
}

.loading-cell, .empty-cell {
    text-align: center;
    padding: 30px !important;
    color: var(--whatsapp-text-secondary);
}

.loading-cell i, .empty-cell i {
    font-size: 24px;
    margin-bottom: 10px;
    display: block;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: nowrap;
}

.btn-small {
    padding: 6px 10px;
    border-radius: 4px;
    border: none;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: opacity 0.2s, transform 0.2s;
    min-width: 32px;
    height: 32px;
}

.btn-small:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-small:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--whatsapp-green);
    color: white;
}

.btn-secondary {
    background: var(--whatsapp-blue);
    color: white;
}

.btn-info {
    background: var(--whatsapp-blue);
    color: white;
}

.btn-warning {
    background: var(--whatsapp-orange);
    color: white;
}

.btn-danger {
    background: var(--whatsapp-red);
    color: white;
}

/* Badges */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    display: inline-block;
}

.badge-qr {
    background: rgba(66, 133, 244, 0.1);
    color: var(--whatsapp-blue);
}

.badge-phone {
    background: rgba(156, 39, 176, 0.1);
    color: var(--whatsapp-purple);
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.status-ready {
    background: rgba(76, 175, 80, 0.1);
    color: #4caf50;
}

.status-registering {
    background: rgba(255, 193, 7, 0.1);
    color: #ffc107;
}

.status-connecting {
    background: rgba(33, 150, 243, 0.1);
    color: #2196f3;
}

.status-qr_generated {
    background: rgba(156, 39, 176, 0.1);
    color: #9c27b0;
}

.status-failed {
    background: rgba(244, 67, 54, 0.1);
    color: #f44336;
}

.status-logged_out {
    background: rgba(158, 158, 158, 0.1);
    color: #9e9e9e;
}

.status-reconnecting {
    background: rgba(255, 152, 0, 0.1);
    color: #ff9800;
}

/* System Info */
.system-info {
    background: var(--whatsapp-panel-bg);
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--whatsapp-border);
    margin-top: auto;
}

.system-info h2 {
    margin: 0 0 15px 0;
    color: var(--whatsapp-text);
    font-size: 18px;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-item strong {
    color: var(--whatsapp-text-secondary);
    font-weight: 500;
    font-size: 14px;
    min-width: 100px;
}

.info-item span {
    color: var(--whatsapp-text);
    font-size: 14px;
    flex: 1;
}

/* Toast Container */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    background: var(--whatsapp-panel-bg);
    border: 1px solid var(--whatsapp-border);
    border-radius: 8px;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 27, 33, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--whatsapp-border);
    border-top-color: var(--whatsapp-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--whatsapp-text);
    font-size: 16px;
    margin: 0;
}

/* Session ID */
.session-id {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--whatsapp-text);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--whatsapp-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--whatsapp-text-secondary);
}

/* Responsive */
@media (max-width: 1200px) {
    .sidebar {
        width: 300px;
    }
}

@media (max-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .mobile-topbar {
        display: flex;
    }

    .mobile-close-btn {
        display: flex !important;
    }

    .sidebar-backdrop {
        display: block;
    }

    .app-container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        max-width: 84vw;
        height: 100vh;
        max-height: 100vh;
        z-index: 999;
        border-right: 1px solid var(--whatsapp-border);
        border-bottom: none;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
    }

    .sidebar-menu {
        max-height: 55vh;
    }
    
    .main-content {
        padding: 16px;
        height: calc(100vh - 53px);
        overflow-y: auto;
    }
    
    .content-header h1 {
        font-size: 24px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .actions-grid {
        grid-template-columns: 1fr;
    }
    
    .info-grid {
        grid-template-columns: 1fr;
    }
    
    .toast {
        min-width: 250px;
        max-width: calc(100vw - 40px);
    }
}

@media (max-width: 480px) {
    .content-header h1 {
        font-size: 20px;
    }
    
    .stat-card h3 {
        font-size: 24px;
    }
    
    .action-card h4 {
        font-size: 16px;
    }
    
    .btn-small {
        padding: 4px 8px;
        font-size: 11px;
        min-width: 28px;
        height: 28px;
    }
}