/* Variables sémantiques — thème clair (repli sans-JS) */
:root {
    color-scheme: light;

    /* Accent + statuts */
    --primary-color: #457d6d;   /* remplace #2563eb — couleur de marque */
    --success-color: #16a34a;
    --warning-color: #f59e0b;
    --danger-color: #dc2626;

    /* Surfaces */
    --bg: #f3f4f6;              /* fond de page */
    --surface: #ffffff;         /* cartes, tableaux, navbar, modales */
    --surface-muted: #f3f4f6;   /* entêtes de tableau, badges neutres */
    --border: #e5e7eb;
    --inverse-surface: #1f2937; /* bandeau de confirmation (fond sombre fixe) */

    /* Textes */
    --text: #1f2937;
    --text-muted: #6b7280;

    /* Fonds teintés (alertes + lignes) */
    --success-tint: #f0fdf4;
    --danger-tint: #fef2f2;
    --selected-tint: #eff6ff;
}

/* Thème sombre */
:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f172a;
    --surface: #1e293b;
    --surface-muted: #273449;
    --border: #334155;
    --inverse-surface: #0b1220;

    --text: #e5e7eb;
    --text-muted: #94a3b8;

    --success-tint: #12261c;
    --danger-tint: #2a1518;
    --selected-tint: #17233a;

    /* --primary/success/warning/danger : inchangés */
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
}

main {
    max-width: none;
    margin: 0 auto;
    padding: 2rem;
}

/* Buttons */
button, .btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 1rem;
}

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

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

.btn-email:disabled {
    background-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.75;
}

.btn-linkedin {
    background-color: #0A66C2;
    color: white;
}

.btn-linkedin:hover {
    background-color: #004182;
}

.btn-linkedin:disabled {
    background-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.75;
}

/* Form inputs */
input, textarea, select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 1rem;
}

/* Login screen */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-logo {
    display: block;
    height: 60px;
    width: auto;
    margin: 0 auto 2rem auto;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input {
    width: 100%;
}

/* Target-cities textarea: full width (story-12 — comma-separated 15 communes) */
#target_cities {
    width: 100%;
}

/* Categories textarea: full width (story-33 — matches Villes ciblées) */
#target_categories {
    width: 100%;
}

.btn-block {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.25rem;
    margin-bottom: 1rem;
}

