/* ==========================================
   WA CS AI Agent — Premium Dark Theme
   Inspired by WhatsApp Dark Mode
   ========================================== */

/* ==========================================
   CSS Variables / Design Tokens
   ========================================== */
:root {
    /* WA-inspired greens */
    --wa-green: #25d366;
    --wa-green-dark: #128c7e;
    --wa-teal: #075e54;
    --wa-light-green: #dcf8c6;

    /* Dark theme */
    --bg-primary: #0b141a;
    --bg-secondary: #111b21;
    --bg-tertiary: #1f2c34;
    --bg-card: rgba(17, 27, 33, 0.85);
    --bg-hover: rgba(37, 211, 102, 0.08);

    /* Surfaces */
    --surface-1: #202c33;
    --surface-2: #2a3942;
    --surface-3: #374045;

    /* Text */
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --text-accent: #25d366;

    /* Borders */
    --border: rgba(134, 150, 160, 0.15);
    --border-accent: rgba(37, 211, 102, 0.3);

    /* Chat bubbles */
    --bubble-out: #005c4b;
    --bubble-in: #202c33;

    /* Status colors */
    --success: #25d366;
    --error: #ea4335;
    --warning: #f59e0b;
    --info: #53bdeb;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 20px rgba(37, 211, 102, 0.15);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --sidebar-width: 240px;
}

/* ==========================================
   Reset & Base
   ========================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

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

code, .textarea-code {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
}

::selection {
    background: rgba(37, 211, 102, 0.3);
    color: #fff;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ==========================================
   Background Effects
   ========================================== */
.bg-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: var(--wa-teal);
    top: -150px;
    left: -100px;
    animation: float1 20s ease-in-out infinite;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: var(--wa-green-dark);
    bottom: -100px;
    right: -100px;
    animation: float2 25s ease-in-out infinite;
}

@keyframes float1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(60px, 40px) scale(1.1); }
}

@keyframes float2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-50px, -30px) scale(1.05); }
}

/* ==========================================
   App Layout
   ========================================== */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ==========================================
   Sidebar
   ========================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--wa-green), var(--wa-teal));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-glow);
}

.logo h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.logo-sub {
    font-size: 0.7rem;
    color: var(--wa-green);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    font-size: 0.87rem;
    font-weight: 500;
    text-align: left;
    width: 100%;
    position: relative;
}

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

.nav-btn.active {
    background: rgba(37, 211, 102, 0.12);
    color: var(--wa-green);
}

.nav-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--wa-green);
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--wa-green);
    color: #000;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

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

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.disconnected { background: var(--error); }
.status-dot.connecting, .status-dot.waiting_qr, .status-dot.reconnecting {
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ==========================================
   Main Content
   ========================================== */
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.page {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    padding: 24px 32px;
}

.page.active {
    display: flex;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    flex: 1;
}

/* ==========================================
   Cards
   ========================================== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition-normal);
}

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

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

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ==========================================
   Buttons
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.25);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.35);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-outline:hover {
    border-color: var(--wa-green);
    color: var(--wa-green);
    background: rgba(37, 211, 102, 0.05);
}

.btn-danger {
    color: var(--error) !important;
    border-color: rgba(234, 67, 53, 0.3) !important;
}
.btn-danger:hover {
    background: rgba(234, 67, 53, 0.1) !important;
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}
.btn-send:hover { transform: scale(1.05); box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ==========================================
   Form Elements
   ========================================== */
.input-group {
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.input-field, .textarea-field {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    outline: none;
}

.input-field:focus, .textarea-field:focus {
    border-color: var(--wa-green);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

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

.textarea-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
}

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

/* Toggle switch */
.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle input { display: none; }

.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--surface-3);
    border-radius: 12px;
    position: relative;
    transition: background var(--transition-fast);
}

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

.toggle input:checked + .toggle-slider {
    background: var(--wa-green);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Badge */
.badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(37, 211, 102, 0.15);
    color: var(--wa-green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.settings-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.6;
}

.settings-hint code {
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
    color: var(--wa-green);
}

/* ==========================================
   Chat Page
   ========================================== */
#pageLiveChat {
    padding: 0;
}

