:root {
    --bg-color: #0f172a;
    --sidebar-color: #1e293b;
    --card-color: #1e293b;
    --accent-primary: #8b5cf6;
    --accent-secondary: #3b82f6;
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;

    /* Extra layout variables */
    --input-bg: rgba(15, 23, 42, 0.4);
    --border-color: rgba(255, 255, 255, 0.08);
    --glass-blend: rgba(255, 255, 255, 0.03);
    --code-bg: rgba(15, 23, 42, 0.4);
    --code-color: #38bdf8;
    --hover-bg: rgba(255, 255, 255, 0.05);
    --stat-gradient: linear-gradient(135deg, #f8fafc 0%, #cbd5e1 100%);

    /* WhatsApp Simulator variables */
    --wa-bg: #0b141a;
    --wa-bubble-bg: #005c4b;
    --wa-bubble-text: #e9edef;
    --wa-bubble-time: rgba(255, 255, 255, 0.6);
    --wa-header-bg: #202c33;
    --wa-header-text: #e9edef;
    --wa-phone-shadow: rgba(0, 0, 0, 0.4);
}

.light-mode {
    --bg-color: #f4efe6;          /* Soothing warm cream background (Remang-Remang) */
    --sidebar-color: #faf7f2;      /* Soft warm paper sidebar */
    --card-color: #faf7f2;         /* Warm milk cozy cards */
    --accent-primary: #6d28d9;     /* Deep rich violet */
    --accent-secondary: #1d4ed8;   /* Deep royal blue */
    --text-primary: #2d261e;       /* Warm soft charcoal (no harsh black) */
    --text-secondary: #6e6456;     /* Soothing warm taupe */
    --success: #047857;            /* Deep soft emerald */
    --danger: #b91c1c;             /* Deep crimson */

    /* Extra layout variables */
    --input-bg: #ffffff;
    --border-color: rgba(45, 38, 30, 0.12); /* Subtle cozy borders */
    --glass-blend: rgba(45, 38, 30, 0.02);
    --code-bg: #eae3d5;            /* Soft dim paper block for code */
    --code-color: #0369a1;         /* Ocean blue for code text */
    --hover-bg: rgba(45, 38, 30, 0.05);
    --stat-gradient: linear-gradient(135deg, #2d261e 0%, #4c3f30 100%); /* Clear readable dark charcoal */

    /* WhatsApp Simulator variables */
    --wa-bg: #eae6df;              /* Perfect WhatsApp dim bg */
    --wa-bubble-bg: #d9fdd3;
    --wa-bubble-text: #111b21;
    --wa-bubble-time: rgba(0, 0, 0, 0.45);
    --wa-header-bg: #e2d9cd;       /* Elegant warm smartphone mockup header */
    --wa-header-text: #2d261e;
    --wa-phone-shadow: rgba(45, 38, 30, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

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

/* Login Overlay */
#auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-card {
    background: var(--sidebar-color);
    padding: 2.5rem;
    border-radius: 1.5rem;
    width: 100%;
    max-width: 400px;
    border: 1px solid rgba(255,255,255,0.1);
}

.auth-card h2 { margin-bottom: 1.5rem; text-align: center; }
.input-group { margin-bottom: 1.25rem; }
.input-group label { display: block; margin-bottom: 0.5rem; color: var(--text-secondary); font-size: 0.875rem; }
.input-group input { 
    width: 100%; padding: 0.75rem; border-radius: 0.5rem; border: 1px solid var(--border-color);
    background: var(--input-bg); color: var(--text-primary);
}

/* Sidebar */
aside {
    width: 260px;
    background-color: var(--sidebar-color);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    border-right: 1px solid var(--border-color);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

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

.nav-item.active {
    border-left: 3px solid var(--accent-primary);
}

/* Main Content */
main {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.05), transparent);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.card {
    background: var(--card-color);
    backdrop-filter: blur(10px);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
}

.stat-label { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 0.5rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }

/* Device Table */
.device-section {
    background: var(--card-color);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
}

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th { text-align: left; color: var(--text-secondary); font-size: 0.875rem; padding: 1rem; border-bottom: 1px solid var(--border-color); }
td { padding: 1rem; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }

.status-badge { padding: 0.25rem 0.75rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 600; }
.status-online { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.status-offline { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

.btn { padding: 0.5rem 1.5rem; border-radius: 0.5rem; border: none; font-weight: 600; cursor: pointer; transition: all 0.3s; }
.btn-primary { background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary)); color: white; width: 100%; margin-top: 1rem;}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-add { width: auto; margin: 0; }

#qr-modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); justify-content: center; align-items: center; z-index: 2000;
}

.modal-content { background: var(--sidebar-color); padding: 2rem; border-radius: 1rem; text-align: center; width: 400px;}
#qr-container { 
    background: white; padding: 1rem; border-radius: 0.5rem; 
    margin: 1.5rem auto; width: 292px; height: 292px;
    display: flex; align-items: center; justify-content: center;
}

.api-key { font-family: monospace; background: rgba(0,0,0,0.3); padding: 0.25rem 0.5rem; border-radius: 0.25rem; font-size: 0.8rem; }

/* Modal Data List */
#data-modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); justify-content: center; align-items: center; z-index: 2100;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.btn-close { background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer; }
.btn-info { background: #3498db; color: white; padding: 0.3rem 0.6rem; }
.loading { border: 4px solid rgba(255,255,255,0.1); border-top: 4px solid var(--accent-primary); border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; margin: 2rem auto; }
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); justify-content: center; align-items: center; z-index: 2500;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Send Message Tabs */
.msg-tab {
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s;
    user-select: none;
}
.msg-tab:hover {
    background: rgba(255, 255, 255, 0.1);
}
.msg-tab.active {
    background: var(--accent-primary);
    color: white;
}

/* ==========================================
   Cozy Warm Dim (Remang-Remang) Light Mode Overrides
   ========================================== */
.light-mode {
    color-scheme: light;
}

/* Global scrollbars for Light Mode */
.light-mode ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.light-mode ::-webkit-scrollbar-track {
    background: var(--bg-color);
}
.light-mode ::-webkit-scrollbar-thumb {
    background: rgba(45, 38, 30, 0.15);
    border-radius: 4px;
}
.light-mode ::-webkit-scrollbar-thumb:hover {
    background: rgba(45, 38, 30, 0.25);
}

/* Card & Section Borders Overrides to use var(--border-color) seamlessly */
.light-mode .docs-card,
.light-mode .stat-card,
.light-mode .device-section,
.light-mode .premium-btn,
.light-mode .quick-action-item,
.light-mode .guidelines-card,
.light-mode .phone-media-placeholder,
.light-mode .poll-preview-option,
.light-mode .webhook-card,
.light-mode .log-card,
.light-mode .settings-section {
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 4px 20px -2px rgba(45, 38, 30, 0.05) !important;
}

/* Active elements & soft backgrounds */
.light-mode .msg-tab {
    background: rgba(45, 38, 30, 0.04) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-color) !important;
}
.light-mode .msg-tab:hover {
    background: rgba(45, 38, 30, 0.08) !important;
    color: var(--text-primary) !important;
}
.light-mode .msg-tab.active {
    background: var(--accent-primary) !important;
    color: white !important;
    border-color: var(--accent-primary) !important;
}

