/* ==========================================================================
   EMTOP — Visites (liste, formulaire, fiche et historique)
   D'après la maquette « Suivi des prospects et visites » : historique des visites en frise.
   Réutilise les composants de l'administration (adm-*) et du planning (pl-badge, pl-radio, pl-who).
   Classes préfixées « vi- » : aucun impact sur les autres modules.
   ========================================================================== */

.vi-page { --vi-color: #f26b21; }
.vi-icon { background: color-mix(in srgb, var(--vi-color) 12%, transparent); color: var(--vi-color); }

/* --- Liste ---------------------------------------------------------------------------- */
.vi-toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.vi-filter--large { grid-column: span 2; }
.vi-filter .form-label { margin-bottom: .35rem; font-size: .8125rem; }
.vi-filter-actions { justify-content: flex-end; }
.vi-toolbar:not(.has-commercial) .vi-filter-actions { grid-column: span 2; }

.vi-table .cell-main { min-width: 150px; }
.vi-table td[data-label="Client / Prospect"] { min-width: 160px; }
.vi-table td[data-label="Objet de la visite"] { min-width: 200px; max-width: 320px; }
.vi-table td[data-label="Résultat"] { min-width: 160px; max-width: 260px; }
.vi-table td[data-label="Prochaine visite"] { min-width: 140px; max-width: 220px; }
.vi-table .pl-who { white-space: normal; }

.vi-clamp {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow-wrap: break-word;
}

.vi-calendar {
    display: inline-flex;
    flex-direction: column;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 48px;
    border: 1px solid color-mix(in srgb, var(--vi-color) 25%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--vi-color) 8%, transparent);
    line-height: 1.1;
    color: var(--vi-color);
}

.vi-calendar-day { font-size: 1.0625rem; font-weight: 700; }
.vi-calendar-month { font-size: .6875rem; font-weight: 600; text-transform: uppercase; }

.vi-tag {
    display: inline-flex;
    margin-top: 3px;
    padding: 1px 8px;
    border-radius: var(--em-radius-pill);
    font-size: .6875rem;
    font-weight: 600;
    white-space: nowrap;
}

.vi-tag--client { background: rgba(var(--em-success-rgb), .12); color: #0b8a4c; }
.vi-tag--prospect { background: rgba(var(--em-primary-rgb), .12); color: var(--em-primary); }
html[data-theme="dark"] .vi-tag--client { color: #4ade80; }

/* --- Formulaire ------------------------------------------------------------------------ */

/* Choix exclusif client / prospect : seule la liste du type choisi est affichée (le serveur ignore l'autre) */
.vi-cible-choix { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.vi-page label.vi-cible-option { position: relative; display: block; margin: 0; cursor: pointer; }
.vi-cible-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.vi-cible-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 14px;
    border: 1.5px solid var(--em-border-strong);
    border-radius: var(--em-radius-lg, 12px);
    background: var(--em-card-bg);
    font-weight: 600;
    color: var(--em-heading-color);
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}

.vi-cible-option span .em-icon { width: 18px; height: 18px; }
.vi-cible-option:hover span { border-color: var(--vi-color); }
.vi-cible-option input:checked + span { border-color: var(--vi-color); background: color-mix(in srgb, var(--vi-color) 8%, var(--em-card-bg)); color: var(--vi-color); }
.vi-cible-option input:focus-visible + span { outline: 2px solid var(--vi-color); outline-offset: 2px; }

.vi-cible:has(input[value="client"]:checked) .vi-cible-prospect,
.vi-cible:has(input[value="prospect"]:checked) .vi-cible-client,
.vi-cible:not(:has(input[name="visite[cible]"]:checked)) .vi-cible-client,
.vi-cible:not(:has(input[name="visite[cible]"]:checked)) .vi-cible-prospect { display: none; }
.vi-cible .form-text { display: flex; align-items: center; gap: 5px; }
.vi-cible .form-text .em-icon { width: 14px; height: 14px; }

.vi-hint { display: flex; align-items: center; gap: 5px; margin-top: 10px; }
.vi-hint .em-icon { width: 14px; height: 14px; }

/* --- Fiche : informations de la visite ---------------------------------------------------- */
.vi-infos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 20px 24px; list-style: none; }
.vi-infos > li { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 12px 14px; border-radius: 12px; background: var(--em-band); }
.vi-info--wide { grid-column: 1 / -1; }
.vi-info-label { font-size: .8125rem; color: var(--em-muted); }
.vi-info-value { font-weight: 500; color: var(--em-heading-color); overflow-wrap: anywhere; }
.vi-texte { font-weight: 400; white-space: pre-line; }

/* --- Fiche client / prospect et historique (frise) ---------------------------------------- */
.vi-fiche-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--em-border); }
.vi-fiche-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.vi-fiche-title h2 { margin: 0; font-size: 1.0625rem; font-weight: 700; color: var(--em-heading-color); overflow-wrap: anywhere; }
.vi-fiche-sub { margin: 6px 0 0; font-size: .8125rem; color: var(--em-muted); overflow-wrap: anywhere; }

