:root {
    /* Ultra Clean Light Theme (Apple Aesthetic) */
    --color-bg: #f2f2f7;
    /* iOS grouped background color */
    --color-surface: rgba(255, 255, 255, 0.85);
    /* Much brighter glass */
    --color-surface-solid: #ffffff;
    /* Solid white for cards */
    --color-surface-hover: #e5e5ea;
    /* iOS standard gray for hover/inputs */
    --color-border: rgba(0, 0, 0, 0.06);
    /* Very subtle borders */

    --color-accent: #10b981;
    /* WhatsApp green, tuned for light mode */
    --color-accent-hover: #059669;
    --color-primary: #10b981;
    --color-primary-hover: #059669;
    --color-danger: #ff3b30;
    --color-danger-hover: #d70015;

    --color-text: #000000;
    /* Max contrast text */
    --color-text-muted: #8e8e93;
    /* iOS system gray */

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --glass-blur: blur(30px);
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Safe Area Insets for Mobile Notch / Home Bar */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Dark Theme overrides via System Preference or Manual Toggle */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #000000;
        --color-surface: rgba(28, 28, 30, 0.65);
        --color-surface-solid: #1c1c1e;
        --color-surface-hover: rgba(255, 255, 255, 0.08);
        --color-border: rgba(255, 255, 255, 0.12);

        --color-accent: #10b981;
        --color-accent-hover: #059669;
        --color-primary: #10b981;
        --color-primary-hover: #059669;
        --color-danger: #ff453a;
        --color-danger-hover: #ff3b30;

        --color-text: #f5f5f7;
        --color-text-muted: #98989d;

        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.6);
    }
}

/* Explicit Dark Mode */
:root[data-theme="dark"] {
    --color-bg: #000000;
    --color-surface: rgba(28, 28, 30, 0.65);
    --color-surface-solid: #1c1c1e;
    --color-surface-hover: rgba(255, 255, 255, 0.08);
    --color-border: rgba(255, 255, 255, 0.12);

    --color-accent: #10b981;
    --color-accent-hover: #059669;
    --color-primary: #10b981;
    --color-primary-hover: #059669;
    --color-danger: #ff453a;
    --color-danger-hover: #ff3b30;

    --color-text: #f5f5f7;
    --color-text-muted: #98989d;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout */
#app {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    overflow-y: auto;
}

