:root {
  --bg: #f4f6f8; --surface: #fff; --surface-2: #f0f3f6; --text: #18212b; --muted: #637083; --line: #dfe4ea;
  --primary: #1f3a5c; --primary-ink: #fff; --accent: #e8127a; --danger: #c62828; --warn: #b45309; --radius: 12px;
  --st-nouvelle-bg: #dbeafe; --st-nouvelle-fg: #1e40af;
  --st-en_cours-bg: #fef3c7; --st-en_cours-fg: #92400e;
  --st-attente_fourniture-bg: #fee2e2; --st-attente_fourniture-fg: #991b1b;
  --st-attente_validation_client-bg: #ede9fe; --st-attente_validation_client-fg: #5b21b6;
  --st-cloturee-bg: #dcfce7; --st-cloturee-fg: #166534;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c; --surface: #18212b; --surface-2: #202b37; --text: #e8edf2; --muted: #93a1b3; --line: #2c3947;
    --primary: #4c8dff; --danger: #ef6b6b; --warn: #f0a04b; --shadow: none;
    --st-nouvelle-bg: #1c2f57; --st-nouvelle-fg: #9ec1ff;
    --st-en_cours-bg: #4a3712; --st-en_cours-fg: #fcd581;
    --st-attente_fourniture-bg: #4c1d1d; --st-attente_fourniture-fg: #ffb0b0;
    --st-attente_validation_client-bg: #372a5c; --st-attente_validation_client-fg: #cdbcff;
    --st-cloturee-bg: #14382a; --st-cloturee-fg: #93e0b0;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .5rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
.count { color: var(--muted); font-size: .9rem; margin: .5rem 0; }
.section { margin: 1.5rem 0 .5rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.back { margin: 0 0 .5rem; }

/* ---- structure */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem;
  padding-top: max(.5rem, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; color: var(--text); }
.brand img { display: block; height: 2.4rem; width: auto; }
.brand:hover { text-decoration: none; }
.brand-app { font-size: .72rem; font-weight: 700; letter-spacing: .12em; color: var(--muted); border-left: 1px solid var(--line); padding-left: .5rem; }
.login-logo { display: block; width: min(15rem, 70%); height: auto; margin: 0 auto .5rem; }
.report-logo { height: 3.2rem; width: auto; align-self: flex-start; }
@media (prefers-color-scheme: dark) { .brand img, .login-logo { background: #fff; padding: .25rem .6rem; border-radius: 8px; } }
.topbar nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.topbar nav a { padding: .45rem .75rem; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar nav a.on { background: var(--primary); color: var(--primary-ink); }
main { max-width: 1120px; margin: 0 auto; padding: 1rem; padding-bottom: 6rem; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.menu {
  position: absolute; right: 0; top: 2.6rem; min-width: 12rem; display: grid; gap: .25rem; padding: .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
}
.menu a, .menu button { text-align: left; padding: .5rem; border: 0; background: none; border-radius: 6px; color: var(--text); font: inherit; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ---- cartes, listes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.list { display: grid; gap: .6rem; }
.list .card { margin: 0; }
.card.order { display: grid; gap: .3rem; color: inherit; }
.card.order:hover { text-decoration: none; border-color: var(--primary); }
.card.order h3 { font-size: 1.02rem; }
.row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.meta { display: flex; gap: .25rem .9rem; flex-wrap: wrap; color: var(--muted); font-size: .88rem; align-items: center; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); font-size: .85rem; }
.item-main { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1; min-width: 12rem; }
.item-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.item-detail { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--line); }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.type { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--st-en_cours-bg); color: var(--st-en_cours-fg); }
.badge.pr-urgent { background: var(--st-attente_fourniture-bg); color: var(--st-attente_fourniture-fg); }
.badge.pr-a_prevoir { background: var(--st-nouvelle-bg); color: var(--st-nouvelle-fg); }
.badge.sp-demandee { background: var(--st-attente_fourniture-bg); color: var(--st-attente_fourniture-fg); }
.badge.sp-commandee { background: var(--st-en_cours-bg); color: var(--st-en_cours-fg); }
.badge.sp-livree { background: var(--st-cloturee-bg); color: var(--st-cloturee-fg); }
.pill { display: inline-block; min-width: 1.4rem; padding: 0 .4rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .78rem; text-align: center; font-weight: 600; }
@media (min-width: 0) {
  .badge.st-nouvelle, .tile.st-nouvelle, .chip.st-nouvelle.on { background: var(--st-nouvelle-bg); color: var(--st-nouvelle-fg); }
  .badge.st-en_cours, .tile.st-en_cours, .chip.st-en_cours.on { background: var(--st-en_cours-bg); color: var(--st-en_cours-fg); }
  .badge.st-attente_fourniture, .tile.st-attente_fourniture, .chip.st-attente_fourniture.on { background: var(--st-attente_fourniture-bg); color: var(--st-attente_fourniture-fg); }
  .badge.st-attente_validation_client, .tile.st-attente_validation_client, .chip.st-attente_validation_client.on { background: var(--st-attente_validation_client-bg); color: var(--st-attente_validation_client-fg); }
  .badge.st-cloturee, .tile.st-cloturee, .chip.st-cloturee.on { background: var(--st-cloturee-bg); color: var(--st-cloturee-fg); }
}

/* ---- tableau de bord */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .6rem; }
.tile { display: grid; gap: .1rem; padding: .9rem 1rem; border-radius: var(--radius); color: inherit; }
.tile:hover { text-decoration: none; filter: brightness(.97); }
.tile strong { font-size: 1.9rem; line-height: 1.1; }
.tile span { font-size: .88rem; font-weight: 600; }
.tile.plain { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.tile.plain span { color: var(--muted); font-weight: 400; }
.tile.plain.danger strong { color: var(--danger); }
.tile.plain.warn strong { color: var(--warn); }
.tiles.small strong { font-size: 1.5rem; }
.tiles.admin { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.tiles.admin strong { font-size: 1.05rem; }

/* ---- formulaires */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .5rem; margin-bottom: .75rem; align-items: center; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .8rem 1rem; align-items: start; }
.form.narrow { max-width: 26rem; }
.form > .wide, .form .wide { grid-column: 1 / -1; }
.form h2, .form h3 { margin: 0; }
.form h3 { margin-top: .5rem; padding-top: .8rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.field { display: grid; gap: .25rem; }
.field > span, .lbl { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: .78rem; }
input, select, textarea {
  width: 100%; padding: .6rem .7rem; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 2.6rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input:disabled, select:disabled { opacity: .6; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 2.6rem; }
.check input { width: 1.2rem; min-height: 0; height: 1.2rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; }
.form-actions.sticky { position: sticky; bottom: 4.6rem; padding: .6rem 0 0; background: linear-gradient(transparent, var(--surface) 35%); }
.inline-add { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.inline-add input { flex: 1; min-width: 10rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; min-height: 2.6rem; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .7rem; min-height: 2.1rem; font-size: .88rem; }
.btn.tiny { padding: .1rem .5rem; min-height: 1.7rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
button.icon { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .3rem .5rem; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.chip { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.chip.on { border-color: transparent; background: var(--primary); color: var(--primary-ink); }

/* ---- fiche */
.detail-grid { display: grid; gap: 1rem; align-items: start; }
@media (min-width: 900px) { .detail-grid { grid-template-columns: 1.25fr 1fr; } }
.col { min-width: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 .75rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.desc { white-space: pre-wrap; padding: .75rem; border-radius: 8px; background: var(--surface-2); }
.supplies { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.supplies li { display: flex; gap: .5rem; align-items: center; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.supplies li > div { flex: 1; }
.supplies select { width: auto; }
.thread { display: grid; gap: .5rem; max-height: 26rem; overflow-y: auto; margin-bottom: .75rem; }
.msg { max-width: 92%; padding: .55rem .8rem; border-radius: 12px; background: var(--surface-2); justify-self: start; }
.msg.mine { justify-self: end; background: var(--st-nouvelle-bg); color: var(--st-nouvelle-fg); }
.msg-h { font-size: .78rem; opacity: .85; }
.msg p { margin: .15rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: grid; gap: .5rem; }
.composer .btn { justify-self: end; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; font-size: .9rem; }

/* ---- planning */
.week-nav { display: flex; gap: .4rem; }
.week { display: grid; gap: .75rem; }
@media (min-width: 900px) { .week { grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: start; } }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.day h3 { text-transform: capitalize; margin-bottom: .4rem; font-size: .92rem; }
.day.idle { background: transparent; }
.plan-card { display: grid; gap: .3rem; padding: .55rem .6rem; margin-bottom: .5rem; border-radius: 8px; background: var(--surface-2); border-left: 4px solid var(--muted); }
.plan-card a { color: inherit; }
.plan-card .time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary); }
.plan-card.done { opacity: .6; }
.plan-card .move { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); }
.plan-card .move input { min-height: 1.9rem; padding: .2rem .4rem; font-size: .85rem; }
.bd-nouvelle { border-left-color: var(--st-nouvelle-fg); } .bd-en_cours { border-left-color: var(--st-en_cours-fg); }
.bd-attente_fourniture { border-left-color: var(--st-attente_fourniture-fg); }
.bd-attente_validation_client { border-left-color: var(--st-attente_validation_client-fg); } .bd-cloturee { border-left-color: var(--st-cloturee-fg); }
.backlog { margin-top: 1.25rem; }
.backlog-row { display: flex; gap: .75rem; justify-content: space-between; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.backlog-row a { color: inherit; flex: 1; min-width: 12rem; }
.backlog-row input { width: auto; }

/* ---- arborescence */
.tree-row { display: flex; justify-content: space-between; gap: .5rem; align-items: center; padding: .2rem .3rem; border-radius: 6px; }
.tree-row:hover { background: var(--surface-2); }
.tree-actions { display: flex; gap: .3rem; opacity: .85; }
.bulk { margin-top: 1rem; }
.bulk summary { cursor: pointer; font-weight: 600; color: var(--primary); margin-bottom: .5rem; }
.bulk textarea { margin-bottom: .5rem; font-family: ui-monospace, monospace; font-size: .88rem; }

/* ---- divers */
.alert { padding: .7rem .9rem; border-radius: 8px; }
.alert.error { background: var(--st-attente_fourniture-bg); color: var(--st-attente_fourniture-fg); }
.spinner { width: 1.6rem; height: 1.6rem; margin: 2rem auto; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 5.2rem; display: grid; gap: .4rem; z-index: 50; width: min(92vw, 26rem); }
.toast { padding: .7rem 1rem; border-radius: 10px; background: #18212b; color: #fff; box-shadow: 0 6px 20px rgb(0 0 0 / 30%); }
.toast.error { background: #b3261e; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login .form { width: min(24rem, 100%); grid-template-columns: 1fr; padding: 1.5rem; }
.login h1 { font-size: 2rem; }

/* ---- mobile : navigation en barre du bas */
@media (max-width: 760px) {
  .topbar { justify-content: space-between; }
  .topbar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: .4rem .5rem; padding-bottom: max(.4rem, env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); justify-content: space-around; flex: none;
  }
  .topbar nav a { padding: .55rem .6rem; font-size: .85rem; flex: 1; text-align: center; }
  .uname { display: none; }
  h1 { font-size: 1.3rem; }
  .item-actions { width: 100%; }
}
@media print { .topbar, .toasts, .btn { display: none; } }

/* ---- planning : regroupement par site */
.site-group { margin-bottom: .6rem; }
.site-group h4 { margin: 0 0 .25rem; padding: .25rem .5rem; font-size: .9rem; border-radius: 6px; background: var(--st-nouvelle-bg); color: var(--st-nouvelle-fg); }
.site-group h4.warn { background: var(--st-en_cours-bg); color: var(--st-en_cours-fg); }
.site-client { margin: 0 0 .3rem .5rem; font-size: .78rem; color: var(--muted); }

.checklist { display: grid; gap: .1rem; max-height: 13rem; overflow: auto; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.checklist .check { min-height: 2.1rem; }

/* ---- tournées, rapports, impression */
.visit-tag { margin: 0 0 .3rem .5rem; font-size: .8rem; color: var(--muted); }
.backlog-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.period-nav { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.period-nav input { width: auto; }
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.report-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--primary); padding-bottom: .75rem; margin-bottom: 1rem; }
.report-head h2 { font-size: 1.3rem; margin: 0; }
.report-head p { margin: .1rem 0; }
.report-client { font-size: 1.1rem; font-weight: 700; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.summary > div { padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px; }
.summary strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.report-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; margin-bottom: .5rem; }
.report-cols h3, .report-site h3 { margin: .8rem 0 .3rem; font-size: 1rem; }
ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: .15rem; }
.table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.report-table th, .report-table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.report-table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.nowrap { white-space: nowrap; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .no-print { display: none !important; }
  .report { border: 0; padding: 0; box-shadow: none; background: #fff; color: #000; }
  .report-site { break-inside: avoid-page; }
  .report-table tr { break-inside: avoid; }
  .muted { color: #444; }
}

/* ---- simplification : options repliées, action rapide */
details.more > summary, details.more-filters > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: .35rem 0; }
details.more > .form { margin-top: .6rem; padding-top: .8rem; border-top: 1px solid var(--line); }
details.more-filters { margin: -.25rem 0 .75rem; }
.plan-foot { display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.plan-foot .move { flex: 1; justify-content: flex-end; min-width: 10rem; }

/* ---- choix du local en cascade, site unique */
.loc-cascade { display: grid; gap: .4rem; }
.site-line { margin: 0; padding: .6rem .8rem; border-radius: 8px; background: var(--surface-2); }

/* ---- photos */
.row.spread { justify-content: space-between; }
.row.spread h2 { margin: 0; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: .5rem; margin-top: .6rem; }
.photo { padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: zoom-in; aspect-ratio: 1; }
.photo img, .photo-loading { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-loading { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; background: rgb(0 0 0 / 82%); }
.lightbox-body { display: grid; gap: .6rem; max-width: min(96vw, 60rem); max-height: 94vh; }
.lightbox-body img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 8px; justify-self: center; }
.lightbox-bar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; color: #fff; font-size: .9rem; }
.lightbox-bar .btn { background: #fff; color: #18212b; }
.lightbox-bar .btn.danger { color: #c62828; }

/* ---- accueils par profil */
.hello { margin-bottom: .75rem; }
.cta {
  display: flex; align-items: center; justify-content: center; gap: .6rem; width: 100%; padding: 1.1rem 1rem; margin-bottom: .5rem;
  border-radius: var(--radius); background: var(--primary); color: var(--primary-ink); font-size: 1.15rem; font-weight: 700; box-shadow: var(--shadow);
}
.cta:hover { text-decoration: none; filter: brightness(1.1); }
.cta span { font-size: 1.5rem; line-height: 1; }
.upcoming { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.upcoming li { display: flex; gap: .75rem; padding: .5rem .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.upcoming b { min-width: 6.5rem; text-transform: capitalize; }
@media (min-width: 761px) { .cta { width: auto; min-width: 20rem; } }