#pageLiveChat .page-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}

.chat-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.6;
}

.chat-empty-sub {
    font-size: 0.82rem;
    margin-top: 4px;
}

.chat-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    animation: bubbleIn 0.3s var(--transition-slow);
    white-space: pre-wrap;
    word-wrap: break-word;
}

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

.chat-bubble.user {
    background: var(--bubble-out);
    color: var(--text-primary);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    background: var(--bubble-in);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.chat-bubble .bubble-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.chat-bubble .bubble-meta {
    font-size: 0.7rem;
    color: var(--wa-green);
    margin-top: 2px;
}

.chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bubble-in);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingDot 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-bar {
    display: flex;
    gap: 10px;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-input:focus {
    border-color: var(--wa-green);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

/* ==========================================
   Conversations Page
   ========================================== */
.conv-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
}

.conv-list {
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border);
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: rgba(37, 211, 102, 0.1); }

.conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    color: var(--text-muted);
}

.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-phone {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.conv-meta {
    text-align: right;
    flex-shrink: 0;
}

.conv-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.conv-count {
    font-size: 0.68rem;
    color: var(--wa-green);
    margin-top: 2px;
}

.conv-detail {
    overflow-y: auto;
    padding: 20px;
}

.conv-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.conv-detail-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conv-empty, .kb-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
}

.kb-empty-icon { font-size: 2.5rem; margin-bottom: 8px; opacity: 0.5; }
.conv-empty .sub, .kb-empty .sub { font-size: 0.8rem; margin-top: 4px; }

/* ==========================================
   Knowledge Base Page
   ========================================== */
.kb-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.kb-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    transition: all var(--transition-normal);
}

.kb-card:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-glow);
}

.kb-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 10px;
}