.mobile-header {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

.sidebar {
    width: 260px;
    background-color: var(--color-surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 28px 24px 20px;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    color: var(--color-accent);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--color-surface-hover);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.status-badge.connected {
    background: rgba(48, 209, 88, 0.15);
    color: var(--color-accent);
}

.status-badge.disconnected {
    background: rgba(255, 69, 58, 0.15);
    color: var(--color-danger);
}

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

.status-badge.connected .status-dot {
    background-color: var(--color-accent);
}

.status-badge.disconnected .status-dot {
    background-color: var(--color-danger);
}

.status-badge.needs-login {
    background: rgba(255, 159, 10, 0.15);
    color: #ff9f0a;
}
.status-badge.needs-login .status-dot {
    background-color: #ff9f0a;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-badge.connecting {
    background: rgba(10, 132, 255, 0.15);
    color: #0a84ff;
}
.status-badge.connecting .status-dot {
    background-color: #0a84ff;
}

.nav-menu {
    list-style: none;
    padding: 20px 12px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-weight: 500;
    margin-bottom: 4px;
}

.nav-link:hover {
    background-color: var(--color-surface-hover);
    color: var(--color-text);
}

.nav-link.active {
    background-color: rgba(48, 209, 88, 0.15);
    color: var(--color-accent);
}

/* Quick Broadcast nav link — orange accent */
.nav-link-qb.active {
    background-color: rgba(255, 149, 0, 0.15);
    color: #ff9500;
}
.nav-link-qb:hover {
    color: #ff9500;
}

.nav-link i {
    font-size: 1.2rem;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    background: transparent;
}

/* Common Components */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.card {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
    background: var(--color-surface-solid);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-family: inherit;
    letter-spacing: -0.01em;
}

.btn i {
    font-size: 1.1rem;
}

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

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.btn-success {
    background-color: var(--color-accent);
    color: #fff;
}

.btn-success:hover {
    background-color: var(--color-accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(48, 209, 88, 0.3);
}

.btn-danger {
    background-color: var(--color-danger);
    color: white;
}

.btn-danger:hover {
    background-color: var(--color-danger-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 69, 58, 0.3);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover {
    background-color: var(--color-surface-hover);
}

/* Responsive Table Container */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
}

.table-responsive .data-table {
    min-width: 620px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th,
.data-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tbody tr {
    transition: background-color 0.2s ease;
}

.data-table tbody tr:hover {
    background-color: var(--color-surface-hover);
}

.actions-cell {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.btn-icon.danger:hover {
    color: var(--color-danger);
    background: rgba(255, 69, 58, 0.15);
}

/* Group Picker */
.group-picker {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-hover);
    overflow: hidden;
}

.picker-search {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
    background: transparent;
}

.picker-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
}

.picker-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.picker-item:hover {
    background: var(--color-surface-hover);
}

.picker-item input[type="checkbox"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* Log Console */
.log-console {
    background-color: var(--color-surface-solid);
    border-radius: var(--radius-md);
    padding: 16px;
    height: 300px;
    overflow-y: auto;
    font-family: 'SF Mono', 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    border: 1px solid var(--color-border);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.log-entry {
    margin-bottom: 8px;
    line-height: 1.4;
}

.log-entry.success {
    color: var(--color-accent);
}

.log-entry.error {
    color: var(--color-danger);
}

.log-entry.warning {
    color: #ff9f0a;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 10px;
    background-color: var(--color-surface-hover);
    border-radius: 5px;
    overflow: hidden;
    margin: 16px 0;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-bar {
    height: 100%;
    background-color: var(--color-primary);
    width: 0%;
    transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--color-surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--color-text);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 320px;
    font-weight: 500;
    transform: translateX(120%) scale(0.95);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateX(0) scale(1);
    opacity: 1;
}

.toast.success {
    border-left: 4px solid var(--color-accent);
}

.toast.error {
    border-left: 4px solid var(--color-danger);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--color-surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--color-border);
    border-radius: 24px;
    width: 100%;
    max-width: 500px;
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-close {
    background: var(--color-surface-hover);
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.modal-body {
    margin-bottom: 32px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Media Library */
.media-dropzone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    background: var(--color-surface);
    transition: all 0.2s ease;
    cursor: pointer;
    margin-bottom: 24px;
}

.media-dropzone:hover, .media-dropzone.highlight {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.media-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.media-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.media-preview {
    height: 150px;
    background: var(--color-surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.media-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-preview .media-icon {
    font-size: 3rem;
    color: var(--color-text-muted);
}

.media-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.media-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-size {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.media-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.media-card:hover .media-actions {
    opacity: 1;
}

.media-picker-modal .media-grid {
    max-height: 60vh;
    overflow-y: auto;
    padding: 8px;
}

/* =============================
   Nav Divider
   ============================= */
.nav-divider {
    height: 1px;
    background: var(--color-border);
    margin: 12px 16px;
    list-style: none;
}

/* =============================
   Login Page
   ============================= */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 20px;
    background: var(--color-bg);
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    animation: slideUp 0.4s ease;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: white;
    margin-bottom: 16px;
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.35);
}

.login-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--color-text);
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0;
    line-height: 1.5;
}

/* Login States */
.login-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    text-align: center;
}

.login-state-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0;
    color: var(--color-text);
}
.login-state-title.success {
    color: var(--color-accent);
}

.login-state-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0;
}

.qr-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
}

/* QR Code */
.qr-wrapper {
    background: #ffffff;
    padding: 16px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    display: inline-block;
}

#qr-code-canvas img,
#qr-code-canvas canvas {
    display: block;
    border-radius: 8px;
}

/* Loading Placeholder */
.qr-placeholder {
    width: 240px;
    height: 240px;
    background: var(--color-surface-hover);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner-lg {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Connected State */
.connected-badge {
    display: flex;
    align-items: center;
    justify-content: center;
}

.connected-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #30d158 0%, #25a244 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    box-shadow: 0 4px 20px rgba(48, 209, 88, 0.4);
    animation: popIn 0.4s ease;
}

/* Error State */
.error-badge {
    font-size: 3rem;
    line-height: 1;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1rem;
}

/* Instructions */
.login-instructions {
    display: none;
    background: var(--color-surface-hover);
    border-radius: 12px;
    padding: 20px 24px;
    margin-top: 8px;
}

.login-instructions h3 {
    margin: 0 0 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.login-instructions ol {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-instructions li {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}

@keyframes popIn {
    from { transform: scale(0.6); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* =============================
   Sidebar Footer & Logout
   ============================= */
.sidebar-footer {
    margin-top: auto;
    padding: 12px 16px 20px;
    border-top: 1px solid var(--color-border);
}

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.sidebar-logout-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    color: var(--color-danger);
}

.sidebar-logout-btn i {
    font-size: 1.1rem;
}

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

/* PWA Install Button */
.pwa-install-btn {
    background: rgba(36, 194, 78, 0.12) !important;
    color: var(--color-accent) !important;
    border: 1px solid rgba(36, 194, 78, 0.3) !important;
    font-weight: 600 !important;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.pwa-install-btn:hover {
    background: rgba(36, 194, 78, 0.22) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(36, 194, 78, 0.25);
}

.pwa-install-mobile-btn {
    color: var(--color-accent) !important;
    background: rgba(36, 194, 78, 0.15) !important;
    border-radius: var(--radius-sm);
}

/* =============================
   Danger Button Variants
   ============================= */
.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border: none;
}
.btn-danger:hover {
    background: var(--color-danger-hover);
}

.btn-danger-outline {
    background: transparent;
    color: var(--color-danger);
    border: 1.5px solid var(--color-danger);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-danger-outline:hover {
    background: rgba(255, 59, 48, 0.1);
}
.btn-danger-outline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Login page button row */
.login-btn-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

/* ============================================================
   QUICK BROADCAST PAGE
   ============================================================ */

.qb-page {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    animation: slideUp 0.3s ease;
}

/* Header */
.qb-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.qb-header-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, #ff9500 0%, #ff6b00 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: white;
    box-shadow: 0 4px 16px rgba(255, 149, 0, 0.35);
    flex-shrink: 0;
}

.qb-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 0 2px;
    color: var(--color-text);
}

.qb-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin: 0;
}

.qb-header-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.qb-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
}
.qb-status-dot.idle { background: var(--color-text-muted); }
.qb-status-dot.running {
    background: var(--color-accent);
    animation: pulse 1s ease-in-out infinite;
}

/* Body: two-column layout */
.qb-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .qb-body { grid-template-columns: 1fr; }
}

/* Panels */
.qb-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.qb-panel-header {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Radio Buttons */
.qb-radio-group {
    display: flex;
    gap: 12px;
}

.qb-radio-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    user-select: none;
}

.qb-radio-label input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.qb-radio-indicator {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.qb-radio-label input:checked ~ .qb-radio-indicator {
    border-color: #ff9500;
    background: #ff9500;
    box-shadow: inset 0 0 0 3px var(--color-surface);
}

.qb-radio-label:has(input:checked) {
    border-color: #ff9500;
    background: rgba(255, 149, 0, 0.08);
    color: #ff9500;
}

.qb-radio-label i {
    font-size: 1.1rem;
}

/* Fields */
.qb-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.qb-field-row {
    flex-direction: row;
    align-items: flex-start;
}

.qb-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.qb-label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--color-text-muted);
}

