:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --success: #16a34a;
    --bg: #f5f6fa;
    --card-bg: #ffffff;
    --text: #1f2430;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.auth-card h1 {
    font-size: 20px;
    margin: 0 0 24px;
    text-align: center;
}

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

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

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 11px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.btn:hover { background: var(--primary-dark); }

.btn-block { width: 100%; }

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

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 18px;
}

.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

/* Layout admin (utilisé dès l'étape dashboard) */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: #1f2430;
    color: #fff;
    padding: 20px 0;
    flex-shrink: 0;
}

.sidebar .brand {
    padding: 0 20px 20px;
    font-weight: 700;
    font-size: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 12px;
}

.sidebar a {
    display: block;
    padding: 10px 20px;
    color: #cbd0dc;
    text-decoration: none;
    font-size: 14px;
}

.sidebar a:hover, .sidebar a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.main-content {
    flex: 1;
    padding: 30px;
}

.main-content > * {
    max-width: 1100px;
}

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

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ============================================
   Campagnes — statistiques, badges, table, actions
   ============================================ */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0 0 4px;
    font-size: 26px;
}

.page-header .page-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

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

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #f9fafb;
}

.engine-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #15803d;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    padding: 8px 14px;
    border-radius: 8px;
}

/* Grille de statistiques */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
}

.stat-card.stat-accent .stat-value { color: var(--primary); }
.stat-card.stat-warning .stat-value { color: #d97706; }
.stat-card.stat-success .stat-value { color: var(--success); }

/* Badges de statut */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-draft     { background: #f3f4f6; color: #4b5563; }
.status-scheduled { background: #eff6ff; color: #2563eb; }
.status-sending   { background: #fffbeb; color: #d97706; }
.status-sent      { background: #f0fdf4; color: #16a34a; }
.status-paused    { background: #fffbeb; color: #d97706; }
.status-cancelled { background: #fef2f2; color: #dc2626; }

/* Table des campagnes */
.campaigns-table-wrap {
    overflow-x: auto;
    margin: 0 -24px;
    padding: 0 24px;
}

.campaigns-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 760px;
}

.campaigns-table thead th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.campaigns-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s ease;
}

.campaigns-table tbody tr:hover {
    background: #fafafe;
}

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

.campaigns-table td {
    padding: 14px 12px;
    vertical-align: top;
}

.campaign-name {
    font-weight: 600;
    color: var(--text);
    display: block;
}

.campaign-subject {
    color: var(--text-muted);
    font-size: 12px;
    display: block;
    margin-top: 2px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recipients-count {
    font-weight: 600;
    font-size: 15px;
}

.progress-detail {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.progress-bar-track {
    background: #e5e7eb;
    border-radius: 4px;
    height: 6px;
    width: 120px;
    margin-top: 5px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-bar-fill.is-complete { background: var(--success); }
.progress-bar-fill.is-active { background: #f59e0b; }

.engagement-stats {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.engagement-stats .engagement-link {
    display: inline-block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 600;
}

.no-data {
    color: #9ca3af;
}

.created-date {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}

/* Boutons d'action en icônes */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    font-size: 15px;
    line-height: 1;
    transition: background 0.12s ease, color 0.12s ease;
}

.action-btn:hover {
    background: #f3f4f6;
    color: var(--text);
}

.action-btn.action-send:hover { background: #f0fdf4; color: var(--success); }
.action-btn.action-danger:hover { background: #fef2f2; color: var(--danger); }

/* État vide */
.empty-state {
    text-align: center;
    padding: 56px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-state p {
    margin: 0 0 18px;
    font-size: 14px;
}

/* Responsive : sidebar en haut sur petits écrans */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        padding: 12px 0;
    }
    .main-content {
        padding: 16px;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   Listes de diffusion
   ============================================ */

.section-title {
    margin: 0 0 4px;
    font-size: 16px;
}

.section-hint {
    margin: 0 0 18px;
    font-size: 13px;
    color: var(--text-muted);
}

.list-form-card {
    margin-bottom: 24px;
}

.list-form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.list-form-row .form-group {
    flex: 1;
    min-width: 220px;
    margin-bottom: 0;
}

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

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.bulk-action-btn {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.bulk-action-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.bulk-action-btn:not(:disabled):hover {
    background: #fef2f2;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s ease;
}

.data-table tbody tr:hover {
    background: #fafafe;
}

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

.data-table td {
    padding: 12px;
    vertical-align: middle;
}

.data-table td.col-checkbox {
    width: 34px;
}

.list-name-cell {
    font-weight: 600;
    color: var(--text);
}

.list-description-cell {
    color: var(--text-muted);
    font-size: 13px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subscriber-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #eef2ff;
    color: var(--primary);
    text-decoration: none;
}

.subscriber-badge:hover {
    background: #e0e7ff;
}

.subscriber-badge .badge-total {
    color: var(--text-muted);
    font-weight: 500;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ============================================
   Templates d'emails
   ============================================ */

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}

.template-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.template-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

.template-thumb {
    position: relative;
    height: 150px;
    background: #f3f4f6;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
}

.template-thumb iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 400%;
    height: 400%;
    border: none;
    transform: scale(0.25);
    transform-origin: top left;
    pointer-events: none;
    background: #fff;
}

.template-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    font-size: 32px;
}

.template-body {
    padding: 14px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.template-name {
    font-weight: 600;
    font-size: 14px;
    margin: 0 0 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-subject {
    color: var(--text-muted);
    font-size: 12.5px;
    margin: 0 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-meta {
    font-size: 11.5px;
    color: #9ca3af;
    margin: 0 0 12px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.template-actions {
    display: flex;
    gap: 6px;
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.template-actions a,
.template-actions button {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    border-radius: 6px;
    border: none;
    background: #f3f4f6;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease;
}

.template-actions a:hover,
.template-actions button:hover {
    background: #e5e7eb;
}

.template-actions button.action-danger {
    color: var(--danger);
}

.template-actions button.action-danger:hover {
    background: #fef2f2;
}

/* ============================================
   Tableau de bord
   ============================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    align-items: start;
}

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

.dashboard-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-title-row h3 {
    margin: 0;
    font-size: 16px;
}

.card-title-row a {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

.card-title-row a:hover { text-decoration: underline; }

/* Fil d'activité récente */
.activity-feed {
    display: flex;
    flex-direction: column;
}

.activity-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; padding-bottom: 0; }
.activity-item:first-child { padding-top: 0; }

.activity-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: #eef2ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.activity-body { min-width: 0; }

.activity-text {
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-text strong { font-weight: 600; }

.activity-time {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Répartition des contacts */
.breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.breakdown-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
}

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

.breakdown-label {
    flex: 1;
    color: var(--text);
}

.breakdown-count {
    font-weight: 700;
    color: var(--text);
}

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

@media (max-width: 640px) {
    .quick-actions { width: 100%; }
    .quick-actions .btn, .quick-actions .btn-secondary { flex: 1; text-align: center; }
}
