/* ============================================================
   PIPELET CRM – Feuille de style principale
   Palette : Navy #1B2B5E | Yellow #F5C400 | Light BG #F7F5EF
   ============================================================ */

:root {
  --navy:     #1B2B5E;
  --yellow:   #F5C400;
  --bg:       #F7F5EF;
  --card-bg:  #FFFFFF;
  --sidebar-w: 140px;
  --radius:   12px;
  --shadow:   0 2px 12px rgba(0,0,0,.08);
  --font:     'Inter', sans-serif;
  --danger:   #E03E3E;
  --success:  #2D9E6B;
  --muted:    #6B7280;
}

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

body { font-family: var(--font); background: var(--bg); color: var(--navy); font-size: 15px; }

/* ── Impersonate Bar ── */
.impersonate-bar {
  background: var(--yellow); color: var(--navy);
  text-align: center; padding: 8px 16px; font-size: 14px; font-weight: 600;
}
.btn-stop { background: var(--navy); color: #fff; border-radius: 6px; padding: 2px 10px; text-decoration: none; margin-left: 12px; }

/* ── Layout ── */
.app-wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); background: var(--card-bg);
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 0; gap: 4px;
  box-shadow: 2px 0 8px rgba(0,0,0,.06); position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-logo { margin-bottom: 24px; }
.logo-img { max-width: 100px; height: auto; }

.nav-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 8px; border-radius: var(--radius); width: 110px;
  text-decoration: none; color: var(--navy); font-size: 13px; font-weight: 500;
  transition: background .15s;
}
.nav-item:hover, .nav-item.active { background: var(--bg); }
.nav-icon { font-size: 22px; margin-bottom: 4px; }
.nav-cta .nav-plus {
  background: var(--yellow); color: var(--navy);
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; margin-bottom: 4px;
}

/* ── Main content ── */
.main-content { flex: 1; padding: 24px; }

/* ── Cards ── */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.sub-card { background: var(--bg); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; color: var(--navy); display: flex; align-items: center; gap: 10px; }