/* Textareas */
.qb-textarea {
    width: 100%;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-hover);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    padding: 12px 14px;
    resize: vertical;
    transition: border-color 0.2s;
    box-sizing: border-box;
    line-height: 1.5;
}

.qb-textarea:focus {
    outline: none;
    border-color: #ff9500;
    box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.12);
}

.qb-targets-ta {
    min-height: 220px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
}

.qb-message-ta {
    min-height: 160px;
}

.qb-targets-count {
    font-size: 0.75rem;
    color: var(--color-accent);
    font-weight: 600;
    text-align: right;
}

/* Delay input */
.qb-delay-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.qb-input {
    width: 90px;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-hover);
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s;
}
.qb-input:focus {
    outline: none;
    border-color: #ff9500;
    box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.12);
}

.qb-delay-unit {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.qb-delay-hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Action Buttons */
.qb-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 8px;
}

.qb-btn-send, .qb-btn-stop, .qb-btn-clear {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.qb-btn-send {
    background: linear-gradient(135deg, #ff9500, #ff6b00);
    color: white;
    box-shadow: 0 4px 14px rgba(255, 149, 0, 0.35);
    flex: 1;
    justify-content: center;
}
.qb-btn-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(255, 149, 0, 0.45);
}
.qb-btn-send:active { transform: translateY(0); }

.qb-btn-stop {
    background: var(--color-danger);
    color: white;
    flex: 1;
    justify-content: center;
}
.qb-btn-stop:hover { background: var(--color-danger-hover); }

.qb-btn-clear {
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
    border: 1.5px solid var(--color-border);
}
.qb-btn-clear:hover {
    background: rgba(255, 59, 48, 0.08);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

/* Log Panel */
.qb-log-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.qb-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-hover);
}

