:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #dde1e6;
    --color-text: #1f2430;
    --color-muted: #667085;
    --color-primary: #0d3a48;
    --color-primary-dark: #082a35;
    --color-accent-gold: #e0a828;
    --color-danger: #b3261e;
    --color-warning: #a15c00;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-primary);
    color: #fff;
    padding: 0.75rem 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-bottom: 3px solid var(--color-accent-gold);
}

.topbar-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; flex-wrap: wrap; }
.topbar-logo { height: 22px; width: auto; display: block; }
.topbar-welcome { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; opacity: 0.85; font-size: 0.9em; padding-left: 0.6rem; border-left: 1px solid rgba(255, 255, 255, 0.3); color: #fff; text-decoration: none; }
.topbar-welcome:hover { opacity: 1; text-decoration: underline; }

/* Photo affichée devant le titre de chaque page (4x la taille de l'ancien avatar de la barre du
   haut, retiré) : flotte à gauche pour que le h1 vienne s'aligner à côté, "clear" appliqué aux
   premiers blocs de contenu usuels pour qu'ils démarrent toujours sous la photo, jamais à côté. */
.page-avatar { float: left; width: 88px; height: 88px; border-radius: 50%; object-fit: cover; margin: 0 1.25rem 0.75rem 0; border: 2px solid var(--color-surface); box-shadow: 0 0 0 1px var(--color-border); }
.container h1, .container-full h1 { margin-top: 0.3rem; }
/* Titre vertical-centré sur la hauteur de la photo (88px) quand il la suit directement, ou quand
   il est le premier titre d'un conteneur qui la suit (ex: le bloc flex titre+bouton du dashboard). */
.page-avatar + h1, .page-avatar + div > h1:first-child { line-height: 88px; margin-top: 0; margin-bottom: 0; }
.card, .kpi-row, .grid-2, .dashboard-layout, form.filters, .settings-grid, .map-layout, .filters-bar, .results { clear: left; }

.topbar-nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.topbar-nav a { color: #fff; text-decoration: none; opacity: 0.9; }
.topbar-nav a:hover { text-decoration: underline; }
.topbar-nav a.active { font-weight: 800; opacity: 1; }
.topbar-logout { display: flex; align-items: center; opacity: 0.85; }
.topbar-logout:hover { opacity: 1; text-decoration: none !important; }

.container {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

.container-full {
    max-width: 1600px;
    margin: 1.5rem auto;
    padding: 0 2.5rem;
}

.map-layout { display: flex; gap: 1.25rem; align-items: stretch; }
.map-sidebar { flex: 0 0 280px; }
.map-sidebar .field { margin-bottom: 0.7rem; }
.map-wrap { flex: 1; min-width: 0; }
#carte { position: relative; width: 100%; height: 72vh; min-height: 480px; border-radius: 8px; border: 1px solid var(--color-border); }
.map-legend { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.75rem; font-size: 0.85em; }
.map-legend span.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.3rem; vertical-align: middle; }
.search-results { border: 1px solid var(--color-border); border-radius: 6px; max-height: 220px; overflow-y: auto; margin-top: 0.3rem; background: var(--color-surface); }
.search-results div { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.88em; border-bottom: 1px solid var(--color-border); }
.search-results div:last-child { border-bottom: none; }
.search-results div:hover { background: #f0f4f2; }
@media (max-width: 900px) {
    .map-layout { flex-direction: column; }
    .map-sidebar { flex-basis: auto; width: 100%; }
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin-top: 0; }

.kpi-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.kpi-tile { flex: 1; min-width: 170px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 1rem 1.25rem; }
.kpi-tile .value { font-size: 1.7rem; font-weight: 800; line-height: 1.2; }
.kpi-tile .label { color: var(--color-muted); font-size: 0.82em; margin-top: 0.15rem; }

.pyramid { max-width: 500px; margin: 0 auto; }
.pyramid-row { display: flex; align-items: center; gap: 0.75rem; }
.pyramid-row-link { color: inherit; text-decoration: none; border-radius: 8px; padding: 0.15rem 0.3rem; margin: 0 -0.3rem; transition: background 0.15s; }
.pyramid-row-link:hover { background: #f2f4f6; }
.pyramid-row-link:hover .pyramid-tier { filter: brightness(1.08); }
.pyramid-label { width: 150px; flex-shrink: 0; color: var(--color-muted); line-height: 1.2; }
.pyramid-label-code { display: block; font-weight: 800; font-size: 1.5em; color: var(--color-text); letter-spacing: -0.01em; }
.pyramid-label-desc { display: block; font-weight: 600; font-size: 0.78em; }
.pyramid-tier-wrap { flex: 1; }
.pyramid-tier {
    width: 100%;
    height: 58px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 1.2em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    background-image: linear-gradient(rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.08));
    transition: clip-path 0.3s;
}
.pyramid-ca { font-size: 0.62em; font-weight: 600; opacity: 0.92; }
.pyramid-conversion-side { width: 84px; text-align: left; flex-shrink: 0; line-height: 1.3; }
.pyramid-conversion-side strong { display: block; font-size: 1em; }
.pyramid-conversion-side .muted { font-size: 0.72em; }
.pyramid-lost-info {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border, #e2e2e2);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85em;
}
.pyramid-lost-info .label { color: var(--color-muted); }
.pyramid-lost-info .value { font-weight: 700; color: #d03b3b; }

.status-tiles { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.status-tile { flex: 1; min-width: 130px; border-radius: 8px; padding: 0.85rem 1rem; color: #fff; display: block; text-decoration: none; }
.status-tile-link { transition: transform 0.15s, filter 0.15s; }
.status-tile-link:hover { filter: brightness(1.08); transform: translateY(-1px); }
.status-tile .value { font-size: 1.25rem; font-weight: 800; margin: 0.1rem 0; }
.status-tile .count { font-size: 0.8em; opacity: 0.92; }
.status-tile .label { font-size: 0.78em; opacity: 0.92; text-transform: uppercase; letter-spacing: 0.03em; }

.bar-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.bar-label { width: 44px; font-size: 0.85em; font-weight: 600; flex-shrink: 0; }
.bar-track { flex: 1; background: #eef1f4; border-radius: 4px; height: 18px; }
.bar-fill { height: 100%; border-radius: 4px; min-width: 3px; transition: width 0.3s; }
.bar-value { width: 200px; text-align: right; font-size: 0.8em; color: var(--color-muted); flex-shrink: 0; }
.bar-row-link { color: inherit; text-decoration: none; border-radius: 6px; padding: 0.15rem 0.3rem; margin-left: -0.3rem; transition: background 0.15s; }
.bar-row-link:hover { background: #f2f4f6; }
.bar-row-link:hover .bar-label { text-decoration: underline; }

.stacked-bar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; width: 160px; background: #eef1f4; }

.gauge-row { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.gauge { width: 200px; text-align: center; }
.gauge-svg { width: 100%; height: auto; }
.gauge-label { font-weight: 600; font-size: 0.85em; margin-top: -0.5rem; }
.gauge-value { font-size: 1.05em; font-weight: 700; }
.gauge-restant { font-size: 0.8em; color: var(--color-muted); }

.progress-item { width: 100%; }
.progress-header { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.3rem; }
.progress-label { font-weight: 600; font-size: 0.85em; }
.progress-pct { font-weight: 800; font-size: 0.85em; white-space: nowrap; }
.progress-track { background: #eef1f4; border-radius: 6px; height: 12px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; min-width: 3px; transition: width 0.3s; }
.progress-values { font-size: 0.95em; font-weight: 700; margin-top: 0.35rem; }
.progress-restant { font-size: 0.8em; color: var(--color-muted); }

.month-chart { display: flex; align-items: flex-end; gap: 0.5rem; height: 180px; }
.month-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.month-count { font-size: 0.78em; font-weight: 700; color: var(--color-muted); min-height: 1.1em; }
.month-bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.month-bar { width: 100%; background: var(--color-primary); border-radius: 3px 3px 0 0; min-height: 2px; transition: height 0.3s; }
.month-label { font-size: 0.72em; color: var(--color-muted); margin-top: 0.3rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--color-border); font-size: 0.92em; }
th { color: var(--color-muted); font-weight: 600; }
tr:hover td { background: #fafbfc; }

a.sort-header { color: inherit; text-decoration: none; white-space: nowrap; }
a.sort-header:hover { color: var(--color-primary); text-decoration: underline; }
.sort-arrow { font-size: 0.75em; color: var(--color-primary); }

a.button, button, input[type=submit] {
    display: inline-block;
    background: var(--color-primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.95em;
}
a.button:hover, button:hover { background: var(--color-primary-dark); }
button.secondary, a.button.secondary { background: #fff; color: var(--color-primary); border: 1px solid var(--color-primary); }

.resource-table td, .resource-table th { vertical-align: middle; }
.resource-table td:first-child { font-weight: 600; }
.badge-version { background: #eef1f4; color: var(--color-muted); font-weight: 600; white-space: nowrap; }
.resource-action { text-align: right; white-space: nowrap; }
.resource-name { display: flex; align-items: center; gap: 0.75rem; }
.resource-thumb { width: 44px; height: 62px; object-fit: cover; border-radius: 4px; border: 1px solid var(--color-border); flex-shrink: 0; background: #fff; }

@media (max-width: 640px) {
    .resource-table thead { display: none; }
    .resource-table, .resource-table tbody, .resource-table tr, .resource-table td { display: block; width: 100%; }
    .resource-table tr { border-bottom: 1px solid var(--color-border); padding: 0.75rem 0; }
    .resource-table tr:last-child { border-bottom: none; }
    .resource-table td { border: none; padding: 0.15rem 0; }
    .resource-table td[data-label]::before { content: attr(data-label); display: block; color: var(--color-muted); font-size: 0.75em; }
    .resource-table td[data-label=""]::before { display: none; }
    .resource-table td.resource-name { display: flex; align-items: center; }
    .resource-table td.resource-name::before { display: none; }
    .resource-action { text-align: left; margin-top: 0.4rem; }
    .resource-action .button { display: block; text-align: center; }
}

form.filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 1rem; }
form.filters select, form.filters input { width: auto; flex: 1 1 150px; min-width: 130px; }
form.filters button, form.filters a.button { flex-shrink: 0; white-space: nowrap; }

input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95em;
    width: 100%;
}

.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.85em; color: var(--color-muted); margin-bottom: 0.25rem; }

/* Barre de filtres horizontale en haut de page (remplace la colonne latérale) : les champs
   s'enroulent proprement sur plusieurs lignes si la largeur manque, toujours alignés à gauche,
   jamais étirés sur toute la largeur de la carte. */
.filters-bar-form { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-end; justify-content: flex-start; }
.filters-bar-form .field { margin-bottom: 0; flex: 1 1 170px; min-width: 150px; max-width: 220px; }
.filters-bar-form .field select, .filters-bar-form .field input { width: 100%; }
.filters-bar-actions { flex: 0 0 auto; max-width: none; min-width: 0; }
.filters-bar-actions label { visibility: hidden; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px; font-size: 0.78em; font-weight: 600; }
.badge-warning { background: #fdf0dc; color: var(--color-warning); }
.badge-tier-grand { background: #fbf0da; color: #8a6512; }
.badge-tier-standard { background: #eef1f4; color: var(--color-muted); }
.badge-stage { background: #e5f3ec; color: var(--color-primary-dark); }
.badge-prospect { background: #e8eef4; color: #3d5a75; }
.badge-ancien { background: #fdf0dc; color: #8a6512; }

.flash { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-success { background: #e5f3ec; color: var(--color-primary-dark); }
.flash-error { background: #fbe9e7; color: var(--color-danger); }

/* Chevrons de progression C0-C4 : une teinte par étape, du bleu Re-uz (C0) au vert affaire
   signée (C4). Étapes futures atténuées ; étape courante mise en avant par un contour. */
.chevron-steps { display: flex; width: 100%; margin-bottom: 1rem; }
.chevron-step {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    color: #fff;
    font-weight: 600;
    font-size: 0.9em;
    letter-spacing: 0.02em;
    margin-left: -18px;
    clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 50%, calc(100% - 18px) 100%, 0 100%, 18px 50%);
}
.chevron-step:first-child { margin-left: 0; clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 50%, calc(100% - 18px) 100%, 0 100%); }
.chevron-step.future { opacity: 0.62; }
.chevron-step.current {
    opacity: 1;
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.9);
    transform: scale(1.08);
    z-index: 2;
}
.chevron-markers { display: flex; margin-top: 0.35rem; }
.chevron-marker { flex: 1; height: 5px; border-radius: 3px; background: transparent; }
.chevron-marker.active { background: var(--color-accent-gold); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* Grille responsive pour les cartes de Paramètres : autant de colonnes que la largeur le permet
   (chaque carte garde une largeur minimale lisible), une seule colonne sur mobile. Les cartes de
   la grille perdent leur margin-bottom individuelle, le "gap" de la grille gère l'espacement. */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.settings-grid .card { margin-bottom: 0; }
@media (max-width: 640px) { .settings-grid { grid-template-columns: 1fr; } }

.dashboard-layout { display: flex; gap: 1.25rem; align-items: flex-start; }
.filters-sidebar { flex: 0 0 240px; position: sticky; top: 1.5rem; }
.filters-sidebar h2 { margin-bottom: 0.75rem; }
.filters-sidebar form button, .filters-sidebar form a.button { width: 100%; margin-top: 0.3rem; text-align: center; }
.results { flex: 1; min-width: 0; }
@media (max-width: 800px) {
    .dashboard-layout { flex-direction: column; }
    .filters-sidebar { flex-basis: auto; width: 100%; position: static; }
}

.pagination { display: flex; align-items: center; gap: 0.4rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination-ellipsis { padding: 0 0.2rem; color: var(--color-muted); }
.pagination a.disabled { opacity: 0.4; pointer-events: none; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: max-content; }

/* Deux premières colonnes figées pendant le défilement horizontal (tableaux très larges comme
   "Mes comptes") : la 1re a une largeur fixe pour que la 2e connaisse son décalage "left" exact ;
   fond opaque explicite (sinon le contenu défilé transparaît derrière), séparateur visuel à droite
   de la zone figée. */
.table-frozen-2 th:nth-child(1), .table-frozen-2 td:nth-child(1) { position: sticky; left: 0; z-index: 2; width: 44px; background: var(--color-surface); }
.table-frozen-2 th:nth-child(2), .table-frozen-2 td:nth-child(2) { position: sticky; left: 44px; z-index: 2; background: var(--color-surface); box-shadow: 3px 0 6px -3px rgba(0, 0, 0, 0.2); }
.table-frozen-2 thead th:nth-child(1), .table-frozen-2 thead th:nth-child(2) { z-index: 3; }
.table-frozen-2 tr:hover td:nth-child(1), .table-frozen-2 tr:hover td:nth-child(2) { background: #fafbfc; }
.login-wrap { max-width: 380px; margin: 4rem auto; }
.muted { color: var(--color-muted); font-size: 0.9em; }

.rappel-status { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0.5rem; border-radius: 12px; font-size: 0.78em; font-weight: 600; white-space: nowrap; }
.rappel-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rappel-status-retard { background: #fbe9e7; color: var(--color-danger); }
.rappel-status-retard::before { background: var(--color-danger); }
.rappel-status-proche { background: #fdf0dc; color: var(--color-warning); }
.rappel-status-proche::before { background: var(--color-warning); }
.rappel-status-ok { background: #e5f3ec; color: #0c891b; }
.rappel-status-ok::before { background: #0c891b; }
.rappel-status-fait { background: #eef1f4; color: var(--color-muted); }
.rappel-status-fait::before { background: var(--color-muted); }

.rappel-week-group { border-bottom: 1px solid var(--color-border); padding: 0.5rem 0; }
.rappel-week-group:last-child { border-bottom: none; }
.rappel-week-header { display: flex; justify-content: space-between; font-weight: 600; font-size: 0.9em; }
.rappel-week-items { margin: 0.3rem 0 0; padding: 0; list-style: none; font-size: 0.85em; }
.rappel-week-items li { padding: 0.15rem 0; color: var(--color-muted); display: flex; justify-content: space-between; gap: 0.5rem; }
.rappel-week-items a { color: inherit; }

.photo-cropper-viewport {
    width: 220px;
    height: 220px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    background: #eef1f4;
    border: 1px solid var(--color-border);
    cursor: grab;
    touch-action: none;
}
.photo-cropper-viewport img { position: absolute; top: 0; left: 0; max-width: none; user-select: none; -webkit-user-drag: none; }
.photo-cropper-viewport:active { cursor: grabbing; }

@media print {
    .topbar, .no-print { display: none !important; }
    .container, .container-full { max-width: none; margin: 0; }
    .card { border: none; box-shadow: none; padding: 0; margin-bottom: 1.5rem; break-inside: avoid; }
    body { background: #fff; }
}