.kb-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.kb-card-category {
    font-size: 0.7rem;
    color: var(--wa-green);
    background: rgba(37, 211, 102, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
}

.kb-card-content {
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.kb-inactive {
    opacity: 0.5;
}

/* ==========================================
   Settings Page
   ========================================== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.settings-card-wide {
    grid-column: 1 / -1;
}

.qr-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: var(--surface-1);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.qr-container img {
    border-radius: var(--radius-sm);
    max-width: 250px;
}

.qr-placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.qr-placeholder .sub {
    font-size: 0.75rem;
    margin-top: 4px;
}

.wa-actions {
    display: flex;
    gap: 10px;
}

.prompt-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.system-alerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.system-alert-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: rgba(15, 23, 42, 0.35);
}

.system-alert-item.warning {
    border-color: rgba(245, 158, 11, 0.5);
    background: rgba(245, 158, 11, 0.12);
}

.system-alert-item.critical {
    border-color: rgba(239, 68, 68, 0.55);
    background: rgba(239, 68, 68, 0.12);
}

.system-health-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.system-health-badge.healthy {
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
}

.system-health-badge.warning {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
}

.system-health-badge.critical {
    background: rgba(239, 68, 68, 0.18);
    color: #f87171;
}

/* ==========================================
   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: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s var(--transition-slow);
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } }

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

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.btn-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px; }

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

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

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s var(--transition-slow);
    max-width: 340px;
}

.toast.success { border-color: var(--success); }
.toast.success span:first-child { color: var(--success); }
.toast.error { border-color: var(--error); }
.toast.error span:first-child { color: var(--error); }
.toast.info { border-color: var(--info); }
.toast.info span:first-child { color: var(--info); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ==========================================
   Analytics Page
   ========================================== */
.analytics-period {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.period-btn {
    padding: 4px 12px !important;
    font-size: 0.75rem !important;
}

.period-btn.active {
    background: rgba(37, 211, 102, 0.15) !important;
    border-color: var(--wa-green) !important;
    color: var(--wa-green) !important;
}

.analytics-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    transition: all var(--transition-normal);
}

.stat-card:hover {
    border-color: var(--border-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.stat-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--wa-green);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.analytics-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 200px;
    padding: 16px 0;
}

.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.chart-bar {
    width: 100%;
    max-width: 40px;
    background: linear-gradient(to top, var(--wa-green), var(--wa-green-dark));
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.5s ease;
}

.chart-bar-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.chart-bar-value {
    font-size: 0.72rem;
    color: var(--text-primary);
    font-weight: 600;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.busiest-hours {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.busy-hour-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.busy-hour-time {
    font-size: 0.82rem;
    font-weight: 600;
    min-width: 50px;
    color: var(--text-primary);
}

.busy-hour-bar-bg {
    flex: 1;
    height: 24px;
    background: var(--surface-1);
    border-radius: 4px;
    overflow: hidden;
}

.busy-hour-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--wa-green), var(--wa-green-dark));
    border-radius: 4px;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
}

/* Escalated badge */
.conv-escalated {
    font-size: 0.65rem;
    background: rgba(234, 67, 53, 0.15);
    color: var(--error);
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* ==========================================
   Brand Management Page
   ========================================== */
.table-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
}

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

.data-table thead {
    background: var(--surface-1);
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.brand-row:hover {
    background: rgba(255, 255, 255, 0.01);
}

.brand-id-cell {
    width: 74px;
    font-weight: 700;
    color: var(--text-secondary);
}

.brand-name-cell {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.brand-name-text {
    font-weight: 700;
    color: var(--text-primary);
}

.brand-badge-current { background: var(--primary) !important; color: #fff !important; }
.brand-badge-enabled { background: var(--success) !important; color: #fff !important; }
.brand-badge-disabled { background: var(--error) !important; color: #fff !important; }

.brand-actions-cell {
    text-align: right;
}

.brand-actions-wrap {
    display: inline-flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.brand-deactivate-btn {
    color: var(--warning) !important;
    border-color: var(--warning) !important;
}

.brand-delete-btn {
    color: var(--error) !important;
    border-color: var(--error) !important;
}

/* ==========================================
   Broadcast Page
   ========================================== */
.broadcast-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--surface-1);
    border-radius: var(--radius-md);
    padding: 4px;
}

.bcast-tab {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.bcast-tab:hover { color: var(--text-primary); }
.bcast-tab.active {
    background: rgba(37, 211, 102, 0.12);
    color: var(--wa-green);
    box-shadow: var(--shadow-sm);
}

.bcast-panel { display: none; }
.bcast-panel.active { display: block; }

.bcast-recipient-mode {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.recipient-mode-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    color: var(--text-secondary);
    font-size: 0.82rem;
    cursor: pointer;
}

.recipient-mode-option input {
    display: none;
}

.recipient-mode-option.active {
    border-color: var(--wa-green);
    color: var(--wa-green);
    background: rgba(37, 211, 102, 0.08);
}

/* Message type selector */
.msg-type-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.msg-type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--surface-1);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 80px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.msg-type-option input { display: none; }
.msg-type-option:hover { border-color: var(--wa-green); color: var(--text-primary); }
.msg-type-option.active {
    border-color: var(--wa-green);
    background: rgba(37, 211, 102, 0.08);
    color: var(--wa-green);
}

.msg-type-icon { font-size: 1.3rem; }

/* Progress bar */
.bcast-progress {
    margin-top: 16px;
}

.bcast-progress-bar {
    height: 12px;
    background: var(--surface-1);
    border-radius: 6px;
    overflow: hidden;
}

.bcast-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--wa-green), var(--wa-green-dark));
    border-radius: 6px;
    transition: width 0.5s ease;
    box-shadow: 0 0 10px rgba(37, 211, 102, 0.4);
}

.bcast-progress-text {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* Group members */
.group-members-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 30px;
}

.member-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.member-chip .remove-member {
    cursor: pointer;
    color: var(--error);
    font-weight: bold;
    background: none;
    border: none;
    font-size: 0.9rem;
    padding: 0;
    line-height: 1;
}

/* List builder */
.list-section-block {
    background: var(--surface-1);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

/* Campaign status badges */
.bcast-status {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}
.bcast-status.draft { background: rgba(134,150,160,0.2); color: var(--text-muted); }
.bcast-status.sending { background: rgba(245,158,11,0.15); color: var(--warning); }
.bcast-status.completed { background: rgba(37,211,102,0.15); color: var(--success); }
.bcast-status.cancelled { background: rgba(234,67,53,0.15); color: var(--error); }

/* Chat Preview Phone */
.preview-phone {
    background: #0b141a;
    border-radius: 16px;
    overflow: hidden;
    max-width: 380px;
    margin: 0 auto;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

.preview-phone-header {
    background: #1f2c34;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #e9edef;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.preview-phone-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #00a884;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.preview-phone-body {
    padding: 14px;
    min-height: 120px;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.preview-bubble {
    background: #005c4b;
    border-radius: 0 8px 8px 8px;
    padding: 8px 12px;
    max-width: 95%;
    position: relative;
}

.preview-bubble-text {
    color: #e9edef;
    font-size: 0.84rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.preview-bubble-footer {
    font-size: 0.72rem;
    color: rgba(233,237,239,0.5);
    margin-top: 4px;
    padding: 0 12px 4px;
}

.preview-bubble-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    padding: 0 4px;
}

.preview-btn {
    background: rgba(0,168,132,0.15);
    border: 1px solid rgba(0,168,132,0.3);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    color: #00a884;
    font-size: 0.82rem;
    font-weight: 500;
}

.preview-bubble-list {
    margin-top: 6px;
}

.preview-list-btn {
    background: rgba(0,168,132,0.15);
    border: 1px solid rgba(0,168,132,0.3);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    color: #00a884;
    font-size: 0.82rem;
    font-weight: 500;
    margin: 4px 4px 0;
}

.preview-list-items {
    padding: 4px;
}

.preview-list-item {
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.78rem;
    color: #e9edef;
}

.preview-list-item .item-desc {
    font-size: 0.7rem;
    color: rgba(233,237,239,0.4);
}

.preview-bubble-media {
    margin-top: 6px;
}

.preview-bubble-media img {
    max-width: 100%;
    border-radius: 8px;
}

.preview-media-placeholder {
    background: #1f2c34;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.preview-phone-time {
    text-align: center;
    font-size: 0.7rem;
    color: rgba(233,237,239,0.3);
    padding: 6px;
    background: #0b141a;
    border-top: 1px solid rgba(255,255,255,0.04);
}

/* ==========================================
   Auto Reply Page
   ========================================== */
.ar-test-bar {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ar-test-result {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    line-height: 1.5;
    animation: fadeIn 0.2s ease;
}

.ar-test-result.matched {
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.3);
    color: var(--text-primary);
}

.ar-test-result.no-match {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: var(--text-secondary);
}

.ar-match-badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 6px;
    vertical-align: middle;
}

.ar-match-badge.contains {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.ar-match-badge.exact {
    background: rgba(37, 211, 102, 0.15);
    color: var(--wa-green);
}

.ar-match-badge.starts_with {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

/* ==========================================
   Utilities
   ========================================== */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 900px) {
    .sidebar { width: 60px; }
    .sidebar .logo h1, .sidebar .logo-sub, .nav-btn span, .nav-badge,
    .sidebar-footer .status-text { display: none; }
    .sidebar-header { padding: 16px 10px; }
    .sidebar-nav { padding: 8px 4px; }
    .nav-btn { justify-content: center; padding: 10px; }
    .nav-btn.active::before { display: none; }
    .settings-grid { grid-template-columns: 1fr; }
    .conv-layout { grid-template-columns: 1fr; }
    .conv-detail { display: none; }
    .page { padding: 16px; }
    .analytics-stats { grid-template-columns: repeat(2, 1fr); }
    .analytics-charts { grid-template-columns: 1fr; }
    .msg-type-grid { gap: 4px; }
    .msg-type-option { min-width: 60px; padding: 8px; }
}