.qb-log-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.qb-log-meta {
    display: flex;
    align-items: center;
    gap: 16px;
}

#qb-progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.qb-btn-log-clear {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}
.qb-btn-log-clear:hover {
    background: var(--color-border);
    color: var(--color-text);
}

/* Progress bar */
.qb-progress-bar-wrap {
    height: 3px;
    background: var(--color-border);
}
.qb-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff9500, #ff6b00);
    transition: width 0.4s ease;
    border-radius: 0 2px 2px 0;
}

/* Log output */
.qb-log-output {
    height: 280px;
    overflow-y: auto;
    padding: 12px 20px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    scroll-behavior: smooth;
}

.qb-log-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--color-text-muted);
    font-family: var(--font-sans);
}

.qb-log-line {
    display: flex;
    gap: 12px;
    padding: 2px 0;
    border-bottom: 1px solid transparent;
}
.qb-log-line:hover { background: var(--color-surface-hover); border-radius: 4px; }

.qb-log-time {
    color: var(--color-text-muted);
    flex-shrink: 0;
    opacity: 0.6;
}

.qb-log-msg { color: var(--color-text); }
.qb-log-line.error .qb-log-msg { color: var(--color-danger); }
.qb-log-line.warn .qb-log-msg { color: #ff9500; }
.qb-log-line.info .qb-log-msg { color: var(--color-accent); }

/* ============================================================
   CHATS LAYOUT (Desktop Default)
   ============================================================ */
.chats-layout {
    display: flex;
    gap: 24px;
    height: calc(100vh - 120px);
}

.chats-sidebar-pane {
    width: 350px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.chats-messages-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chats-back-btn {
    display: none;
}

/* ============================================================
   MOBILE & TABLET RESPONSIVE SYSTEM
   ============================================================ */

/* Universal mobile touch-action */
button, a, input, select, textarea {
    touch-action: manipulation;
}

@media (max-width: 768px) {
    body.drawer-open {
        overflow: hidden;
    }

    /* Mobile Header App Bar */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 56px;
        padding: 0 16px;
        padding-top: var(--safe-top);
        background: var(--color-surface);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        border-bottom: 1px solid var(--color-border);
        position: sticky;
        top: 0;
        z-index: 80;
    }

    .mobile-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        font-weight: 700;
        font-size: 1.1rem;
        color: var(--color-accent);
    }

    .mobile-logo-icon {
        font-size: 1.3rem;
        color: var(--color-accent);
        display: flex;
        align-items: center;
    }

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

    /* Off-Canvas Navigation Drawer */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 280px;
        max-width: 82vw;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: var(--shadow-lg);
        background: var(--color-surface);
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        z-index: 95;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Main Content Area */
    .main-content {
        padding: 16px 12px 32px;
    }

    /* Page Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .page-header > button,
    .page-header > .btn,
    .page-header > a {
        width: 100%;
        justify-content: center;
    }

    .page-title {
        font-size: 1.5rem;
    }

    /* Card & Card Headers */
    .card {
        padding: 16px;
        border-radius: var(--radius-md);
        margin-bottom: 16px;
    }

    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 14px;
    }

    .card-header > div {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        width: 100%;
    }

    .card-header select,
    .card-header input {
        width: 100% !important;
    }

    /* Metrics Grid */
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .metric-card {
        padding: 12px !important;
    }

    .metric-card > div:last-child {
        font-size: 1.4rem !important;
    }

    /* Form inputs prevent iOS auto-zoom on focus */
    .form-control,
    .qb-textarea,
    .qb-input,
    select,
    input[type="text"],
    input[type="password"],
    input[type="number"],
    textarea {
        font-size: 16px !important;
    }

    /* Buttons */
    .btn {
        min-height: 44px;
        padding: 10px 18px;
    }

    .btn-icon {
        min-width: 40px;
        min-height: 40px;
    }

    /* Chats Browser Mobile Adaptive Switching */
    .chats-layout {
        height: calc(100vh - 90px);
        height: calc(100dvh - 90px);
        gap: 0;
        position: relative;
    }

    .chats-sidebar-pane {
        width: 100%;
        display: flex;
    }

    .chats-messages-pane {
        display: none;
        width: 100%;
    }

    .chats-layout.chat-selected .chats-sidebar-pane {
        display: none;
    }

    .chats-layout.chat-selected .chats-messages-pane {
        display: flex;
    }

    .chats-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: var(--color-surface-hover);
        color: var(--color-text);
        padding: 6px 10px;
        border-radius: var(--radius-sm);
        cursor: pointer;
    }

    /* Modals */
    .modal-content, .auth-card {
        width: calc(100% - 24px) !important;
        max-height: 90vh;
        overflow-y: auto;
        padding: 24px 18px !important;
        border-radius: 20px !important;
        margin: 12px;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Toasts */
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .toast {
        min-width: 0;
        width: 100%;
        padding: 12px 16px;
        transform: translateY(120%) scale(0.95);
    }

    .toast.show {
        transform: translateY(0) scale(1);
    }

    /* Login / QR Page */
    .login-page {
        padding: 20px 12px;
    }

    .login-card {
        padding: 24px 16px;
        border-radius: 16px;
        width: 100%;
    }

    .login-title {
        font-size: 1.3rem;
    }

    .qr-wrapper {
        padding: 12px;
        max-width: 100%;
    }

    #qr-code-canvas img,
    #qr-code-canvas canvas {
        max-width: 200px;
        height: auto;
    }

    .qr-placeholder {
        width: 200px;
        height: 200px;
    }

    /* Multi-column grid flattening */
    .page-header > div {
        width: 100%;
    }

    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Quick Broadcast */
    .qb-body {
        grid-template-columns: 1fr !important;
    }

    .qb-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .qb-header-status {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }

    .qb-radio-group {
        flex-direction: column;
    }

    .qb-actions {
        flex-direction: column;
    }

    .qb-actions button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr !important;
    }

    .actions-cell {
        flex-wrap: wrap;
    }

    .nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .tab-btn {
        flex-shrink: 0;
    }

    .media-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Phase 3 — Responsive Upgrade Classes
   ───────────────────────────────────────────────────────────────────────────── */