.alert-error {
    background-color: var(--danger-tint);
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.alert-success {
    background-color: var(--success-tint);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

/* Navbar */
.navbar {
    background: var(--surface);
    padding: 5px 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.nav-brand img {
    height: 50px;
    width: auto;
    display: block;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-right {
    display: flex;
    align-items: center;
}

.nav-left a,
.nav-right a {
    color: var(--text);
    text-decoration: none;
}

.nav-left a {
    font-size: 1.225rem;
    font-weight: 700;
    color: var(--primary-color);
}

.nav-left a:hover,
.nav-right a:hover {
    color: var(--primary-color);
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
}

.campaign-title {
    color: var(--primary-color);
}

/* Boutons du dashboard « Mes campagnes » : texte noir, non souligné */
.campaigns-dashboard .btn-primary {
    color: #000000;
    text-decoration: none;
}

/* Nom de campagne dans le tableau « Mes campagnes » : couleur principale, gras, non souligné */
.campaign-name {
    color: var(--primary-color);
    font-weight: 700;
    text-decoration: none;
}

/* Campaigns table */
.campaigns-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.campaigns-table th,
.campaigns-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.campaigns-table th {
    background: var(--surface-muted);
    font-weight: 600;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.badge-draft { background: var(--surface-muted); color: var(--text); }
.badge-scraping { background: var(--warning-color); color: white; }
.badge-selection_pending { background: var(--warning-color); color: white; }
.badge-enriching { background: var(--primary-color); color: white; }
.badge-enriched { background: var(--success-color); color: white; }
/* Prospect "Enrichi" (enrichment status) — kept distinct from campaign "En cours" */
.badge-prospect-enriched { background: #7c3aed; color: white; }
.badge-completed { background: var(--success-color); color: white; }

/* Form styles */
.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.form-section h3 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.form-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* Breathing room before field titles in the campaign form (left column) */
label[for="name"],
label[for="language"],
label[for="contact_channel"],
label[for="sender_name"],
label[for="writing_instructions"] {
    margin-top: 1rem;
}

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Two-column campaign form */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: start;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Tuile statistique cliquable (lien + œil) */
.stat-card--link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.stat-card--link:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.stat-label .stat-eye {
    vertical-align: -0.125em;
    margin-left: 0.35em;
}

/* Info grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.info-grid dt {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.info-grid dd {
    margin: 0;
}

/* Auto-filter icons (transparent background, brand color) — campaign view */
.filter-icon {
    display: inline-flex;
    align-items: center;
    color: var(--primary-color);
    vertical-align: middle;
}
.filter-icon + .filter-icon { margin-left: 0.5rem; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    background: var(--surface);
    border-radius: 0.5rem;
}

.empty-state p {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

/* Buttons (small + danger) — referenced by campaign templates */
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

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

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.25rem;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.btn-icon--danger:hover {
    color: var(--danger-color);
    background: var(--danger-tint);
}

.btn-icon:hover { color: var(--primary-color); }

/* Action bar (story-04) */
.action-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.scraping-progress {
    color: var(--primary-color);
    font-weight: 500;
}

/* Simple spinner */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Disabled button */
.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Prospect selection (story-05) */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.filter-bar input[type="text"] {
    flex: 1;
    min-width: 200px;
}

.selected-counter {
    font-weight: 600;
    color: var(--primary-color);
}

.prospects-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.prospects-table th, .prospects-table td {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.prospects-table th { background: var(--surface-muted); }
/* Column sort triangles (story-34) */
.sort-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    line-height: 0;
}
.sort-arrow {
    display: inline-flex;
    color: var(--text-muted);
    text-decoration: none;
    padding: 1px 0;
}
.sort-arrow:hover { color: var(--text); }
.sort-arrow svg { display: block; }
.sort-arrow polygon {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linejoin: round;
}
/* Doit être déclaré APRÈS `.sort-arrow polygon` (même spécificité). */
.sort-arrow--active polygon { fill: currentColor; }
.col-check { width: 40px; text-align: center; }
.row-ecarte td { opacity: 0.55; }  /* rejected prospects look muted */

.badge-selectionne { background: #0891b2; color: white; }
.badge-ecarte { background: var(--danger-color); color: white; }

/* Confirmation bar fixed at bottom */
.confirm-bar {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--inverse-surface);
    color: white;
    padding: 0.9rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.confirm-bar.hidden { display: none; }

.confirm-bar .btn-primary { background: var(--success-color); }

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pagination-pages a {
    color: var(--primary-color);
    text-decoration: none;
}

.pagination-pages a:hover {
    text-decoration: underline;
}

.pagination-label {
    color: var(--text-muted);
}

.pagination-link.active {
    font-weight: 700;
    color: var(--text);
}

.pagination-sep {
    color: var(--text-muted);
}

.page-size select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

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

/* External-link icon (story-12) */
.icon-link { color: var(--primary-color); display: inline-flex; align-items: center; }

/* LinkedIn contact link + icon (story-35) */
.contact-link {
    color: inherit;
    text-decoration: none;
}

.contact-link:hover {
    text-decoration: underline;
    color: var(--primary-color);
}

.linkedin-icon,
.email-icon {
    display: block;
    width: 14px;
    margin-top: 2px;
}

/* Icônes de contact côte-à-côte sous le nom (dashboard campagne) */
.contact-icons {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.contact-icons .linkedin-icon,
.contact-icons .email-icon {
    margin-top: 0;
}

/* Enrichment screen (story-06) */
.enrichment-progress {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.row-enriched td { background: var(--success-tint); }
.row-failed td { background: var(--danger-tint); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--surface);
    border-radius: 0.5rem;
    padding: 1.5rem 2rem;
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.methods-list { list-style: none; padding: 0; }
.methods-list li { padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.methods-list code { background: var(--surface-muted); padding: 0.1rem 0.4rem; border-radius: 0.25rem; }

/* Prospect details modal (two-column table + collapsible "voir") */
.detail-table { width: 100%; border-collapse: collapse; }
.detail-table td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.detail-table .detail-label { font-weight: 600; color: var(--text-muted); white-space: nowrap; width: 1%; }

.detail-toggle { margin-top: 0.75rem; }
.detail-toggle.hidden { display: none; }
.detail-toggle summary {
    display: inline-block;
    cursor: pointer;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--surface-muted);
    font-size: 0.9rem;
    list-style: none;
}
.detail-toggle summary::-webkit-details-marker { display: none; }
.detail-toggle summary:hover { background: var(--border); }
.detail-long {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--surface-muted);
    border-radius: 0.25rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.9rem;
}

/* Messages screen (story-07) */
.messages-progress {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.channel-badge {
    margin-left: auto;
    background: var(--surface-muted);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
}

/* Unified campaign view (story-10) */
.badge-brut { background: var(--surface-muted); color: var(--text); }
.badge-pending { background: var(--surface-muted); color: var(--text); }
.badge-listed { background: var(--surface-muted); color: var(--text); border: 1px solid var(--border); }
.badge-failed { background: #b91c1c; color: white; }
.badge-generated { background: var(--success-color); color: white; }
.badge-sent { background: var(--success-color); color: white; }
.badge-in_progress { background: var(--warning-color); color: white; }
.badge-impossible { background: #9ca3af; color: white; }
.badge-error { background: #b91c1c; color: white; }

/* Message bubble (story-22) */
.msg-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    vertical-align: middle;
    cursor: default;
}
.msg-bubble--generated { cursor: pointer; }
.msg-bubble--generated:hover { opacity: 0.85; }

/* story-37: arrow to the right of a sent-message bubble */
.msg-arrow { margin-left: 3px; flex-shrink: 0; }

.row-selected td { background: var(--selected-tint); }

.bulk-actions {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    background: var(--surface-muted);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}
.bulk-actions.hidden { display: none; }

/* Scoring stars (story-31) */
.score-stars {
    display: inline-flex;
    align-items: center;
    gap: 0.05rem;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}
.score-stars:hover { opacity: 0.85; }
.star { color: var(--text-muted); }
.star--filled { color: var(--primary-color); }
.score-justification { white-space: pre-wrap; line-height: 1.6; }

.score-title { display: flex; align-items: center; gap: 0.5rem; }
.score-title .score-stars { cursor: default; }
.score-title .score-stars:hover { opacity: 1; }

.campaign-table-wrap { overflow-x: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1rem; }

.modal-disclaimer {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-muted);
    margin-top: 0.75rem;
    margin-bottom: 0;
}
.msg-textarea { width: 100%; font-family: inherit; }
.modal-wide { max-width: 720px; }
.modal-xl { max-width: 960px; }

/* story-37: sent-state in the message modal header + confirmation modal */
.msg-title { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.msg-sent-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--success-color);
    background: var(--success-tint);
    border: 1px solid var(--success-color);
    border-radius: 1rem;
    padding: 0.1rem 0.6rem;
    white-space: nowrap;
}
.msg-sent-label.hidden { display: none; }
.modal-top { z-index: 300; }
.modal-sm { max-width: 380px; }

/* Target cities modal list (story-13) — respect newline-separated cities */
.cities-list { white-space: pre-line; font-size: 0.95rem; line-height: 1.6; }

/* Theme toggle (story-24) */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 0.25rem;
    margin-right: 0.5rem;
    display: inline-flex;
    align-items: center;
}
.theme-toggle:hover { color: var(--primary-color); }
.theme-toggle .icon { width: 20px; height: 20px; }

/* Navbar settings icon (story-33) — mirrors .theme-toggle */
.nav-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    margin-right: 0.5rem;
    display: inline-flex;
    align-items: center;
}
.nav-icon:hover { color: var(--primary-color); }
.nav-icon .icon { width: 20px; height: 20px; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: inline; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* System — color field (story-25) */
.color-field { display: flex; align-items: center; gap: 0.75rem; }
.color-field input[type="color"] {
    width: 48px; height: 38px; padding: 2px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); cursor: pointer;
}
.color-field input[type="text"] { max-width: 160px; }

/* Large textareas: wider edit field (story-31 follow-up) */
#profile_summary_prompt,
#scoring_prompt,
#writing_instructions,
#scoring_instructions {
    width: 1000px;
    max-width: 100%;
}

/* Profile — two-column layout + summary (story-27) */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 800px) {
    .profile-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
}

.profile-summary {
    font-style: italic;
    margin-top: 1rem;
    line-height: 1.7;
    white-space: pre-wrap;   /* preserve the LLM text's line breaks */
}

/* System — two-column layout + inline-icon button (story-38) */
.btn-inline-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.system-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

.system-users-actions { display: flex; gap: 8px; align-items: center; }

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

.setting-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.setting-label {
    font-weight: 500;
}

/* System — users management modal (story-38) */
.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.users-table th,
.users-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.users-table th {
    background: var(--surface-muted);
    font-weight: 600;
}

.user-row:hover { background: var(--surface-muted); }

.user-row-actions { text-align: right; }

.badge-admin {
    background: var(--primary-color);
    color: white;
}

