/* ==========================================================================
   Tournée Perly — feuille de style
   Pensée pour une main, en extérieur, tôt le matin.
   ========================================================================== */

:root {
  /* Palette sombre (par défaut : lisible à l'aube, économe en batterie OLED) */
  --bg:        #0D1B21;
  --bg-elev:   #14282F;
  --surface:   #17303A;
  --surface-2: #1E3C47;
  --line:      rgba(255, 255, 255, .10);
  --line-soft: rgba(255, 255, 255, .05);
  --text:      #E9F1F2;
  --muted:     #8CA6AD;
  --accent:    #2CA6B8;   /* teal — repère principal */
  --accent-ink:#062026;
  --done:      #45C08A;   /* vert — livré */
  --warn:      #F0A93B;   /* ambre — code porte, attention */
  --danger:    #E5675F;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  --s-1: 4px;  --s-2: 8px;  --s-3: 12px;
  --s-4: 16px; --s-5: 24px; --s-6: 32px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --tap: 48px;              /* cible tactile minimale */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="light"] {
  --bg:        #EEF2F1;
  --bg-elev:   #FFFFFF;
  --surface:   #FFFFFF;
  --surface-2: #F3F6F6;
  --line:      rgba(18, 38, 45, .14);
  --line-soft: rgba(18, 38, 45, .07);
  --text:      #12262D;
  --muted:     #5E7379;
  --accent:    #10707F;
  --accent-ink:#FFFFFF;
  --done:      #1E9C6B;
  --warn:      #B36A08;
  --danger:    #C0392B;
}

@media (prefers-color-scheme: light) {
  html[data-theme="auto"] {
    --bg:        #EEF2F1;
    --bg-elev:   #FFFFFF;
    --surface:   #FFFFFF;
    --surface-2: #F3F6F6;
    --line:      rgba(18, 38, 45, .14);
    --line-soft: rgba(18, 38, 45, .07);
    --text:      #12262D;
    --muted:     #5E7379;
    --accent:    #10707F;
    --accent-ink:#FFFFFF;
    --done:      #1E9C6B;
    --warn:      #B36A08;
    --danger:    #C0392B;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(96px + var(--safe-b));
  overscroll-behavior-y: contain;
}

button, input, textarea, a { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- Barre supérieure ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  padding: var(--s-3) var(--s-4) var(--s-2);
  padding-top: calc(var(--s-3) + env(safe-area-inset-top, 0px));
}

.topbar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.brand { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }

.brand__mark {
  width: 10px; height: 22px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent) 0 55%, var(--warn) 55% 100%);
  flex: none;
}

.brand__name {
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 1.05rem;
  white-space: nowrap;
}

.topbar__actions { display: flex; align-items: center; gap: var(--s-1); }

.iconbtn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: 1.1rem;
  line-height: 1;
  flex: none;
}
.iconbtn--ghost { background: transparent; border-color: transparent; }
.iconbtn:active { transform: scale(.94); }

.pill {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.pill--sync { background: rgba(240, 169, 59, .16); color: var(--warn); border: 1px solid rgba(240, 169, 59, .3); }

/* ---------- Compteurs ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  border-left: 3px solid var(--muted);
}
.stat--net  { border-left-color: var(--warn); }
.stat--done { border-left-color: var(--done); }

.stat__num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1;
}
.stat--net .stat__num  { color: var(--warn); }
.stat--done .stat__num { color: var(--done); }

.stat__pair { display: flex; align-items: baseline; gap: var(--s-2); }

.stat__num--brut {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}
.stat__num--brut::before { content: "/"; margin-right: var(--s-2); opacity: .45; }
.stat__num--brut[hidden] { display: none; }

.stat__label {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

/* ---------- Barre d'avancement ---------- */

.progress {
  height: 5px;
  margin-top: var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--done));
  border-radius: var(--r-full);
  transition: width .3s ease;
}

/* ---------- Estimation de temps ---------- */

.chrono {
  margin: var(--s-2) 0 0;
  font-size: .78rem;
  color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 4px var(--s-2);
  align-items: baseline;
  min-height: 1em;
}
.chrono b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}
.chrono .eta { color: var(--accent); font-family: var(--mono); font-weight: 600; }
.chrono .cal { opacity: .75; }

/* ---------- Recherche ---------- */

.searchrow { position: relative; margin-top: var(--s-3); }

.search {
  width: 100%;
  height: var(--tap);
  padding: 0 44px 0 var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--text);
}
.search::placeholder { color: var(--muted); }
.search::-webkit-search-cancel-button { display: none; }

.searchrow .iconbtn {
  position: absolute; right: 4px; top: 3px;
  width: 42px; height: 42px;
}

/* ---------- Panneau réglages ---------- */

.panel {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  padding: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-4);
}

.panel__group { display: flex; flex-direction: column; gap: var(--s-2); }
.panel__group--row { flex-direction: row; flex-wrap: wrap; gap: var(--s-2); }

.panel__title {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 700;
}

.panel__note { margin: 0; font-size: .78rem; color: var(--muted); }

.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 3px;
  gap: 3px;
}

.seg {
  flex: 1;
  min-height: 40px;
  padding: 0 var(--s-2);
  border: none;
  background: transparent;
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}
.seg.is-active { background: var(--accent); color: var(--accent-ink); }

.switch {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: var(--tap);
  cursor: pointer;
  font-size: .92rem;
}
.switch input {
  width: 24px; height: 24px;
  accent-color: var(--accent);
  flex: none;
}