/* Task 3.1 — Broadcast Page: Responsive 2-column grid */
.broadcast-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
}

@media (max-width: 900px) {
    .broadcast-grid {
        grid-template-columns: 1fr;
    }
}

/* Task 3.2 — Campaign variable table: horizontal scroll on narrow viewports */
.variable-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    border-radius: var(--radius-sm);
}

@media (max-width: 600px) {
    .variable-table-wrap table {
        min-width: 480px;
    }
}

/* ─── Task 3.3 — Chats Page: Mobile 3-Panel Tab System ───────────────────── */

/* Mobile tab switcher bar — shown only on narrow screens */
.chats-mobile-tabs {
    display: none;
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 4px;
}

.chats-mobile-tab-btn {
    flex: 1;
    padding: 12px 6px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: all 0.2s;
}

.chats-mobile-tab-btn i {
    font-size: 1.2rem;
}

.chats-mobile-tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* Page Lock for Dedicated Full-Height WhatsApp Inbox */
body.page-chats-active {
    overflow: hidden !important;
}

body.page-chats-active #app {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

body.page-chats-active .content-wrapper {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

body.page-chats-active .main-content {
    padding: 0 !important;
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}


/* ─── Task 3.4 — Bottom Mobile Navigation Bar ───────────────────────────── */

.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    .mobile-bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 10px 4px 8px;
        cursor: pointer;
        color: var(--color-text-muted);
        font-size: 0.65rem;
        font-weight: 600;
        text-decoration: none;
        gap: 3px;
        transition: color 0.15s;
        border: none;
        background: none;
        letter-spacing: 0.02em;
        position: relative;
    }

    .mobile-bottom-nav-item i {
        font-size: 1.3rem;
        line-height: 1;
    }

    .mobile-bottom-nav-item.active,
    .mobile-bottom-nav-item:active {
        color: var(--color-primary);
    }

    /* Unread badge on Inbox tab */
    .mobile-bottom-nav-item .mobile-nav-badge {
        position: absolute;
        top: 6px;
        right: calc(50% - 18px);
        background: #25d366;
        color: #000;
        font-size: 0.6rem;
        font-weight: 700;
        min-width: 16px;
        height: 16px;
        border-radius: 8px;
        display: none;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
        line-height: 1;
    }

    /* Push main content up so it's not hidden behind the bottom nav */
    .content-wrapper {
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }

    /* Toast sits above the bottom nav on mobile */
    .toast-container {
        bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    }
}