.vi-historique { padding: 18px 24px 22px; }
.vi-historique-title { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: .9375rem; font-weight: 600; color: var(--em-heading-color); }

.vi-timeline { position: relative; margin: 0 0 18px; padding: 0; list-style: none; }

.vi-timeline-item { position: relative; display: flex; gap: 12px; padding-bottom: 14px; }
.vi-timeline-item:last-child { padding-bottom: 0; }

.vi-timeline-item:not(:last-child)::before {
    position: absolute;
    top: 20px;
    bottom: 0;
    left: 5px;
    width: 2px;
    background: color-mix(in srgb, var(--vi-color) 25%, transparent);
    content: "";
}

.vi-timeline-dot {
    position: relative;
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    margin-top: 7px;
    border: 2px solid var(--vi-color);
    border-radius: 50%;
    background: var(--em-card-bg);
}

.vi-timeline-item.is-current .vi-timeline-dot { background: var(--vi-color); }

.vi-timeline-body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; padding: 2px 10px 6px; border-radius: 10px; color: inherit; }
.vi-timeline-body:hover { background: var(--em-hover-bg); color: inherit; }
.vi-timeline-item.is-current .vi-timeline-body { background: color-mix(in srgb, var(--vi-color) 7%, var(--em-card-bg)); }
.vi-timeline-title { font-weight: 600; color: var(--em-heading-color); }
.vi-timeline-date { font-size: .75rem; color: var(--em-muted); }
.vi-timeline-text { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: .8125rem; color: var(--em-body-color); }

.vi-historique-note { margin: 10px 0 0; font-size: .75rem; color: var(--em-muted); }

