:root {
    --bg-dark: #0f111a;
    --bg-panel: rgba(26, 29, 41, 0.7);
    --bg-panel-solid: #1a1d29;
    --primary: #4ade80; /* Brighter WhatsApp Green / Evolution style */
    --primary-hover: #22c55e;
    --accent: #3b82f6; /* Blue accent */
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(16px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Utilities */
.hidden { display: none !important; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1.5rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.p-4 { padding: 1.5rem; }
.p-5 { padding: 3rem; }
.text-center { text-align: center; }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }
.flex-gap { display: flex; gap: 1rem; }
.w-100 { width: 100%; }

/* Views */
.view-container {
    display: none;
    min-height: 100vh;
}
.view-container.active {
    display: flex;
}

/* --- Login View --- */
#loginView {
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    z-index: 10;
    text-align: center;
}

.brand {
    margin-bottom: 30px;
}
.brand-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 10px;
    filter: drop-shadow(0 0 10px rgba(74, 222, 128, 0.5));
}

.input-group {
    position: relative;
    margin-bottom: 20px;
}
.input-group i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.input-group input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s;
}
.input-group input:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
}

/* Background Shapes for Login */
.bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 1;
    opacity: 0.4;
}
.shape1 { width: 400px; height: 400px; background: var(--primary); top: -100px; right: -100px; }
.shape2 { width: 300px; height: 300px; background: var(--accent); bottom: -50px; left: -50px; }
.shape3 { width: 250px; height: 250px; background: #8b5cf6; top: 40%; left: 30%; }

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    font-size: 0.95rem;
}
.btn-block { width: 100%; padding: 12px; }
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 4px 15px rgba(74, 222, 128, 0.3); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { background: rgba(255,255,255,0.05); }
.btn-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* --- Dashboard layout --- */
#dashboardView {
    flex-direction: row;
    background: var(--bg-dark);
}

.sidebar {
    width: 280px;
    height: 100vh;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-right: none;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    z-index: 50;
}

.sidebar-header {
    padding: 30px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 { font-size: 1.5rem; letter-spacing: 1px; }
.sidebar-header .brand-icon { font-size: 2rem; margin-bottom: 0; }

.nav-links {
    list-style: none;
    padding: 20px;
    flex: 1;
}

.nav-links li { margin-bottom: 10px; }
.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-links li.active a, .nav-links a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}
.sidebar-footer .btn { width: 100%; }

.main-content {
    flex: 1;
    margin-right: 280px; /* offset sidebar */
    padding: 20px 40px;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    margin-bottom: 30px;
    border-radius: 12px;
}

.nav-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(74, 222, 128, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.5; }
}

/* Content Sections */
.content-section { display: none; }
.content-section.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 25px;
}
.section-header h3 { font-size: 1.5rem; margin-bottom: 5px; }
.section-header p { color: var(--text-muted); font-size: 0.95rem; }

/* Instances Grid */
.instances-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.instance-card {
    background: var(--bg-panel-solid);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}

.instance-card:hover { border-color: rgba(255, 255, 255, 0.2); transform: translateY(-3px); }

.instance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.instance-phone {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
.instance-phone i { color: var(--primary); }

.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-connected { background: rgba(74, 222, 128, 0.15); color: var(--primary); }
.status-connecting { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.status-disconnected { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.instance-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.instance-actions {
    display: flex;
    gap: 10px;
}
.instance-actions .btn { flex: 1; padding: 8px; font-size: 0.9rem; }

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal.show { display: flex; animation: fadeInModal 0.2s ease; }
@keyframes fadeInModal {
    from { opacity: 0; } to { opacity: 1; }
}

.modal-content {
    background: var(--bg-dark); /* Solid over glass to avoid weird double blurs */
    width: 100%;
    max-width: 500px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    transform: scale(0.95);
    transition: all 0.3s;
}
.modal.show .modal-content { transform: scale(1); }

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    transition: color 0.2s;
}
.close-btn:hover { color: #fff; }

.modal-body { padding: 25px; }

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.form-group label { display: block; margin-bottom: 8px; color: var(--text-muted); }
.form-control {
    width: 100%;
    padding: 12px 15px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
}
.form-control:focus { border-color: var(--primary); }

.method-card {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.method-card i { font-size: 1.5rem; margin-bottom: 10px; color: var(--text-muted); }
.method-card:hover { background: rgba(255, 255, 255, 0.08); }
.method-card.active { border-color: var(--primary); background: rgba(74, 222, 128, 0.1); }
.method-card.active i { color: var(--primary); }

/* QR and Pairing Display */
.qr-wrapper, .pairing-code-wrapper {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    display: inline-block;
    min-width: 250px;
    min-height: 250px;
}

.qrcode-container { margin: 0 auto; display: flex; justify-content: center; }

.pairing-code-display {
    color: #000;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
}

.qr-skeleton, .pairing-skeleton {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #666;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.loader-container {
    padding: 60px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: var(--text-muted);
}
.loader-container .spinner { border-color: rgba(255,255,255,0.1); border-top-color: var(--primary); }

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

/* Toasts */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-panel-solid);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-icon { color: var(--primary); font-size: 1.2rem; }
.toast-error .toast-icon { color: var(--danger); }

/* API Docs Section */
.badge {
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-left: 10px;
}
.method-post { background: rgba(59, 130, 246, 0.2); color: #3b82f6; border: 1px solid rgba(59, 130, 246, 0.3);}
.method-get { background: rgba(74, 222, 128, 0.2); color: var(--primary); border: 1px solid rgba(74, 222, 128, 0.3);}

.code-block {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
    font-family: monospace;
    overflow-x: auto;
    margin-top: 10px;
}
.code-block pre { margin: 0; color: #a5b4fc; }

.form-data-list {
    list-style-position: inside;
    color: var(--text-muted);
}
.form-data-list li { margin-bottom: 5px; }
.form-data-list code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    color: #fca5a5;
}