/* ── Auth ── */
.auth-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--bg); }
.auth-card  { background: var(--card-bg); border-radius: var(--radius); padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-logo  { text-align: center; margin-bottom: 28px; }
.auth-logo img { max-height: 50px; }
.auth-logo h1   { font-size: 28px; font-weight: 700; color: var(--navy); margin-top: 8px; }
.auth-subtitle  { font-size: 18px; margin-bottom: 20px; text-align: center; }
.auth-form      { display: flex; flex-direction: column; gap: 16px; }
.auth-link      { display: block; text-align: center; margin-top: 16px; color: var(--navy); font-size: 14px; text-decoration: underline; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--navy); }
.input-field, .textarea-field, select.input-field {
  width: 100%; padding: 10px 14px; border: 1.5px solid #E5E7EB;
  border-radius: 8px; font-size: 15px; font-family: var(--font);
  background: #fff; color: var(--navy); margin-bottom: 12px;
  transition: border-color .15s;
}
.input-field:focus, .textarea-field:focus { outline: none; border-color: var(--navy); }
.textarea-field { resize: vertical; min-height: 100px; }
.row-inputs { display: flex; gap: 12px; }
.row-inputs .input-field { margin-bottom: 12px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: 8px; font-weight: 600;
  font-size: 15px; cursor: pointer; border: none; text-decoration: none;
  transition: opacity .15s, transform .1s; font-family: var(--font);
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn-primary  { background: var(--navy);    color: #fff; }
.btn-yellow   { background: var(--yellow);  color: var(--navy); }
.btn-outline  { background: transparent; border: 2px solid var(--navy); color: var(--navy); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 6px 12px; font-size: 13px; }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-yellow  { background: var(--yellow); color: var(--navy); }
.badge-admin   { background: var(--navy);   color: #fff; }
.badge-user    { background: #E5E7EB;       color: var(--navy); }
.badge-prospect_chaud  { background: #FECDD3; color: #9F1239; }
.badge-prospect_tiede  { background: #FEF3C7; color: #92400E; }
.badge-prospect_froid  { background: #DBEAFE; color: #1E40AF; }
.badge-client          { background: #D1FAE5; color: #065F46; }
.badge-client_abonnement { background: #D1FAE5; color: #065F46; }
.badge-client_ponctuel   { background: #D1FAE5; color: #065F46; }
.badge-client_resilie    { background: #E5E7EB; color: #4B5563; }
.badge-client_impaye     { background: #FEE2E2; color: #991B1B; }
.badge-ancien_client   { background: #E5E7EB; color: #4B5563; }
.badge-perdu           { background: #FEE2E2; color: #991B1B; }
.badge-canal           { background: #EDE9FE; color: #4C1D95; }
/* Statuts "contact" — teinte violet/indigo neutre */
.badge-nouveau_contact      { background: #F69960; color: #9c3c02; }
.badge-contact_sans_reponse { background: #E0E7FF; color: #3730A3; }
.badge-contact_en_echange   { background: #E0E7FF; color: #3730A3; }
.badge-contact_rdv_planifie { background: #E0E7FF; color: #3730A3; }
.badge-contact_rdv_annule   { background: #E0E7FF; color: #3730A3; }
.badge-contact_rdv_non_venu { background: #E0E7FF; color: #3730A3; }
/* Statuts "visiteur" — teinte orange/ambre */
.badge-visiteur_present  { background: #FFEDD5; color: #9A3412; }
.badge-visiteur_reflexion{ background: #FFEDD5; color: #9A3412; }
.badge-visiteur_refus    { background: #FFEDD5; color: #9A3412; }
.badge-vni               { background: #FFEDD5; color: #9A3412; }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.alert-success { background: #D1FAE5; color: #065F46; }
.alert-error   { background: #FEE2E2; color: #991B1B; }

/* ── Relances ── */
.relance-card {
  display: flex; justify-content: space-between; align-items: flex-start;
  background: #E8ECF7; border-radius: var(--radius); padding: 16px 20px;
  margin-bottom: 12px; gap: 16px;
}
.relance-info { display: flex; flex-direction: column; gap: 4px; }
.relance-info strong { font-size: 16px; }
.relance-info span   { font-size: 13px; color: #374151; }
.retard  { color: var(--danger); font-weight: 700; font-size: 13px; }
.relance-note { text-align: right; }
.note-label   { font-weight: 600; font-size: 13px; }
.relance-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ── Stats ── */
.stats-grid { display: flex; gap: 16px; flex-wrap: wrap; }
.stat-box {
  flex: 1; min-width: 140px; background: #E8ECF7; border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.stat-label { font-size: 14px; font-weight: 600; color: var(--navy); }
.stat-value { font-size: 36px; font-weight: 800; color: var(--navy); }

/* ── Tables ── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: fixed; }
.data-table th { background: var(--bg); padding: 10px 12px; text-align: left; font-weight: 700; border-bottom: 2px solid #E5E7EB; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid #F3F4F6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table tr:hover td { background: #F9FAFB; }
.row-alert td { background: #FFF7ED; }

/* ── Contacts table – largeurs fixes par colonne ── */
.data-table th:nth-child(1),
.data-table td:nth-child(1) { width: 16%; white-space: normal; word-break: break-word; } /* Nom */
.data-table th:nth-child(2),
.data-table td:nth-child(2) { width: 22%; }                                               /* Email */
.data-table th:nth-child(3),
.data-table td:nth-child(3) { width: 13%; }                                               /* Téléphone */
.data-table th:nth-child(4),
.data-table td:nth-child(4) { width: 14%; white-space: normal; }                          /* Statut */
.data-table th:nth-child(5),
.data-table td:nth-child(5) { width: 12%; }                                               /* Canal */
.data-table th:nth-child(6),
.data-table td:nth-child(6) { width: 11%; }                                               /* Date entrée */
.data-table th:nth-child(7),
.data-table td:nth-child(7) { width: 13%; text-align: center; white-space: nowrap; }       /* Boutons actions */

/* ── History ── */
.history-item { background: #F3F4F6; border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.history-header { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.history-vente { border-left: 4px solid var(--yellow); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.modal-box {
  background: #EEF2FF; border-radius: var(--radius); padding: 28px;
  width: 90%; max-width: 480px; position: relative; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 20px; cursor: pointer; color: var(--navy);
}
.modal-box h3 { font-size: 18px; margin-bottom: 16px; }

/* ── Misc ── */
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.text-muted   { color: var(--muted); font-size: 14px; }
.text-danger  { color: var(--danger); font-weight: 600; }
.text-center  { text-align: center; }
.dashboard    { display: flex; flex-direction: column; gap: 20px; }
.contact-header { }
.contact-title-row { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.contact-title-row h2 { font-size: 22px; font-weight: 800; }
.contact-title-side { display: flex; align-items: flex-start; gap: 20px; }
.call-qr { text-align: center; flex-shrink: 0; }
.call-qr-code { width: 128px; height: 128px; background: #fff; border-radius: 8px; padding: 4px; border: 1px solid #E5E7EB; }
.call-qr-code svg { width: 100%; height: 100%; display: block; }
.call-qr-label { font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.call-qr-mobile { display: none; }
.ca-row { font-size: 18px; font-weight: 700; margin: 16px 0; }
.contact-edit-form .row-inputs { flex-wrap: wrap; }
.input-label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }
.filter-form { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.filter-form .input-field { margin-bottom: 0; flex: 1; min-width: 160px; }
.filter-date-range { display: flex; gap: 10px; flex: 1; min-width: 260px; }
.filter-date-range .input-field { margin-bottom: 0; flex: 1; min-width: 0; }
.filter-tabs { display: flex; gap: 10px; margin-bottom: 16px; }
.tab { padding: 7px 16px; border-radius: 20px; text-decoration: none; color: var(--navy); background: var(--bg); font-weight: 600; font-size: 13px; }
.tab.active { background: var(--navy); color: #fff; }
.logout-link { display: block; text-align: center; margin-top: 24px; color: var(--navy); font-weight: 700; text-decoration: underline; cursor: pointer; }
.divider { border: none; border-top: 1px solid #E5E7EB; margin: 16px 0; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 70px; }
  .nav-label { display: none; }
  .nav-item  { width: 56px; padding: 10px 6px; }
  .main-content { padding: 14px; }
  .row-inputs { flex-direction: column; gap: 0; }
  .stats-grid { flex-direction: column; }
  .relance-card { flex-direction: column; }
  .relance-note { text-align: left; }
  .contact-title-row { flex-direction: column; }
  .call-qr { display: none; }   /* déjà sur le téléphone : le QR ne sert à rien */
  .call-qr-mobile { display: inline-flex; }
  .filter-form { flex-direction: column; }
  .filter-date-range { flex-direction: row; min-width: 100%; }
  .list-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .filter-tabs { flex-wrap: wrap; }

  /* Tableau contacts responsive */
  .data-table { table-layout: auto; font-size: 13px; }
  .data-table th, .data-table td { padding: 8px 6px; }
  /* Masquer Canal sur tablette pour gagner de la place */
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) { display: none; }
  /* Bouton Voir toujours visible */
  .data-table th:nth-child(7),
  .data-table td:nth-child(7) { width: auto; white-space: nowrap; }
}

@media (max-width: 480px) {
  .sidebar { width: 56px; }
  .auth-card { padding: 24px 16px; }
  .stat-value { font-size: 28px; }

  /* Tableau contacts mobile : Nom + Statut + boutons uniquement */
  .data-table { font-size: 12px; table-layout: auto; }
  .data-table th:nth-child(2),
  .data-table td:nth-child(2) { display: none; } /* Email */
  .data-table th:nth-child(3),
  .data-table td:nth-child(3) { display: none; } /* Téléphone */
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) { display: none; } /* Canal (déjà caché à 768, renforce) */
  .data-table th:nth-child(6),
  .data-table td:nth-child(6) { display: none; } /* Date entrée */
  /* Nom : prend l'espace disponible, coupe proprement */
  .data-table th:nth-child(1),
  .data-table td:nth-child(1) { width: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; word-break: normal; }
  /* Statut : taille auto */
  .data-table th:nth-child(4),
  .data-table td:nth-child(4) { width: auto; }
  /* Boutons : compact */
  .data-table th:nth-child(7),
  .data-table td:nth-child(7) { width: auto; padding-left: 4px; padding-right: 4px; }
  /* Boutons plus petits sur mobile */
  .data-table td:nth-child(7) .btn-sm { padding: 5px 8px; font-size: 12px; }
  .data-table td:nth-child(7) .btn-danger { padding: 5px 7px; margin-left: 2px !important; }
}

/* ── Menu toggle (mobile) ─────────────────────── */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    padding: 0;
}
.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #374151;
    border-radius: 2px;
    transition: transform .25s, opacity .25s;
}
/* Croix quand ouvert */
.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}

@media (max-width: 768px) {
    .menu-toggle        { display: flex; }
    .sidebar-overlay.open { display: block; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform .28s ease;
    }
    .sidebar.open       { transform: translateX(0); }

    .main-content       { margin-left: 0; padding-top: 60px; }
}

/* ══════════════════════════════════════════════
   MOBILE — bloc unique consolidé (override tout)
   ══════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Layout global ── */
    /* PAS de overflow-x:hidden sur app-wrapper car ça casse position:fixed */
    body { overflow-x: hidden; }

    .main-content {
        width: 100%;
        max-width: 100%;
        margin-left: 0 !important;
        padding: 64px 12px 16px !important;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* ── Inputs ne débordent pas ── */
    .input-field, .textarea-field, select.input-field,
    .contact-edit-form input, .contact-edit-form select,
    .relance-form input, .relance-form select {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    /* ── Cards ── */
    .card { padding: 16px 12px; }
    .row-inputs > * { width: 100% !important; }
    .modal-box { width: 95%; padding: 20px 16px; }
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* ── Hamburger ── */
    .menu-toggle { display: flex; }
    .sidebar-overlay.open { display: block; }

    /* ── Sidebar drawer ── */
    .sidebar {
        position: fixed !important;
        top: 0; left: 0;
        width: 220px !important;
        height: 100% !important;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform .28s ease;
        align-items: flex-start !important;
        padding: 24px 12px !important;
    }
    .sidebar.open { transform: translateX(0) !important; }

    /* Logo dans le drawer */
    .sidebar-logo {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px 0 20px;
        border-bottom: 1px solid #E5E7EB;
        margin-bottom: 12px;
    }
    .logo-img { max-width: 130px; max-height: 60px; object-fit: contain; }

    /* Items nav en ligne */
    .nav-item {
        flex-direction: row !important;
        width: 100% !important;
        justify-content: flex-start !important;
        gap: 12px;
        padding: 12px 14px !important;
    }
    .nav-label { display: block !important; font-size: 15px; }
    .nav-icon  { font-size: 20px; margin-bottom: 0 !important; }
    .nav-cta .nav-plus {
        width: 32px; height: 32px;
        font-size: 20px;
        margin-bottom: 0 !important;
    }
}

.contact-nav {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.contact-nav .btn-nav[disabled] {
    opacity: .35;
    cursor: not-allowed;
    pointer-events: none;
}
/* ── Enregistrements d'appels & évaluation IA ───────────────── */
.cai-upload { margin-bottom: .75rem; }
.cai-upload label { display: block; font-size: 13px; font-weight: 600; margin-bottom: .25rem; }
.cai-attach { margin-top: .6rem; }
.cai-box { margin-top: .75rem; background: #fff; border: 1px solid #E5E7EB; border-radius: 10px; padding: 12px 14px; }
.cai-head { display: flex; align-items: center; gap: .5rem; font-size: 14px; margin-bottom: .5rem; }
.cai-audio { width: 100%; height: 40px; }
.cai-score { display: flex; align-items: center; gap: .6rem; margin: .75rem 0 .5rem; flex-wrap: wrap; }
.cai-score-val { font-size: 28px; font-weight: 800; line-height: 1; }
.cai-score-val small { font-size: 14px; font-weight: 600; color: var(--muted); }
.cai-text { font-size: 14px; margin: .4rem 0; }
.cai-sub { font-size: 13px; }
.cai-cols { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; font-size: 14px; margin: .5rem 0; }
.cai-cols ul { margin: .25rem 0 0 1.1rem; padding: 0; }
@media (max-width: 640px) { .cai-cols { grid-template-columns: 1fr; } }
.cai-details { margin-top: .5rem; font-size: 14px; }
.cai-details > summary { cursor: pointer; font-weight: 600; color: var(--navy); padding: .25rem 0; }
.cai-crit { border-top: 1px solid #F3F4F6; padding: .35rem 0; }
.cai-crit > summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: .5rem; list-style: none; }
.cai-crit > summary::-webkit-details-marker { display: none; }
.cai-crit-meta { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.cai-crit p { margin: .3rem 0; font-size: 13px; }
.cai-transcript { font-size: 13px; max-height: 320px; overflow-y: auto; background: #F9FAFB; padding: .6rem; border-radius: 8px; }
.cai-pending { font-size: 13px; font-weight: 600; color: var(--navy); }
.cai-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: .75rem; }
.cai-weights { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .5rem 1rem; }
.cai-weight { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid #F3F4F6; font-size: 14px; }
.cai-weight select { width: auto; min-width: 64px; }

/* Encart partenaire coaching (Appels IA + fiche contact) */
.partner-coach { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; padding: 12px 14px; background: #FFFBEB; border: 1px solid #FDE68A; border-radius: 10px; }
.partner-coach-photo { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; object-position: top; flex-shrink: 0; }
.partner-coach-body { min-width: 0; }
.partner-coach-tag { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #92400E; margin-bottom: 2px; }
.partner-coach-name { display: block; font-size: 14px; color: var(--navy); }
.partner-coach-text { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.partner-coach .btn { word-break: break-all; }
