/* Carnet de Tournée — charte Cartel (cartelshop.be) : jaune Cartel, noir, blanc, gris.
   Le jaune sert de fond (avec texte noir), jamais de couleur de texte sur fond clair. */
:root {
  --canvas: #fff9dc;        /* jaune pâle */
  --paper: #ffffff;
  --paper-2: #f7f6f4;
  --ink: #333333;
  --muted: #6b6b6b;
  --line: #dadada;
  --primary: #000000;       /* titres, liens, sélection */
  --primary-2: #404040;
  --primary-soft: #ecebe8;
  --brand: #ffd600;         /* jaune Cartel */
  --brand-ink: #000000;     /* texte posé sur le jaune */
  --brand-text: #7a6200;    /* jaune assombri, lisible en texte sur fond clair */
  --brand-soft: #fff6bf;
  --danger: #c62828;
  --danger-soft: #fde2e0;
  --ok: #2e7d32;
  --ok-soft: #dcefdc;
  --shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .06);
  --radius: 10px;
  --f-title: 'Oswald', 'Arial Narrow', sans-serif;
  --f-text: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --nav-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #111111;
    --paper: #1c1c1c;
    --paper-2: #242424;
    --ink: #ececec;
    --muted: #a3a3a3;
    --line: #363636;
    --primary: #ffd600;
    --primary-2: #bdbdbd;
    --primary-soft: #2c2a22;
    --brand: #ffd600;
    --brand-ink: #000000;
    --brand-text: #ffd600;
    --brand-soft: #332b00;
    --danger: #ff8a80;
    --danger-soft: #4a1f1c;
    --ok: #81c784;
    --ok-soft: #1d3a22;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.45 var(--f-text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
