/* ═══════════════════════════════════════════════════════════
   WhatsApp Campaign Dashboard - CSS
   Dark theme, professional dashboard styling
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1a2744;
    --bg-input: #0d1b2a;
    --border-color: #2a2a4a;
    --border-light: #333366;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #666688;
    --accent-primary: #6366f1;
    --accent-hover: #818cf8;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --accent-blue: #3b82f6;
    --accent-purple: #a855f7;
    --accent-cyan: #06b6d4;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-width: 240px;
    --sidebar-collapsed: 64px;
    --topbar-height: 60px;
    --transition: all 0.25s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ─── Layout ──────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    min-height: 60px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--accent-primary);
}

.logo i { font-size: 20px; }

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    display: none;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-primary);
}

.nav-item i { width: 20px; text-align: center; font-size: 15px; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.server-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

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

.status-dot.online { background: var(--accent-green); box-shadow: 0 0 8px rgba(34, 197, 94, 0.5); }
.status-dot.offline { background: var(--accent-red); }
.status-dot.error { background: var(--accent-yellow); }

/* ─── Main Content ────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: var(--transition);
}

.top-bar {
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    flex: 1;
}

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

.content-area {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* ─── Cards ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-1px);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.stat-value.green { color: var(--accent-green); }
.stat-value.red { color: var(--accent-red); }
.stat-value.yellow { color: var(--accent-yellow); }
.stat-value.blue { color: var(--accent-blue); }
.stat-value.purple { color: var(--accent-purple); }

/* ─── Cards Container ─────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-body { padding: 20px; }

/* ─── Tables ──────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid rgba(42, 42, 74, 0.5);
    vertical-align: middle;
}

tbody tr:hover { background: rgba(99, 102, 241, 0.03); }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; }

/* ─── Badges ──────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-online { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.badge-offline { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-error { background: rgba(245, 158, 11, 0.15); color: var(--accent-yellow); }
.badge-paused { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.badge-running { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.badge-draft { background: rgba(136, 136, 170, 0.15); color: var(--text-secondary); }
.badge-completed { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.badge-stopped { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--accent-yellow); }
.badge-assigned { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.badge-failed { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-in_progress { background: rgba(99, 102, 241, 0.15); color: var(--accent-primary); }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-success { background: var(--accent-green); color: white; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger { background: var(--accent-red); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-warning { background: var(--accent-yellow); color: #1a1a2e; }
.btn-warning:hover:not(:disabled) { background: #d97706; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-card); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ─── Forms ───────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

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

.form-control {
    width: 100%;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

textarea.form-control { resize: vertical; min-height: 80px; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ─── Modal ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: var(--transition);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Device Grid ─────────────────────────────────────── */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    transition: var(--transition);
}

.device-card:hover { border-color: var(--border-light); }

.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.device-card-name {
    font-weight: 600;
    font-size: 14px;
}

.device-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.device-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.device-stat i { width: 14px; text-align: center; }

.battery-bar {
    width: 40px;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
}

.battery-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.battery-bar-fill.high { background: var(--accent-green); }
.battery-bar-fill.medium { background: var(--accent-yellow); }
.battery-bar-fill.low { background: var(--accent-red); }

/* ─── Toast ───────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 250px;
    box-shadow: var(--shadow);
}

.toast-success { background: var(--accent-green); color: white; }
.toast-error { background: var(--accent-red); color: white; }
.toast-info { background: var(--accent-blue); color: white; }
.toast-warning { background: var(--accent-yellow); color: #1a1a2e; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── Slider / Range ──────────────────────────────────── */
.range-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-group input[type="range"] {
    flex: 1;
    accent-color: var(--accent-primary);
}

.range-value {
    min-width: 50px;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-primary);
}

/* ─── Toggle Switch ───────────────────────────────────── */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--accent-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ─── Progress Bar ────────────────────────────────────── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
    background: var(--accent-primary);
}

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .mobile-toggle { display: block; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .device-grid { grid-template-columns: 1fr; }
    .content-area { padding: 16px; }
}

/* ─── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ─── Utility ─────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
}
.chip .remove {
    cursor: pointer;
    color: var(--text-muted);
    margin-left: 2px;
}
.chip .remove:hover { color: var(--accent-red); }

/* Loading spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
