:root {
    --wa-green: #25d366;
    --wa-green-dark: #128c7e;
    --wa-teal: #075e54;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #14532d;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
    --radius: 1rem;
    --radius-sm: 0.625rem;
}

* { box-sizing: border-box; }

body.app-body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #020617 100%);
    min-height: 100vh;
    width: 260px;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem 0.75rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.app-brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.35);
}

.app-sidebar .nav-link {
    color: #94a3b8;
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    margin: 0.15rem 0.5rem;
    font-size: 0.925rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    transition: all 0.2s ease;
}

.app-sidebar .nav-link i { font-size: 1.1rem; width: 1.25rem; }

.app-sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #f8fafc;
}

.app-sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(37, 211, 102, 0.2), transparent);
    color: #fff;
    border-left: 3px solid var(--wa-green);
    padding-left: calc(0.85rem - 3px);
}

.sidebar-user {
    margin: 1rem 0.75rem 0;
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-user .name { color: #f1f5f9; font-weight: 600; font-size: 0.9rem; }
.sidebar-user .role { color: #64748b; font-size: 0.75rem; }

.sidebar-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding: 0 1rem 1rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-sidebar .sidebar-stat-item,
.app-offcanvas .sidebar-stat-item {
    text-align: center;
    padding: 0.65rem 0.35rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.app-sidebar .sidebar-stat-number,
.app-offcanvas .sidebar-stat-number {
    color: #25d366;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.app-sidebar .sidebar-stat-label,
.app-offcanvas .sidebar-stat-label {
    color: #f1f5f9;
    font-size: 0.72rem;
    font-weight: 500;
    margin-top: 0.25rem;
    line-height: 1.2;
}

.app-offcanvas .sidebar-stats {
    padding: 0.75rem 0 0;
    margin-top: 0.75rem;
    border-bottom: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Top bar mobile */
.app-topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow);
}

.app-main {
    flex: 1;
    min-width: 0;
    padding: 1.25rem;
}

@media (min-width: 768px) {
    .app-main { padding: 1.75rem 2rem; }
}

/* Cards */
.stat-card, .card-modern {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-modern .card-header,
.stat-card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-modern .card-body,
.stat-card .card-body { padding: 1.25rem; }

/* Stat tiles */
.stat-tile {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    height: 100%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1);
}

.stat-tile-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
}

.stat-tile-icon.primary { background: #dbeafe; color: #2563eb; }
.stat-tile-icon.info { background: #e0f2fe; color: #0284c7; }
.stat-tile-icon.success { background: #dcfce7; color: #16a34a; }
.stat-tile-icon.warning { background: #fef3c7; color: #d97706; }
.stat-tile-icon.danger { background: #fee2e2; color: #dc2626; }

.stat-tile h3 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.03em;
}

.stat-tile small { color: var(--text-muted); font-weight: 500; }

/* Page header */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1, .page-header h2 {
    margin: 0;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-size: clamp(1.35rem, 2.5vw, 1.75rem);
}

/* Buttons */
.btn-wa {
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    border: none;
    color: #fff;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1.1rem;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
}

.btn-wa:hover {
    background: linear-gradient(135deg, #2ee66d, var(--wa-green));
    color: #fff;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
}

/* Tables */
.table { --bs-table-bg: transparent; }
.table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.table-hover tbody tr:hover { background: #f8fafc; }

.table-responsive-card {
    border-radius: var(--radius);
    overflow: hidden;
}

/* Badges */
.badge-status {
    font-weight: 600;
    padding: 0.35em 0.65em;
    border-radius: 6px;
    font-size: 0.75rem;
    text-transform: capitalize;
}

.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #dcfce7; color: #15803d; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-paused { background: #fef3c7; color: #b45309; }
.badge-cancelled { background: #fee2e2; color: #b91c1c; }
.badge-scheduled { background: #e0e7ff; color: #4338ca; }

/* Alerts */
.alert {
    border-radius: var(--radius-sm);
    border: none;
    box-shadow: var(--shadow);
}

/* Forms */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    padding: 0.6rem 0.85rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--wa-green);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.form-label { font-weight: 600; font-size: 0.875rem; color: #334155; }

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #0f172a 0%, #14532d 50%, #0f172a 100%);
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(37, 211, 102, 0.15) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    pointer-events: none;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 1.25rem;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.auth-card-wide { max-width: 720px; }

.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-logo .icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 0.75rem;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #fff;
}

/* Chat bubbles */
.chat-bubble {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.chat-in {
    background: #fff;
    border: 1px solid var(--border);
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
}

.chat-out {
    background: #dcf8c6;
    border: 1px solid #b8e0a8;
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
}

.chat-thread {
    max-height: 450px;
    overflow-y: auto;
    background: #f8fafc;
}

.chat-source {
    text-transform: capitalize;
    font-weight: 600;
}

.chat-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

/* DataTables */
.dataTables_wrapper .dataTables_filter input {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 0.35rem 0.65rem;
}

.dataTables_wrapper .dataTables_length select {
    border-radius: var(--radius-sm);
}

/* Error pages */
.error-page {
    text-align: center;
    padding: 4rem 1rem;
}

.error-page h1 {
    font-size: 4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Installer steps */
.install-steps {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.install-step {
    flex: 1;
    min-width: 60px;
    text-align: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    background: #f1f5f9;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.install-step.active {
    background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
    color: #fff;
}

.install-step.done { background: #dcfce7; color: #15803d; }

/* Offcanvas mobile sidebar */
.offcanvas.app-offcanvas {
    background: var(--sidebar-bg);
    color: #fff;
    width: 280px;
}

.offcanvas.app-offcanvas .nav-link { color: #94a3b8; }
.offcanvas.app-offcanvas .nav-link.active { color: #fff; }

.log-viewer {
    max-height: 500px;
    overflow: auto;
    padding: 1rem 1.25rem;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 0.8125rem;
    line-height: 1.5;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* WhatsApp template preview (campaign form) */
.wa-preview-phone {
    background: linear-gradient(180deg, #e5ddd5 0%, #d9cfc7 100%);
    border-radius: var(--radius);
    padding: 1.25rem;
    min-height: 200px;
}

.wa-preview-bubble {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    max-width: 100%;
}

.wa-preview-header-img img {
    width: 100%;
    display: block;
    max-height: 180px;
    object-fit: cover;
}

.wa-preview-header-img.wa-preview-placeholder {
    background: #f1f5f9;
    color: #94a3b8;
    text-align: center;
    padding: 2rem;
    font-size: 0.875rem;
}

.wa-preview-header-text {
    padding: 0.75rem 1rem 0;
    font-weight: 700;
    font-size: 0.9375rem;
}

.wa-preview-body {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.wa-preview-body mark,
.wa-preview-header-text mark {
    background: #dcfce7;
    color: #166534;
    padding: 0 0.2rem;
    border-radius: 3px;
}

.wa-preview-body mark.wa-var-empty,
.wa-preview-header-text mark.wa-var-empty {
    background: #fef3c7;
    color: #92400e;
}

.wa-preview-footer {
    padding: 0 1rem 0.75rem;
    font-size: 0.75rem;
    color: #64748b;
}

.wa-preview-buttons {
    border-top: 1px solid #e2e8f0;
}

.wa-preview-btn {
    text-align: center;
    padding: 0.65rem;
    color: #0ea5e9;
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 1px solid #e2e8f0;
}

.wa-preview-btn:last-child {
    border-bottom: none;
}
