/* =====================================================
   CRM Divorce Leads — Admin Design
   Couleurs: fond #f8f9fa, sidebar #1e293b, accents #3b82f6
   ===================================================== */

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

:root {
    --bg: #f8f9fa;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --text: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --white: #ffffff;
    --border: #e2e8f0;
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --info: #3b82f6;
    --info-bg: #dbeafe;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

html {
    font-size: 14px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

/* =====================================================
   Layout
   ===================================================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* =====================================================
   Sidebar
   ===================================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

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

.logo-icon {
    font-size: 24px;
    color: var(--accent);
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -0.3px;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: #cbd5e1;
    font-size: 24px;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: var(--white);
}

.sidebar-nav a.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-separator {
    border-top: 1px solid rgba(255,255,255,0.08);
    margin: 12px 0;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.admin-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 700;
    font-size: 14px;
}

.admin-name {
    font-size: 13px;
    color: #cbd5e1;
}

.logout-link {
    color: #94a3b8;
    font-size: 18px;
    transition: color 0.15s;
}

.logout-link:hover {
    color: var(--danger);
}

/* =====================================================
   Main Content
   ===================================================== */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

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

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text);
    padding: 4px;
}

.page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.current-date {
    font-size: 13px;
    color: var(--text-light);
}

.content-wrapper {
    padding: 24px;
    max-width: 1400px;
}

/* =====================================================
   Alerts / Flash Messages
   ===================================================== */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: var(--danger-bg);
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-warning {
    background: var(--warning-bg);
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert-info {
    background: var(--info-bg);
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.alert-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    margin-left: 12px;
}

.alert-close:hover {
    opacity: 1;
}

/* =====================================================
   Cards
   ===================================================== */

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

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

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

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* =====================================================
   Stats Grid (Dashboard)
   ===================================================== */

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

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--accent-light); color: var(--accent); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.orange { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.2;
    color: var(--text);
}

.stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 2px;
}

/* =====================================================
   Bar Chart (CSS-only)
   ===================================================== */

.chart-container {
    padding: 10px 0;
}

.chart-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.chart-bar-label {
    width: 160px;
    font-size: 13px;
    color: var(--text-light);
    text-align: right;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-bar-track {
    flex: 1;
    height: 28px;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.chart-bar-fill {
    height: 100%;
    border-radius: var(--radius-sm);
    transition: width 0.6s ease;
    display: flex;
    align-items: center;
    padding: 0 10px;
    min-width: 32px;
}

.chart-bar-fill.blue { background: var(--accent); color: var(--white); }
.chart-bar-fill.green { background: var(--success); color: var(--white); }
.chart-bar-fill.orange { background: var(--warning); color: var(--white); }

.chart-bar-value {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

/* =====================================================
   Tables
   ===================================================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

table th,
table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

table th {
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    background: #f8fafc;
    position: sticky;
    top: 0;
}

table tbody tr:hover {
    background: #f8fafc;
}

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

/* =====================================================
   Badges
   ===================================================== */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-info { background: var(--info-bg); color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: var(--text-light); }

.badge-site-1 { background: #dbeafe; color: #1e40af; }
.badge-site-2 { background: #d1fae5; color: #065f46; }
.badge-site-3 { background: #fef3c7; color: #92400e; }

/* =====================================================
   Buttons
   ===================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-primary {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}

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

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

.btn-success:hover {
    background: #059669;
    color: var(--white);
}

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

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

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

.btn-outline {
    background: var(--white);
    color: var(--text);
    border-color: var(--border);
}

.btn-outline:hover {
    background: #f8fafc;
    color: var(--text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* =====================================================
   Forms
   ===================================================== */

.form-group {
    margin-bottom: 16px;
}

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

.form-group .form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

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

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

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

.form-inline {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-inline .form-group {
    margin-bottom: 0;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* =====================================================
   Filters Bar
   ===================================================== */

.filters-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 16px 20px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}

.filters-bar .form-group {
    margin-bottom: 0;
    min-width: 150px;
}

.filters-bar .form-control {
    font-size: 13px;
    padding: 6px 10px;
}

/* =====================================================
   Pagination
   ===================================================== */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--white);
    transition: all 0.15s;
}

.pagination a:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .active {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}

.pagination .disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =====================================================
   Login Page
   ===================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 20px;
}

.login-box {
    background: var(--white);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

.login-logo .logo-icon {
    font-size: 40px;
    color: var(--accent);
    display: block;
    margin-bottom: 8px;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
}

.login-logo p {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

.login-box .form-control {
    padding: 12px 14px;
    font-size: 15px;
}

.login-box .btn {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    justify-content: center;
    margin-top: 8px;
}

.login-error {
    background: var(--danger-bg);
    color: #991b1b;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid #fca5a5;
}

/* =====================================================
   Detail Page
   ===================================================== */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.detail-label {
    width: 160px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    flex-shrink: 0;
}

.detail-value {
    font-size: 14px;
    color: var(--text);
    flex: 1;
}

/* =====================================================
   Empty State
   ===================================================== */

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

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.empty-state p {
    font-size: 15px;
}

/* =====================================================
   Toggle Switch
   ===================================================== */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent);
}

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

/* =====================================================
   Tabs
   ===================================================== */

.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* =====================================================
   Log entries
   ===================================================== */

.log-entry {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.log-time {
    width: 140px;
    color: var(--text-muted);
    flex-shrink: 0;
    font-family: monospace;
}

.log-message {
    flex: 1;
    color: var(--text);
}

/* =====================================================
   Connection Test Result
   ===================================================== */

.test-result {
    padding: 16px;
    border-radius: var(--radius);
    margin-top: 16px;
    display: none;
}

.test-result.show {
    display: block;
}

.test-result.success {
    background: var(--success-bg);
    border: 1px solid #a7f3d0;
}

.test-result.error {
    background: var(--danger-bg);
    border: 1px solid #fca5a5;
}

.test-result pre {
    margin-top: 8px;
    font-size: 12px;
    background: rgba(0,0,0,0.05);
    padding: 8px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* =====================================================
   Topic Tag
   ===================================================== */

.topic-keywords {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.topic-keyword {
    display: inline-block;
    padding: 2px 8px;
    background: #f1f5f9;
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-light);
}

/* =====================================================
   Article Content Preview
   ===================================================== */

.article-preview {
    max-height: 400px;
    overflow-y: auto;
    padding: 20px;
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.8;
}

.article-preview h2 {
    font-size: 20px;
    margin: 20px 0 10px;
    color: var(--text);
}

.article-preview h3 {
    font-size: 16px;
    margin: 16px 0 8px;
    color: var(--text);
}

.article-preview p {
    margin-bottom: 12px;
}

.article-preview ul, .article-preview ol {
    margin: 8px 0 12px 24px;
}

/* =====================================================
   Utility Classes
   ===================================================== */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-sm { font-size: 12px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.gap-2 { gap: 16px; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.flex-1 { flex: 1; }
.fw-bold { font-weight: 700; }
.nowrap { white-space: nowrap; }

/* =====================================================
   Responsive
   ===================================================== */

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

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-close {
        display: block;
    }

    .hamburger {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .content-wrapper {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-bar .form-group {
        min-width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .chart-bar-label {
        width: 100px;
        font-size: 11px;
    }
}

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

    .login-box {
        padding: 28px 20px;
    }
}
