/* ════════════════════════════════════════════════════════════
   CRM Centre Atlas - Design système
   Sombre, futuriste, accessibilité AAA
   ════════════════════════════════════════════════════════════ */

:root {
    /* Fond */
    --bg-base: #0A0F1A;
    --bg-sidebar: #111827;
    --bg-card: #1A2332;
    --bg-input: #0F1722;
    --bg-hover: #243042;

    /* Bordures */
    --border: #2A3447;
    --border-strong: #3A4558;

    /* Texte (contrastes AAA) */
    --text: #E5E7EB;
    --text-muted: #9CA3AF;
    --text-strong: #FFFFFF;

    /* Accents Centre Atlas */
    --primary: #1B4F5C;
    --primary-light: #2E7585;
    --primary-glow: rgba(46, 117, 133, 0.3);
    --accent-red: #D74638;

    /* Services */
    --service-bureaux: #3B82F6;
    --service-salles: #F97316;
    --service-coworking: #A16207;
    --service-domiciliation: #A855F7;
    --service-resilie: #DC2626;
    --service-actif: #10B981;

    /* États */
    --success: #10B981;
    --warning: #F59E0B;
    --error: #DC2626;
    --info: #3B82F6;

    /* Espacements */
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

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

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { color: var(--text-strong); }

/* ────────────── LAYOUT ────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

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

.brand {
    color: var(--text-strong);
    font-weight: 700;
    line-height: 1.1;
}

.brand-text { font-size: 18px; letter-spacing: 0.05em; }
.brand-text-2 { color: var(--accent-red); }
.brand-sub { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; letter-spacing: 0.2em; }

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    color: var(--text-muted);
    border-radius: var(--radius);
    margin-bottom: 4px;
    transition: var(--transition);
    font-weight: 500;
    font-size: 15px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary); color: var(--text-strong); }
.nav-icon { font-size: 18px; opacity: 0.9; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }

.user-info { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.user-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--text-strong);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px;
}
.user-name { color: var(--text); font-weight: 600; font-size: 14px; }
.user-role { color: var(--text-muted); font-size: 12px; text-transform: capitalize; }
.logout-btn {
    display: block; text-align: center;
    padding: 10px; border-radius: var(--radius);
    background: var(--bg-hover); color: var(--text-muted);
    font-size: 13px; font-weight: 500;
}
.logout-btn:hover { color: var(--accent-red); }

.main { flex: 1; margin-left: 260px; min-height: 100vh; display: flex; flex-direction: column; }

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

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

.page-title { flex: 1; font-size: 18px; font-weight: 600; color: var(--text-strong); }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 24px; flex: 1; }

/* ────────────── BOUTONS ────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    min-height: 40px;
    line-height: 1;
}

.btn-primary { background: var(--primary); color: var(--text-strong); }
.btn-primary:hover { background: var(--primary-light); box-shadow: 0 0 20px var(--primary-glow); color: var(--text-strong); }
.btn-secondary { background: var(--bg-card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-strong); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--error); color: var(--text-strong); }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-small { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ────────────── INPUTS ────────────── */
.input, input.input, select.input, textarea.input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: var(--transition);
    min-height: 44px;
}
.input:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px var(--primary-glow); }
.textarea { min-height: 80px; resize: vertical; }
.field-error { color: var(--error); font-size: 13px; margin-top: 4px; display: block; }
.form-hint { color: var(--text-muted); font-size: 13px; margin-top: 4px; display: block; }

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

/* ────────────── LOGIN ────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
    width: 100%; max-width: 420px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 40px;
}
.login-brand { text-align: center; margin-bottom: 32px; }
.brand-title { font-size: 28px; font-weight: 700; line-height: 1.1; color: var(--text-strong); }
.brand-title-2 { color: var(--accent-red); }
.brand-subtitle { color: var(--text-muted); font-size: 13px; letter-spacing: 0.3em; margin-top: 8px; }
.login-form .form-field { margin-bottom: 16px; }
.form-field-inline { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; font-size: 14px; color: var(--text-muted); }

/* ────────────── FLASH MESSAGES ────────────── */
.flash-messages { margin-bottom: 20px; }
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: var(--bg-card);
    border-left: 3px solid var(--info);
    display: flex; justify-content: space-between; align-items: center;
    transition: opacity 0.3s;
}
.flash-success { border-color: var(--success); }
.flash-error { border-color: var(--error); }
.flash-warning { border-color: var(--warning); }
.flash button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; }