/* --- Fiche client : historique commercial (client/_historique_commercial.html.twig) ---------- */
.hc { --vi-color: #f26b21; }
.hc-icon { background: rgba(var(--em-primary-rgb), .1); color: var(--em-primary); }
.hc-corps { display: flex; flex-direction: column; gap: 18px; padding: 20px 24px 24px; }

.hc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.hc-stat { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 12px 16px; border-radius: 12px; background: var(--em-band); }
.hc-stat-label { font-size: .8125rem; color: var(--em-muted); }
.hc-stat-value { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 1.125rem; font-weight: 700; color: var(--em-heading-color); }

.hc-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.hc-grid--egal { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.hc-bloc { --hc-color: var(--em-primary); min-width: 0; padding: 16px 18px 18px; border: 1px solid var(--em-border); border-radius: 12px; }
.hc-bloc--visites { --hc-color: var(--vi-color); }
.hc-bloc--actions { --hc-color: #7e57c2; }
.hc-bloc--besoins { --hc-color: #0b8a4c; }
.hc-bloc--reclamations { --hc-color: var(--em-danger); }

.hc-bloc-titre { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: .9375rem; font-weight: 600; color: var(--em-heading-color); }
.hc-bloc-titre .em-icon { flex-shrink: 0; width: 30px; height: 30px; padding: 6px; border-radius: 50%; background: color-mix(in srgb, var(--hc-color) 12%, transparent); color: var(--hc-color); }
.hc-bloc-titre .adm-count { margin-left: auto; }

.hc-sous-titre { margin: 16px 0 8px; font-size: .8125rem; font-weight: 600; color: var(--em-muted); text-transform: uppercase; letter-spacing: .03em; }

/* Frise des visites (composant vi-timeline) */
.hc-timeline { margin-bottom: 0; }
.hc-timeline-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }

/* Entrées datées : comptes rendus, besoins, réclamations, actions précédentes */
.hc-liste { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.hc-entree { padding: 10px 14px; border-left: 3px solid color-mix(in srgb, var(--hc-color) 45%, transparent); border-radius: 0 10px 10px 0; background: var(--em-band); }
.hc-liste--compacte .hc-entree { padding: 8px 12px; }
.hc-entree-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 4px; font-size: .75rem; color: var(--em-muted); }
.hc-date { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--em-heading-color); }
.hc-date .em-icon { width: 14px; height: 14px; color: var(--hc-color); }
.hc-date:hover { color: var(--em-primary); }
.hc-entree-tete .vi-tag { margin-top: 0; }

.hc-texte { margin: 0; font-size: .875rem; color: var(--em-heading-color); white-space: pre-line; overflow-wrap: anywhere; }
.hc-resultat { margin: 6px 0 0; font-size: .8125rem; color: var(--em-body-color); white-space: pre-line; overflow-wrap: anywhere; }
.hc-resultat span { font-weight: 600; color: var(--em-heading-color); }
.hc-vide { margin: 0; font-size: .875rem; color: var(--em-muted); }

.hc-plus { display: inline-flex; align-items: center; gap: 5px; margin-top: 12px; font-size: .8125rem; font-weight: 600; color: var(--em-primary); }
.hc-plus .em-icon { width: 15px; height: 15px; }

/* Action en cours (dernière visite) et échéance de la prochaine visite */
.hc-action-courante { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--hc-color) 7%, var(--em-card-bg)); }
.hc-action-label { font-size: .75rem; font-weight: 600; color: var(--hc-color); text-transform: uppercase; letter-spacing: .03em; }
.hc-action-courante .hc-texte { font-size: .9375rem; font-weight: 500; }
.hc-action-date { display: block; font-size: .8125rem; color: var(--em-body-color); }
.hc-action-date .em-icon { display: inline-block; width: 15px; height: 15px; margin-right: 5px; vertical-align: -3px; color: var(--hc-color); }
.hc-action-date .hc-echeance { margin-left: 6px; }
.hc-action-courante.is-retard { box-shadow: inset 3px 0 0 var(--em-danger); }

.hc-echeance { display: inline-flex; padding: 1px 8px; border-radius: var(--em-radius-pill); font-size: .6875rem; font-weight: 600; white-space: nowrap; }
.hc-echeance.is-retard { background: rgba(var(--em-danger-rgb), .12); color: #d63c3c; }
.hc-echeance.is-jour { background: rgba(var(--em-warning-rgb), .22); color: #9a6a00; }
html[data-theme="dark"] .hc-echeance.is-retard { color: #ff8a8a; }
html[data-theme="dark"] .hc-echeance.is-jour { color: #f9c851; }
html[data-theme="dark"] .hc-bloc--besoins { --hc-color: #4ade80; }

/* --- Responsive ------------------------------------------------------------------------ */
@media (min-width: 768px) and (max-width: 1499.98px) {
    .vi-table .vi-col-resultat { display: none; }
}

@media (max-width: 1199.98px) {
    .vi-toolbar.has-commercial .vi-filter-actions { grid-column: 1 / -1; }
    .hc-grid,
    .hc-grid--egal { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 767.98px) {
    .vi-toolbar,
    .vi-toolbar.has-commercial { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .vi-filter--large,
    .vi-filter-actions,
    .vi-toolbar:not(.has-commercial) .vi-filter-actions,
    .vi-toolbar.has-commercial .vi-filter:nth-last-child(2) { grid-column: 1 / -1; }
    .vi-filter-actions .btn { flex: 1 1 0; }
    .vi-table td[data-label] { max-width: none; }
    .vi-infos { grid-template-columns: minmax(0, 1fr); padding: 16px; }
    .vi-cible-choix { grid-template-columns: minmax(0, 1fr); }
    .vi-fiche-head,
    .vi-historique { padding-right: 18px; padding-left: 18px; }
    .hc-corps { padding: 16px; }
    .hc-stats { grid-template-columns: minmax(0, 1fr); }
    .hc-bloc { padding: 14px; }
}