h1, h2 { font-family: var(--f-title); font-weight: 600; letter-spacing: .02em; margin: 0; }
h1 { font-size: 1.55rem; text-transform: uppercase; }
h2 { font-size: 1rem; text-transform: uppercase; color: var(--primary); margin-bottom: 12px; }
a { color: var(--primary); }
code { font-family: var(--f-mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: #000; color: #fff;
  border-top: 6px solid var(--brand);   /* bandeau jaune comme en haut de cartelshop.be */
  border-bottom: 1px solid #000;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-family: var(--f-title); font-size: 1.3rem; letter-spacing: .03em; white-space: nowrap; }
.brand-name small { font: 600 .72rem var(--f-text); letter-spacing: .06em; text-transform: uppercase; color: var(--brand); margin-left: 6px; }
@media (max-width: 480px) { .brand-name small { display: none; } }
.login-brand h1 { text-transform: none; letter-spacing: .03em; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  background: var(--brand); color: #000; border-radius: 7px; border: 2px solid #000;
  font-family: var(--f-title); font-weight: 600;
}
.who { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.who form { margin: 0; }
@media (max-width: 400px) { .brand-name { font-size: 1rem; } .who { gap: 10px; font-size: .82rem; } }
@media (max-width: 340px) { .brand-name { display: none; } }
.topbar .logo { border-color: var(--brand); }
.topbar .linkish { color: #fff; opacity: .9; }
.topbar .linkish:hover { color: var(--brand); opacity: 1; }

.linkish {
  background: none; border: 0; padding: 0; font: inherit; color: var(--primary);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- Navigation : barre du bas sur mobile, onglets en haut sur grand écran ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  height: var(--nav-h); padding: 8px 2px 6px; border: 0; background: none; color: var(--muted);
  font: 600 .72rem var(--f-text); cursor: pointer;
}
.tabs .ico { font-size: 1.25rem; line-height: 1.2; }
.tabs button.on { color: var(--primary); box-shadow: inset 0 4px 0 var(--brand); }
.badge {
  position: absolute; top: 5px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font: 700 .7rem/18px var(--f-text);
}
@media (prefers-color-scheme: dark) { .badge { color: #111; } }

@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  .tabs {
    position: sticky; top: 0; bottom: auto;
    display: flex; justify-content: center; gap: 4px;
    border-top: 0; border-bottom: 1px solid var(--line);
  }
  .tabs button { flex-direction: row; gap: 8px; height: 50px; padding: 0 18px; font-size: .9rem; }
  .tabs .ico { font-size: 1rem; }
  .tabs button.on { box-shadow: inset 0 -4px 0 var(--brand); }
  .badge { position: static; }
}

/* ---------- Mise en page ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 4px 0 16px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.banner {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
  background: var(--brand-soft); border: 1px solid var(--brand); border-radius: var(--radius);
  padding: 10px 14px; margin: 0 0 16px; font-weight: 600;
}
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
/* Titres soulignés de jaune, comme les intertitres de cartelshop.be */
.card > h2 { display: inline-block; padding-bottom: 5px; border-bottom: 3px solid var(--brand); }
.grid2 { display: grid; gap: 16px; }
@media (min-width: 820px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row2 { display: grid; gap: 14px; }
@media (min-width: 560px) { .row2 { grid-template-columns: 1fr 1fr; } }
.row-num, .row-cp { display: grid; gap: 14px; grid-template-columns: 110px 1fr; }
.num { font-family: var(--f-mono); font-size: .78rem; color: var(--muted); margin-right: 6px; }
.addr { font-size: .88rem; margin-top: 3px; }
.item-links { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.item-links a { font-weight: 600; font-size: .88rem; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

/* ---------- Formulaires ---------- */
label, .field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.field-label { font-weight: 600; font-size: .9rem; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  font: 400 16px var(--f-text); color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px; box-shadow: 0 0 0 5px var(--brand-soft);
}
input.mono { font-family: var(--f-mono); }
fieldset.newclient {
  margin: 0; padding: 14px; border: 1.5px dashed var(--primary-2); border-radius: var(--radius);
  background: var(--brand-soft);
}
fieldset.newclient input { background: var(--paper); }
legend { font-family: var(--f-title); text-transform: uppercase; color: var(--brand-ink); background: var(--brand); padding: 1px 8px; border-radius: 4px; }
.relance-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.relance-row input { flex: 1 1 160px; width: auto; }

/* Contrôle segmenté (boutons ou radios) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper-2); align-self: flex-start; }
.seg button, .seg label span {
  display: block; padding: 0 14px; line-height: 44px; border: 0; background: none;
  font: 600 .9rem var(--f-text); color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg > * + * { border-left: 1px solid var(--line); }
.seg label { display: block; gap: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; pointer-events: none; }
.seg button.on, .seg input:checked + span { background: #000; color: var(--brand); }
@media (prefers-color-scheme: dark) { .seg button.on, .seg input:checked + span { background: var(--brand); color: #000; } }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: 600 .92rem var(--f-text); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--primary-2); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--brand); border: 2px solid #000; color: var(--brand-ink); font-weight: 700; }
@media (prefers-color-scheme: dark) { .btn.primary { border-color: var(--brand); } }
.btn.primary:hover { background: #000; color: var(--brand); border-color: #000; }
@media (prefers-color-scheme: dark) { .btn.primary:hover { background: #fff; color: #000; border-color: #fff; } }
.btn.big { min-height: 52px; font-size: 1.02rem; padding: 0 26px; }
.btn.sm { min-height: 36px; padding: 0 11px; font-size: .82rem; }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn.wide { width: 100%; margin-top: 12px; }
.danger-text { color: var(--danger); }
@media (max-width: 559px) { #visit-form .actions .btn { flex: 1; } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 820px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: var(--paper); border: 1px solid var(--line); border-left: 5px solid var(--brand);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  font: inherit; color: inherit; min-width: 0;
}
button.kpi { cursor: pointer; }
.kpi-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kpi-val { font: 500 1.6rem/1.2 var(--f-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-sub { font-size: .8rem; color: var(--muted); }
.kpi.alert-kpi { border-left-color: var(--danger); background: var(--danger-soft); }
.kpi.alert-kpi .kpi-val, .kpi.alert-kpi .kpi-sub { color: var(--danger); font-weight: 700; }
@media (max-width: 380px) { .kpi-val { font-size: 1.3rem; } }

/* ---------- Graphique ---------- */
.chart { display: block; width: 100%; height: auto; max-height: 260px; overflow: visible; }
.chart .bar { fill: var(--primary-2); }
.chart .bar.cur { fill: var(--brand); stroke: var(--primary); stroke-width: 1.5; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { font: 500 10.5px var(--f-mono); fill: var(--muted); text-anchor: middle; }
.chart text.val { fill: var(--ink); }
.chart text.lbl.cur { fill: var(--primary); font-weight: 700; }

/* ---------- Pipeline ---------- */
.pipe { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.pipe li { display: grid; grid-template-columns: 118px 1fr 32px; align-items: center; gap: 10px; }
.pipe-label { font-size: .88rem; font-weight: 600; }
.pipe-track { height: 14px; background: var(--paper-2); border-radius: 7px; overflow: hidden; border: 1px solid var(--line); }
.pipe-bar { display: block; height: 100%; width: 0; border-radius: 7px; transition: width .3s; }
.pipe-n { font-family: var(--f-mono); text-align: right; }
.st-a_contacter { --st: #a3a3a3; }
.st-contacte { --st: var(--primary-2); }
.st-negociation { --st: var(--brand); }
.st-negociation.pipe-bar { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35); }
.st-gagne { --st: var(--ok); }
.st-perdu { --st: var(--danger); }
.pipe-bar { background: var(--st); }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list.cards { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; font-style: italic; }
.list.cards .empty { background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); }
.note { margin: 6px 0 0; white-space: pre-wrap; font-size: .9rem; color: var(--ink); opacity: .85; }

.item {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.item-top { display: flex; gap: 12px; align-items: flex-start; }
.item-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-side { flex: none; }
.item-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.date {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 54px; padding: 6px 0; background: var(--primary-soft); color: var(--primary); border-radius: 8px; font-size: .95rem;
}
.date small { font-size: .7rem; opacity: .8; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .75rem; font-weight: 700;
  background: var(--paper-2); border: 1px solid var(--line); color: var(--muted); vertical-align: middle;
}
.tag.ex { margin-left: 6px; border-style: dashed; font-weight: 600; }
.tag.t-visite { color: var(--primary); border-color: var(--primary); }
.tag.t-appel { color: var(--muted); }
.tag.t-livraison { color: var(--ok); border-color: var(--ok); }
.tag.r-commande { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.tag.r-devis, .tag.r-rdv { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.tag.r-pas_interesse { color: var(--danger); }
.tag.rl { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.tag.client { background: var(--ok-soft); color: var(--ok); border-color: transparent; font-size: .8rem; padding: 4px 10px; }
.amount { font-weight: 500; color: var(--ok); }
.tel { display: inline-block; margin-top: 4px; font-weight: 600; font-family: var(--f-mono); font-size: .9rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--paper-2); border-radius: 8px; padding: 8px 10px; font-size: .88rem; }
.stats small { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }

.statut-select {
  width: auto; min-height: 36px; padding: 4px 30px 4px 10px; font-size: .82rem; font-weight: 700;
  border: 1.5px solid var(--primary-2); color: var(--ink); background-color: var(--paper);
  box-shadow: inset 5px 0 0 var(--st);  /* repère de couleur du statut (le jaune ne se lit pas en texte) */
}

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.filters input { flex: 1 1 220px; width: auto; }
.filters select { flex: 0 1 170px; width: auto; }

/* Relances */
.rel {
  display: flex; gap: 12px; justify-content: space-between; align-items: flex-start;
  padding: 10px 12px; border-left: 4px solid var(--brand); background: var(--paper-2); border-radius: 8px;
}
.list:not(.cards) .rel + .rel { margin-top: 8px; }
.list.cards .rel { background: var(--paper); border: 1px solid var(--line); border-left-width: 4px; border-left-color: var(--brand); box-shadow: var(--shadow); }
.rel.late, .list.cards .rel.late { border-left-color: var(--danger); background: var(--danger-soft); }
.rel-main { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.rel-top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.when { font-size: .82rem; font-weight: 700; color: var(--primary); }
.rel.late .when { color: var(--danger); }
.rel-act { display: flex; flex-direction: column; gap: 6px; flex: none; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 10px; }
.section-title.late { color: var(--danger); margin-top: 0; }
.count { font-family: var(--f-mono); font-size: .85rem; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 0 8px; color: var(--muted); }

/* Classement */
.list.top { counter-reset: rank; }
.list.top li:not(.empty) {
  counter-increment: rank; display: flex; align-items: center; gap: 12px; padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}
.list.top li:not(.empty)::before {
  content: counter(rank); display: grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  font: 600 .85rem var(--f-mono);
}
.list.top li:first-child::before { background: var(--brand); color: var(--brand-ink); box-shadow: inset 0 0 0 1.5px #000; }
.top-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Dialogue ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  padding: 18px; border: 1px solid var(--line); border-top: 5px solid var(--brand);
  border-radius: var(--radius); background: var(--paper); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 25, 30, .55); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 8px;
  background: var(--ink); color: var(--canvas); font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 820px) { .toast { bottom: 24px; } }

/* ---------- Page de connexion ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--paper); border: 1px solid var(--line);
  border-top: 6px solid var(--brand); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.login-brand .logo { width: 48px; height: 48px; font-size: 1.3rem; }
.login-brand h1 { font-size: 1.4rem; }
.login-brand p { margin: 0; }
.alert { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); border-radius: 8px; padding: 10px 12px; font-weight: 600; }