/* ────────────── DASHBOARD ────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
}
.stat-label { color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--text-strong); }
.stat-success { border-left: 3px solid var(--success); }
.stat-warning { border-left: 3px solid var(--warning); }

.dashboard-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.dashboard-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; }
.section-title { font-size: 16px; font-weight: 600; color: var(--text-strong); margin-bottom: 16px; }

.services-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.service-card { padding: 16px; background: var(--bg-input); border-radius: var(--radius); text-align: center; }
.service-name { font-size: 13px; color: var(--text-muted); margin: 8px 0 4px; }
.service-count { font-size: 24px; font-weight: 700; color: var(--text-strong); }

.renew-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.renew-card { padding: 16px; background: var(--bg-input); border-radius: var(--radius); text-align: center; }
.renew-urgent { border: 1px solid var(--warning); }
.renew-period { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.renew-count { font-size: 28px; font-weight: 700; color: var(--text-strong); }

.email-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.email-stat { text-align: center; padding: 16px; background: var(--bg-input); border-radius: var(--radius); }
.email-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.email-value { font-size: 22px; font-weight: 700; color: var(--text-strong); }

.recent-list { list-style: none; }
.recent-item a { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-radius: var(--radius); transition: var(--transition); }
.recent-item a:hover { background: var(--bg-hover); }
.recent-nom { color: var(--text); font-weight: 500; }
.recent-empty, .interaction-empty { color: var(--text-muted); text-align: center; padding: 20px; }

.interaction-list { list-style: none; }
.interaction-item { display: grid; grid-template-columns: 100px 1fr 100px; gap: 12px; padding: 10px; border-bottom: 1px solid var(--border); font-size: 14px; align-items: center; }
.interaction-type { font-size: 11px; padding: 3px 8px; border-radius: 12px; background: var(--bg-input); color: var(--text-muted); text-transform: uppercase; text-align: center; }
.interaction-type-email { background: rgba(59, 130, 246, 0.15); color: #93C5FD; }
.interaction-type-formulaire { background: rgba(168, 85, 247, 0.15); color: #D8B4FE; }
.interaction-type-statut_change { background: rgba(245, 158, 11, 0.15); color: #FCD34D; }
.interaction-desc { color: var(--text); }
.interaction-date { color: var(--text-muted); font-size: 12px; text-align: right; }

/* ────────────── ENTREPRISES LISTE ────────────── */
.filters-bar { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.search-box { flex: 1; min-width: 240px; }
.filter-select { width: auto; min-width: 160px; }

.entreprises-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

.entreprise-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    display: block; transition: var(--transition);
    color: var(--text);
}
.entreprise-card:hover { transform: translateY(-2px); border-color: var(--primary-light); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); color: var(--text); }
.card-active { border-left: 3px solid var(--service-actif); }
.card-resilie { opacity: 0.6; border-left: 3px solid var(--service-resilie); }

.card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px; }
.card-nom { font-size: 16px; font-weight: 600; color: var(--text-strong); flex: 1; }
.card-info { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }

