/* ======================================
   ChatBot SaaS - Enterprise Design System
   ====================================== */

:root {
    /* --- Light Mode (Default) --- */
    --bg-primary: #F9FAFB;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F3F4F6;
    --bg-card: #FFFFFF;
    --bg-sidebar: #111827; /* Always dark for professional look */
    
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --text-on-dark: #F9FAFB;
    
    --border-color: #E5E7EB;
    --border-hover: #D1D5DB;
    
    --accent-primary: #2563EB;   /* Royal Blue */
    --accent-hover: #1D4ED8;
    --accent-secondary: #64748B; /* Slate */
    
    --status-success: #059669;
    --status-warning: #D97706;
    --status-error: #DC2626;
    --status-info: #3B82F6;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --sidebar-width: 250px;
    --header-height: 64px;
    
    --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    /* --- Dark Mode Override --- */
    --bg-primary: #0F172A;
    --bg-secondary: #1E293B;
    --bg-tertiary: #334155;
    --bg-card: #1E293B;
    --bg-sidebar: #0F172A;
    
    --text-primary: #F3F4F6;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    
    --border-color: #334155;
    --border-hover: #475569;
    
    --accent-primary: #3B82F6;
    --accent-hover: #60A5FA;
    --accent-secondary: #94A3B8;
    
    --status-success: #10B981;
    --status-warning: #F59E0B;
    --status-error: #EF4444;
    --status-info: #60A5FA;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

/* ======================================
   Reset & Base
   ====================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px; /* Slightly tighter for enterprise density */
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-base);
}

a:hover {
    color: var(--accent-hover);
}

button {
    font-family: inherit;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* ======================================
   Typography
   ====================================== */

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.25;
}

h1 { font-size: 1.875rem; } /* 30px */
h2 { font-size: 1.5rem; }   /* 24px */
h3 { font-size: 1.25rem; }  /* 20px */
h4 { font-size: 1.125rem; } /* 18px */

small, .text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* ======================================
   Components: Buttons
   ====================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
    white-space: nowrap;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent-primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--status-error);
    color: #ffffff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ======================================
   Components: Inputs & Forms
   ====================================== */

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.input-wrapper {
    position: relative;
}

.input-wrapper i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.625rem 1rem;
    padding-left: 1rem; /* Adjust if icon present handled by input-wrapper class below */
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input-wrapper input {
    padding-left: 2.75rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

input::placeholder {
    color: var(--text-muted);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-wrapper input {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    accent-color: var(--accent-primary);
}

/* ======================================
   Layout: Auth
   ====================================== */

.auth-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg-tertiary);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border: 1px solid var(--border-color);
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.auth-logo i {
    font-size: 2rem;
    color: var(--accent-primary);
}

.auth-logo span {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ======================================
   Layout: Dashboard
   ====================================== */

.dashboard-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg-tertiary); /* Light gray bg for dashboard */
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    transition: transform var(--transition-base);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo span {
    color: #FFFFFF;
    font-weight: 600;
    font-size: 1.125rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 0.75rem;
    overflow-y: auto;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #9CA3AF;
    border-radius: var(--radius-md);
    margin-bottom: 0.25rem;
    font-weight: 500;
    transition: all var(--transition-base);
}

.nav-item a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #FFFFFF;
}

.nav-item.active a {
    background: var(--accent-primary);
    color: #FFFFFF;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-size: 0.875rem;
}

.user-details .user-name {
    display: block;
    color: #FFFFFF;
    font-size: 0.875rem;
    font-weight: 500;
}

.user-details .user-plan {
    display: block;
    color: #9CA3AF;
    font-size: 0.75rem;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.main-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Page Content */
.page-content {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

.page {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ======================================
   Cards & Stats
   ====================================== */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 0.25rem;
    font-family: var(--font-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

/* Stat colors */
.stat-icon.green { background: #DCFCE7; color: #166534; }
.stat-icon.blue { background: #DBEAFE; color: #1E40AF; }
.stat-icon.purple { background: #F3E8FF; color: #6B21A8; }
.stat-icon.orange { background: #FEF3C7; color: #92400E; }

[data-theme="dark"] .stat-icon.green { background: rgba(5, 150, 105, 0.2); color: #34D399; }
[data-theme="dark"] .stat-icon.blue { background: rgba(59, 130, 246, 0.2); color: #60A5FA; }
[data-theme="dark"] .stat-icon.purple { background: rgba(124, 58, 237, 0.2); color: #A78BFA; }
[data-theme="dark"] .stat-icon.orange { background: rgba(217, 119, 6, 0.2); color: #FBBF24; }

/* ======================================
   Tables & Lists
   ====================================== */

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 0.75rem 1.5rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.875rem;
}

tr:last-child td {
    border-bottom: none;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.active, .status-badge.sent, .status-badge.connected {
    background: #DCFCE7;
    color: #166534;
}

.status-badge.paused, .status-badge.pending, .status-badge.queued {
    background: #FEF3C7;
    color: #92400E;
}

.status-badge.stopped, .status-badge.failed, .status-badge.disconnected, .status-badge.suspended {
    background: #FEE2E2;
    color: #991B1B;
}

[data-theme="dark"] .status-badge.active { background: rgba(5, 150, 105, 0.2); color: #34D399; }
[data-theme="dark"] .status-badge.paused { background: rgba(217, 119, 6, 0.2); color: #FBBF24; }
[data-theme="dark"] .status-badge.stopped { background: rgba(220, 38, 38, 0.2); color: #F87171; }

/* ======================================
   WhatsApp QR & Status
   ====================================== */

.whatsapp-connection {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    text-align: center;
}

.connection-status h4 {
    margin: 1rem 0 0.5rem;
}

.connection-status p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.qr-code {
    background: white; /* QR always on white for scanning reliability */
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
}

.qr-code img {
    width: 200px;
    height: 200px;
    display: block;
}

/* ======================================
   Theme Toggler
   ====================================== */
.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: color var(--transition-base);
}

.theme-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* ======================================
   Toast
   ====================================== */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    min-width: 320px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ======================================
   Responsive
   ====================================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