.btn {
  min-height: var(--tap);
  padding: 0 var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-weight: 600;
}
.btn--danger { color: var(--danger); border-color: var(--danger); }
@supports (color: color-mix(in srgb, red 40%, transparent)) {
  .btn--danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
}
.btn--go { background: var(--done); color: #05221A; border-color: transparent; padding: 0 var(--s-5); }
html[data-theme="light"] .btn--go { color: #fff; }

/* ---------- Liste ---------- */

.list { padding: var(--s-3) var(--s-3) var(--s-6); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: var(--s-6) var(--s-4);
  font-size: .92rem;
}

/* Séparateur de rue : encode le passage à une nouvelle rue de la tournée */
.streetbar {
  display: flex; align-items: baseline; gap: var(--s-2);
  padding: var(--s-4) var(--s-2) var(--s-2);
}
.streetbar__name {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.streetbar__count {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* Groupe repliable (mode « par rue ») */
.group { margin-bottom: var(--s-3); }
.group__head {
  width: 100%;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 52px;
  padding: 0 var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-align: left;
}
.group__name { font-weight: 700; letter-spacing: -.01em; flex: 1; min-width: 0; }
.group__bar {
  width: 56px; height: 5px;
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden; flex: none;
}
.group__bar i { display: block; height: 100%; background: var(--done); }
.group__count {
  font-family: var(--mono); font-size: .78rem; color: var(--muted);
  font-variant-numeric: tabular-nums; flex: none;
}
.group__chev { color: var(--muted); flex: none; transition: transform .2s; }
.group.is-open .group__chev { transform: rotate(90deg); }
.group__body { display: none; padding-top: var(--s-2); }
.group.is-open .group__body { display: block; }

/* ---------- Carte adresse ---------- */

.card {
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  grid-template-areas:
    "check main net"
    "check tags tags"
    "note  note note";
  align-items: center;
  gap: var(--s-1) var(--s-3);
  padding: var(--s-3);
  margin-bottom: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  border-radius: var(--r-md);
}
.card.is-done {
  background: var(--surface-2);
  border-left-color: var(--done);
  opacity: .58;
}
.card.is-done .card__addr { text-decoration: line-through; text-decoration-thickness: 2px; }
.card.is-flash { animation: flash .5s ease; }
@keyframes flash { from { background: var(--surface-2); } }

.card__check {
  grid-area: check;
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line);
  background: transparent;
  border-radius: var(--r-md);
  font-size: 1.4rem; line-height: 1;
  color: transparent;
}
.card.is-done .card__check {
  background: var(--done);
  border-color: var(--done);
  color: #05221A;
}
.card__check:active { transform: scale(.92); }

.card__main {
  grid-area: main;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.card__ordre {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--muted);
  letter-spacing: .05em;
}
.card__addr {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.card__num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.card__figs {
  grid-area: net;
  display: flex; align-items: flex-start; gap: var(--s-4);
}

.fig { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.fig b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1;
}
.fig small {
  font-size: .6rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}

.fig--net b  { font-size: 1.6rem; color: var(--warn); }
.fig--net.is-zero b { color: var(--muted); opacity: .5; }
.fig--brut b { font-size: 1.15rem; color: var(--muted); }

.card__tags {
  grid-area: tags;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  margin-top: var(--s-1);
}

/* Élément signature : la pastille code porte, copiable d'un doigt */
.code {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .12em;
}
@supports (color: color-mix(in srgb, red 14%, transparent)) {
  .code {
    background: color-mix(in srgb, var(--warn) 14%, transparent);
    border-color: color-mix(in srgb, var(--warn) 38%, transparent);
  }
  .card__tool.has-note { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
  .card.is-flash { animation: flash .5s ease; }
}

.code::before { content: "⌨"; font-size: .8rem; letter-spacing: 0; opacity: .7; }
.code:active { transform: scale(.95); }

.tag {
  display: inline-flex; align-items: center;
  min-height: 30px; padding: 0 10px;
  border-radius: var(--r-sm);
  font-size: .78rem;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--muted);
}
.tag--obs { color: var(--text); border-color: var(--line); }
.tag--brut { font-family: var(--mono); }

.card__tool {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 34px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--muted);
  text-decoration: none;
}
.card__tool.has-note { color: var(--accent); border-color: var(--accent); }

.card__note { grid-area: note; width: 100%; }
.card__note[hidden] { display: none; }
.card__note textarea {
  width: 100%;
  min-height: 64px;
  margin-top: var(--s-2);
  padding: var(--s-3);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  resize: vertical;
}

/* ---------- Dock « prochaine adresse » ---------- */

.dock {
  position: fixed;
  left: var(--s-3); right: var(--s-3);
  bottom: calc(var(--s-3) + var(--safe-b));
  z-index: 40;
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
html[data-theme="light"] .dock { box-shadow: 0 8px 24px rgba(18, 38, 45, .16); }

.dock__info { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.dock__eyebrow {
  font-size: .6rem; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700;
}
.dock__addr {
  font-weight: 700; font-size: 1rem; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dock__meta { font-family: var(--mono); font-size: .74rem; color: var(--muted); }
.dock__meta b { color: var(--warn); }
.dock__actions { display: flex; align-items: center; gap: var(--s-2); flex: none; }
.iconbtn--dock { text-decoration: none; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b));
  z-index: 60;
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-full);
  font-size: .88rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  max-width: calc(100vw - 32px);
}
.toast button {
  background: none; border: none; padding: 0;
  color: var(--accent); font-weight: 700; text-decoration: underline;
}

/* ---------- Écrans larges ---------- */

@media (min-width: 720px) {
  .topbar, .panel { padding-left: var(--s-5); padding-right: var(--s-5); }
  .list { max-width: 900px; margin: 0 auto; padding-left: var(--s-5); padding-right: var(--s-5); }
  .dock { left: 50%; transform: translateX(-50%); width: min(880px, calc(100% - 48px)); }
  .stat__num { font-size: 1.8rem; }
  .card { grid-template-columns: var(--tap) 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