/* Code & Raw Preview block style */
.light-mode pre,
.light-mode code,
.light-mode #payload-content {
    background-color: var(--code-bg) !important;
    color: var(--code-color) !important;
    border: 1px solid var(--border-color) !important;
}

/* Auth / Login Overlay Card */
.light-mode .auth-card {
    background: var(--sidebar-color) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 10px 30px rgba(45, 38, 30, 0.08) !important;
}

/* Hover overlays */
.light-mode .nav-item:hover, 
.light-mode .nav-item.active {
    background-color: var(--hover-bg) !important;
}

.light-mode .device-table tr:hover td {
    background: rgba(45, 38, 30, 0.02) !important;
}

/* Documentation Page specific Light Mode overrides */
.light-mode .param-name {
    color: var(--text-primary) !important; /* Soft dark charcoal */
}
.light-mode .type-badge.string {
    background: rgba(29, 78, 216, 0.1) !important;
    color: #1d4ed8 !important;
}
.light-mode .type-badge.array {
    background: rgba(109, 40, 217, 0.1) !important;
    color: #6d28d9 !important;
}
.light-mode .type-badge.int {
    background: rgba(180, 83, 9, 0.1) !important;
    color: #b45309 !important;
}
.light-mode .type-badge.boolean {
    background: rgba(190, 24, 74, 0.1) !important;
    color: #be184d !important;
}
.light-mode .req-badge.required {
    color: #b91c1c !important; /* Dark crimson instead of light red */
}
.light-mode .req-badge.optional {
    color: #57534e !important; /* Muted stone charcoal */
}