.card-services { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.pastille-service {
    font-size: 11px; padding: 3px 10px; border-radius: 12px;
    color: white; font-weight: 600;
}

.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.card-date { font-size: 12px; color: var(--text-muted); }

.statut-badge { font-size: 11px; padding: 4px 10px; border-radius: 12px; font-weight: 600; }
.statut-valide-client { background: rgba(16, 185, 129, 0.15); color: #6EE7B7; }
.statut-perdu-refuse { background: rgba(220, 38, 38, 0.15); color: #FCA5A5; }
.statut-a-relancer { background: rgba(245, 158, 11, 0.15); color: #FCD34D; }
.statut-en-attente { background: rgba(156, 163, 175, 0.15); color: #D1D5DB; }
.statut-resilie { background: rgba(220, 38, 38, 0.15); color: #FCA5A5; }

.pastille { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.pastille-rouge { background: var(--service-resilie); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 32px; }
.pagination-info { color: var(--text-muted); font-size: 14px; }

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

/* ────────────── FICHE ENTREPRISE ────────────── */
.fiche-header { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 20px; }
.header-active { border-left: 3px solid var(--service-actif); }
.header-resilie { border-left: 3px solid var(--service-resilie); opacity: 0.8; }
.fiche-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.fiche-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.fiche-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; }

.info-list { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; font-size: 14px; }
.info-list dt { color: var(--text-muted); font-weight: 600; }
.info-list dd { color: var(--text); }

.notes-content { white-space: pre-wrap; color: var(--text); line-height: 1.7; }

.contacts-list { display: grid; gap: 12px; margin-bottom: 16px; }
.contact-card { display: flex; justify-content: space-between; align-items: start; padding: 16px; background: var(--bg-input); border-radius: var(--radius); border: 1px solid var(--border); }
.contact-principal { border-color: var(--primary-light); }
.contact-nom { font-weight: 600; color: var(--text-strong); margin-bottom: 4px; }
.badge-principal { display: inline-block; margin-left: 8px; font-size: 10px; padding: 2px 6px; border-radius: 8px; background: var(--primary); color: var(--text-strong); }
.contact-fonction, .contact-email, .contact-tel { font-size: 13px; color: var(--text-muted); }

.add-contact-toggle { margin-top: 12px; }
.add-contact-toggle summary { display: inline-block; cursor: pointer; list-style: none; }
.add-contact-toggle summary::-webkit-details-marker { display: none; }
.add-contact-form { margin-top: 16px; padding: 16px; background: var(--bg-input); border-radius: var(--radius); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-field-full { grid-column: 1 / -1; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.emails-list { list-style: none; }
.email-item { display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); align-items: start; }
.email-status { font-size: 11px; padding: 4px 8px; border-radius: 8px; text-transform: uppercase; font-weight: 600; min-width: 80px; text-align: center; }
.status-envoye { background: rgba(156, 163, 175, 0.2); color: #D1D5DB; }
.status-livre { background: rgba(59, 130, 246, 0.2); color: #93C5FD; }
.status-ouvert { background: rgba(16, 185, 129, 0.2); color: #6EE7B7; }
.status-clique { background: rgba(168, 85, 247, 0.2); color: #D8B4FE; }
.status-erreur, .status-bounced { background: rgba(220, 38, 38, 0.2); color: #FCA5A5; }
.email-sujet { font-weight: 600; color: var(--text); }
.email-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

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

.ajouter-note { margin-bottom: 16px; }
.ajouter-note textarea { margin-bottom: 8px; }

.danger-zone { border-color: var(--error); }
.danger-zone .section-title { color: var(--error); }

/* ────────────── FORMULAIRES ────────────── */
.form-page { max-width: 900px; }
.form-section { margin-bottom: 20px; }
.form-field { margin-bottom: 16px; }
.select-multiple { min-height: 100px; padding: 8px; }

.form-actions { display: flex; gap: 12px; padding: 24px 0; }

/* ────────────── ERREURS ────────────── */
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.error-card { text-align: center; max-width: 500px; }
.error-code { font-size: 96px; font-weight: 700; color: var(--accent-red); line-height: 1; }
.error-title { font-size: 28px; color: var(--text-strong); margin: 16px 0 12px; }
.error-message { color: var(--text-muted); margin-bottom: 24px; }

/* ────────────── RESPONSIVE ────────────── */
@media (max-width: 1024px) {
    .dashboard-row { grid-template-columns: 1fr; }
    .fiche-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .menu-toggle { display: block; }
    .main { margin-left: 0; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .services-grid { grid-template-columns: 1fr 1fr; }
    .renew-grid, .email-stats { grid-template-columns: 1fr 1fr 1fr; }
    .filters-bar { flex-direction: column; }
    .filter-select, .search-box { width: 100%; min-width: 0; }
    .entreprises-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .info-list { grid-template-columns: 1fr; gap: 6px; }
    .info-list dt { margin-top: 8px; }
    .interaction-item { grid-template-columns: 1fr; gap: 4px; }
    .interaction-date { text-align: left; }
    .page-title { font-size: 16px; }
}

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