/* Homeloop Dashboard — thème (variables reskinnables une fois la charte fournie) */
:root {
  /* Charte Homeloop (extraite de homeloop.fr) */
  --brand:      #4c00ff;   /* violet électrique — accent principal */
  --brand-dark: #3a00c2;   /* hover */
  --brand-soft: #ede7ff;   /* tint clair */
  --brand-2:    #ed166e;   /* magenta — accent secondaire */
  --ink:        #0a0e34;   /* bleu nuit — texte */
  --ink-soft:   #696b82;
  --line:       #e6e7ef;
  --bg:         #f5f6fb;
  --card:       #ffffff;
  --danger:     #dc3545;
  --warn:       #f5a524;
  --maxw:       1240px;
  --radius:     14px;
  --shadow:     0 1px 2px rgba(16,32,48,.04), 0 6px 20px rgba(16,32,48,.06);
  --font:       "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; font-size: 15px; line-height: 1.45; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand-dark); }

/* ── Login ── */
#login { position: fixed; inset: 0; display: grid; place-items: center;
  background: linear-gradient(160deg, #4c00ff 0%, #0a0e34 100%); z-index: 50; }
.login-card { background: var(--card); padding: 32px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 320px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card input { width: 100%; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ── Brand / logo (wordmark placeholder) ── */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800;
  font-size: 20px; letter-spacing: -.02em; color: var(--ink); }
#homeBrand { cursor: pointer; }
.logo-img { height: 30px; width: auto; display: block; }
.logo-img-lg { height: 44px; width: auto; }
.brand.logo { font-size: 30px; justify-content: center; margin-bottom: 6px; }
.brand.logo .dot { width: 16px; height: 16px; }
.login-sub { text-align: center; color: var(--ink-soft); font-weight: 600; font-size: 15px; margin-bottom: 22px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--ink-soft); }
.app-foot { max-width: var(--maxw); margin: 8px auto 28px; padding: 0 24px; color: var(--ink-soft); font-size: 12px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft); }
.brand small { font-weight: 600; color: var(--ink-soft); font-size: 15px;
  margin-left: 8px; letter-spacing: 0; }

/* ── Header ── */
header.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
header.top .top-inner { max-width: var(--maxw); margin: 0 auto; padding: 4px 24px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
header.top .spacer { flex: 1; }
.period-pick { display: flex; align-items: center; gap: 10px; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); cursor: pointer; white-space: nowrap; }
.switch input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.switch.disabled { opacity: .4; cursor: not-allowed; }
.switch.disabled input { cursor: not-allowed; }
.banner-proj { background: var(--brand-soft); border: 1px solid var(--brand); color: var(--brand-dark);
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; }
.banner-proj b { color: var(--brand-dark); }
.nav { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 10px; }
.nav .tab { padding: 7px 13px; border-radius: 8px; border: none; background: transparent;
  font-weight: 600; font-size: 14px; color: var(--ink-soft); }
.nav .tab.active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

.subnav { background: #fff; border-bottom: 1px solid var(--line); }
.subnav-inner { max-width: var(--maxw); margin: 0 auto; padding: 8px 24px; }
.periodbar { background: var(--card); border-bottom: 1px solid var(--line); }
/* Masquée visuellement mais hauteur conservée (évite le décalage Évolution ⇄ Mois) */
.periodbar.is-empty { visibility: hidden; background: var(--bg); border-bottom-color: transparent; }
.periodbar-inner { max-width: var(--maxw); margin: 0 auto; padding: 8px 24px; display: flex; align-items: center; gap: 10px; }
.crumb { color: var(--ink-soft); font-size: 13px; margin: 4px 0 18px; }
.crumb a { color: var(--ink-soft); text-decoration: none; }
.crumb a:hover { color: var(--brand); }
.crumb b { color: var(--ink); font-weight: 700; }

/* ── Controls ── */
input, select { padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 14px; outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-weight: 600; font-size: 14px; color: var(--ink); transition: .15s; }
.btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.danger:hover { border-color: var(--danger); }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; padding: 8px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink-soft); transition: .15s; }
.iconbtn:hover { color: var(--brand); border-color: var(--brand); }
.iconbtn.active { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }

/* ── Layout ── */
main { max-width: var(--maxw); margin: 0 auto; padding: 24px; }
.section { margin-bottom: 32px; }
.section h2 { font-size: 16px; letter-spacing: -.01em; margin: 0 0 12px; display: flex;
  align-items: center; gap: 10px; }
.section h2 .count { font-weight: 600; color: var(--ink-soft); font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }

/* ── KPI cards ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; }
.kpi .val { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.kpi.accent { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand), var(--shadow); }
.kpi.accent .val { color: var(--brand); }
.kpi.muted { opacity: .5; }
.kpi.muted .val { color: var(--ink-soft); }

/* Page Import & Régions */
.import-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px;
  align-items: end; padding: 18px; }
.import-form .field { margin: 0; }
.import-grid { width: 100%; }
.import-grid td .pill { cursor: default; }
.dot-ok { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.dot-no { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #d9dde3; }

.import-row { display: flex; flex-wrap: wrap; gap: 14px; padding-bottom: 16px; }
.import-row .field { margin: 0; }
.import-row .field select, .import-row .field input { width: 160px; }
.import-row .field input[type="number"] { width: 100px; }

/* Dropzone */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center;
  display: flex; flex-direction: column; gap: 6px; align-items: center; transition: .15s; }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone strong { font-size: 15px; }
.imp-line { padding: 6px 10px; border-radius: 8px; font-size: 13px; margin-top: 4px; }
.imp-line.ok { background: var(--brand-soft); color: var(--brand-dark); }
.imp-line.ko { background: #fde8e8; color: var(--danger); }

/* Checklist */
.checklist th, .checklist td { text-align: center; padding: 6px 8px; font-size: 13px; white-space: nowrap; }
.checklist td:first-child, .checklist th:first-child { text-align: left; }
.checklist .ver-sel { font-size: 12px; padding: 2px 4px; max-width: 96px; }
.cl-date { font-size: 12px; color: var(--ink-soft); }
.cl-x { border: none; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 12px; padding: 0 1px; margin-left: 1px; }
.cl-x:hover { color: var(--danger); }
.coh.ok { color: var(--brand-dark); font-weight: 600; }
.coh.warn { color: var(--warn); font-weight: 600; }

/* Éditeur régions */
.reg-editor { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.reg-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.reg-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.reg-name { font-weight: 700; font-size: 15px; flex: 1; }
.sec-block { background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.sec-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.sec-name { flex: 1; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 20px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; }
.chip b { cursor: pointer; color: var(--brand-dark); opacity: .6; }
.chip b:hover { opacity: 1; color: var(--danger); }
.add-dept { font-size: 12.5px; padding: 4px 8px; }
.reg-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.reg-actions #saveReg { margin-left: auto; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { text-align: center; padding: 11px 14px; font-size: 12px; font-weight: 700;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
thead th:first-child { text-align: left; }
tbody td { padding: 9px 14px; text-align: center; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: none; }

/* hiérarchie géo */
tr.row-region { cursor: pointer; }
tr.row-region > td { font-weight: 700; background: #fff; }
tr.row-region:hover > td { background: var(--brand-soft); }
tr.row-secteur { cursor: pointer; }
tr.row-secteur > td:first-child { padding-left: 34px; }
tr.row-secteur > td { color: var(--ink); background: #fcfdfe; }
tr.row-secteur:hover > td { background: var(--brand-soft); }
tr.row-dept > td:first-child { padding-left: 58px; color: var(--ink-soft); }
tr.row-dept > td { color: var(--ink-soft); }
tr.row-total > td { font-weight: 800; background: #f3f5f8; border-top: 2px solid var(--line); }
tr.row-na > td:first-child { color: var(--warn); font-weight: 700; }
/* Partenaire : compté nulle part dans le total, donc grisé et en italique. */
tr.row-hp > td { color: var(--ink-soft); font-style: italic; }
/* regroupement dépliable (campagnes UTM) */
tr.row-group { cursor: pointer; }
tr.row-group > td { font-weight: 700; background: #fff; }
tr.row-group:hover > td { background: var(--brand-soft); }
tr.row-group .count { margin-left: 4px; }
tr.row-child > td:first-child { padding-left: 34px; color: var(--ink-soft); }
tr.row-child > td { color: var(--ink-soft); background: #fcfdfe; }
/* Coût/lead attribué vs global de la période */
#geoTable td.cell-good { background: #e7f6ee; color: #137a4b; font-weight: 600; }
#geoTable td.cell-warn { background: #fff3e0; color: #b76a00; font-weight: 600; }
#geoTable td.cell-bad  { background: #fde8e8; color: var(--danger); font-weight: 600; }
.geo-legend { display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  font-weight: 600; color: var(--ink-soft); margin-left: 10px; }
.geo-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.geo-legend i.lg-good { background: #e7f6ee; border: 1px solid #137a4b; margin-right: 1px; }
.geo-legend i.lg-warn { background: #fff3e0; border: 1px solid #b76a00; margin: 0 1px 0 8px; }
.geo-legend i.lg-bad { background: #fde8e8; border: 1px solid var(--danger); margin: 0 1px 0 8px; }
.chev { display: inline-block; width: 14px; color: var(--ink-soft); transition: transform .15s;
  font-size: 11px; }
.collapsed .chev { transform: rotate(-90deg); }
.hidden { display: none !important; }

/* Tableau large (Performance par région, jusqu'à 9 colonnes) : scroll dans sa carte plutôt que
   de pousser toute la page en largeur, à n'importe quelle taille d'écran (pas que le mobile). */
.tbl-scroll { overflow-x: auto; }
#geoTable th, #geoTable td { padding: 8px 10px; font-size: 13px; }
#geoTable thead th { white-space: normal; line-height: 1.25; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px;
  font-weight: 700; background: var(--brand-soft); color: var(--brand-dark); }
.barcell { position: relative; }

/* ── Modal ── */
.modal-bg { position: fixed; inset: 0; background: rgba(16,32,48,.5); display: grid;
  place-items: center; z-index: 40; padding: 20px; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; overflow: auto; }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal .body { padding: 20px; }
.modal .foot { padding: 16px 20px; border-top: 1px solid var(--line); display: flex;
  justify-content: flex-end; gap: 10px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }
.field input, .field select { width: 100%; }
textarea { width: 100%; min-height: 320px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
.help { font-size: 12.5px; color: var(--ink-soft); }

/* ── Empty / toast ── */
.empty { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 60; opacity: 0; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
#toast.err { background: var(--danger); }

.dim-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
.chart-wrap { padding: 16px; }
.chart-tools { padding: 12px 14px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chart-tools select { width: auto; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--brand); }

#btnLogout { display: inline-flex; align-items: center; }

@media (max-width: 768px) {
  main { padding: 16px; }
  header.top .top-inner { padding: 8px 14px; gap: 8px; }
  .subnav-inner { padding: 8px 14px; }
  .nav { overflow-x: auto; }
  .dim-grid { grid-template-columns: 1fr; }
  thead th, tbody td { padding: 8px 9px; }
  .hide-sm { display: none; }
  /* Header mobile : logo + pictos sur une ligne, mois dessous */
  header .brand small { display: none; }
  .logo-img { height: 30px; }
  .periodbar-inner { justify-content: center; flex-wrap: wrap; padding: 8px 14px; }
  /* Tableaux : défilement horizontal pour voir tout le contenu */
  .card { overflow-x: auto; }
  .card > table, table.import-grid { min-width: 680px; }
}