/* Terminal & Code Mockups in Cozy Light Mode */
.light-mode .terminal-window {
    background: var(--sidebar-color) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 8px 30px rgba(45, 38, 30, 0.04) !important;
}

.light-mode .terminal-header {
    background: rgba(45, 38, 30, 0.03) !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.light-mode .terminal-title {
    color: var(--text-secondary) !important;
}

.light-mode .terminal-body pre {
    background: transparent !important;
    color: var(--text-primary) !important;
    border: none !important;
    padding: 0 !important;
}

.light-mode .btn-copy {
    background: rgba(45, 38, 30, 0.03) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
}

.light-mode .btn-copy:hover {
    background: rgba(45, 38, 30, 0.06) !important;
    color: var(--text-primary) !important;
}

/* Cozy JSON Syntax Highlighting Overrides for Light Mode */
.light-mode .j-key { color: #6d28d9 !important; }       /* Solid premium violet */
.light-mode .j-str { color: #059669 !important; }       /* Solid clean emerald */
.light-mode .j-num { color: #b45309 !important; }       /* Solid rich amber */
.light-mode .j-bool { color: #be184d !important; }      /* Pink-rose */
.light-mode .j-syn { color: #57534e !important; }       /* Muted slate brackets */
.light-mode .j-com { color: #8c8273 !important; font-style: italic !important; }

/* Elegant Warning Callout Overrides in Light Mode */
.light-mode .docs-callout.warning {
    background: rgba(180, 83, 9, 0.06) !important;
    border: 1px solid rgba(180, 83, 9, 0.15) !important;
    color: #b45309 !important;
}
.light-mode .docs-callout.warning strong {
    color: #b45309 !important;
}

/* Script Card in Light Mode */
.light-mode .script-card {
    background: var(--card-color) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 4px 15px -2px rgba(45, 38, 30, 0.04) !important;
}
.light-mode .script-card:hover {
    background: #ffffff !important;
    border-color: rgba(139, 92, 246, 0.25) !important;
    box-shadow: 0 8px 24px rgba(45, 38, 30, 0.08) !important;
}
.light-mode .script-icon-box {
    background: rgba(139, 92, 246, 0.1) !important;
    color: var(--accent-primary) !important;
}
.light-mode .script-action-btn {
    background: rgba(45, 38, 30, 0.03) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
}

/* Status Code Badges in Light Mode */
.light-mode .status-code-badge.orange {
    background: rgba(217, 119, 6, 0.08) !important;
    color: #b45309 !important;
    border: 1px solid rgba(217, 119, 6, 0.15) !important;
}
.light-mode .status-code-badge.red {
    background: rgba(220, 38, 38, 0.08) !important;
    color: #b91c1c !important;
    border: 1px solid rgba(220, 38, 38, 0.15) !important;
}

/* Webhook Secret Box in Light Mode */
.light-mode .webhook-secret-box {
    background: rgba(4, 120, 87, 0.06) !important;
    color: #047857 !important;
    border-left: 3px solid #047857 !important;
}
