/* Layout : app métier — barre latérale de navigation + espace de travail ; bandeau d'onglets en haut sur téléphone */
:root {
  --bg: #f6f5ef;
  --surface: #ffffff;
  --surface-2: #faf9f3;
  --ink: #2f312a;
  --muted: #6c6e61;
  --line: #e3e1d4;
  --primary: #ffcb00;
  --primary-dark: #eab500;
  --primary-ink: #3d3f34;
  --tint: #fff8dc;
  --link: #6f850b;
  --ok: #2e8b4f;
  --ok-bg: #e6f4ea;
  --warn: #b86e00;
  --warn-bg: #fdf0d9;
  --bad: #c9322a;
  --bad-bg: #fbe6e4;
  --m-prep: #5b72c9;
  --m-macon: #b8613a;
  --m-abri: #3a9364;
  --m-portail: #8656bd;
  --m-cloture: #d19c00;
  --shadow: 0 1px 2px rgba(47,49,42,.06), 0 6px 24px rgba(47,49,42,.08);
  --font-display: "Bitter", Georgia, serif;
  --font-body: "Lato", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1b16; --surface: #23241e; --surface-2: #1f201a; --ink: #ecebe1; --muted: #a5a695;
    --line: #373830; --primary: #ffcb00; --primary-dark: #ffd633; --primary-ink: #2a2b23; --tint: #3a3418;
    --link: #bcd43d; --ok: #5cc17c; --ok-bg: #1f3526; --warn: #f0b340; --warn-bg: #3a2e14;
    --bad: #ff6e64; --bad-bg: #3d1f1d; --m-prep: #8499eb; --m-macon: #e0845a; --m-abri: #5cc08a;
    --m-portail: #b28ae6; --m-cloture: #f2c230; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1b16; --surface: #23241e; --surface-2: #1f201a; --ink: #ecebe1; --muted: #a5a695;
  --line: #373830; --primary: #ffcb00; --primary-dark: #ffd633; --primary-ink: #2a2b23; --tint: #3a3418;
  --link: #bcd43d; --ok: #5cc17c; --ok-bg: #1f3526; --warn: #f0b340; --warn-bg: #3a2e14;
  --bad: #ff6e64; --bad-bg: #3d1f1d; --m-prep: #8499eb; --m-macon: #e0845a; --m-abri: #5cc08a;
  --m-portail: #b28ae6; --m-cloture: #f2c230; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.2; }
.num { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 700; }
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--tint); color: var(--ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 12px; background: var(--primary); color: var(--primary-ink); border-radius: 99px; padding: 0 7px; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 6px; }

.main { padding: 24px 28px 48px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.demo { display: flex; gap: 10px; align-items: center; background: var(--tint); border: 1px dashed var(--primary-dark); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.demo strong { font-weight: 700; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.head h1 { font-size: 26px; }
.head p { margin: 4px 0 0; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 16px; }
.card-b { padding: 14px 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi-l { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.kpi-v { font-family: var(--font-display); font-size: 26px; font-weight: 700; }
.kpi-s { font-size: 13px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.pill.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.pill.bad { background: var(--bad-bg); border-color: transparent; color: var(--bad); }
.pill.info { background: var(--tint); border-color: transparent; color: var(--ink); }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.alerts li:last-child { border-bottom: 0; }
.alerts .stripe { align-self: stretch; border-radius: 4px; background: var(--warn); }
.alerts .stripe.bad { background: var(--bad); }
.alerts .t { font-weight: 700; }
.alerts .d { font-size: 13px; color: var(--muted); }
.empty { padding: 20px 16px; color: var(--muted); font-size: 14px; }

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 70px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; display: flex; }
.bar-track span { display: block; height: 100%; }
.bar-row .r { text-align: right; color: var(--muted); }

/* Tableaux */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { flex: 1 1 220px; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px; font-size: 13px; font-weight: 700; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.client-n { font-weight: 700; }
.client-a { font-size: 12px; color: var(--muted); }
td.right, th.right { text-align: right; }
.mini-metiers { display: flex; height: 8px; width: 90px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.mini-metiers span { display: block; height: 100%; }

/* Tiroir fiche */
.scrim { position: fixed; inset: 0; background: rgba(20,20,15,.35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 21; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.drawer-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: calc(18px + env(safe-area-inset-top, 0px)) 20px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-h h2 { font-size: 21px; }
.drawer-h p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.drawer-b { overflow-y: auto; padding: 18px 20px calc(28px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.fact { background: var(--surface); padding: 10px 12px; min-width: 0; }
.fact .l { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.fact .v { font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.section-t { font-family: var(--font-display); font-size: 15px; margin: 0 0 8px; }
.cmd-list { display: flex; flex-direction: column; gap: 8px; }
.cmd { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.cmd .p { font-weight: 700; }
.cmd .f { font-size: 12px; color: var(--muted); }
.cmd select { border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
.add-line { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 8px; }
.add-line select, .add-line input { min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 8px; font-size: 13px; }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input, .field select { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%; }
.jours { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.calc { font-size: 13px; color: var(--muted); }

/* Kanban */
.kanban-wrap { overflow-x: auto; padding-bottom: 6px; }
.kanban { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-height: 200px; }
.col.over { border-color: var(--primary-dark); background: var(--tint); }
.col-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--line); }
.col-h .n { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; font-size: 12px; }
.col-b { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; cursor: grab; }
.kcard.dragging { opacity: .45; }
.kcard .p { font-weight: 700; font-size: 14px; }
.kcard .f { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kcard .c { font-size: 13px; }
.kcard .foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.kcard .late { color: var(--bad); font-weight: 700; font-size: 12px; }

/* Plan de charge */
.months { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.month { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.month-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.month-h h2 { font-size: 18px; }
.gauge { height: 16px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; display: flex; position: relative; }
.gauge span { height: 100%; }
.gauge-legend { display: flex; justify-content: space-between; font-size: 13px; }
.gauge-legend strong { font-family: var(--font-display); font-size: 20px; }
.metier-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.metier-list div { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.metier-list b { font-size: 14px; color: var(--ink); }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.capa { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stepper button { border: 0; background: var(--surface-2); width: 28px; height: 28px; font-weight: 700; }
.stepper span { min-width: 30px; text-align: center; font-weight: 700; color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }

/* Planning */
.plan { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.pool { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pool h2 { font-size: 15px; }
.pool p { margin: 0; font-size: 13px; color: var(--muted); }
.pchip { border: 1px solid var(--line); border-left: 6px solid var(--c); background: var(--surface); border-radius: 8px; padding: 8px 10px; text-align: left; display: flex; flex-direction: column; gap: 2px; cursor: grab; width: 100%; }
.pchip[aria-pressed="true"] { outline: 3px solid var(--primary); }
.pchip .n { font-weight: 700; font-size: 14px; }
.pchip .r { font-size: 12px; color: var(--muted); }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-nav h2 { font-size: 16px; min-width: 190px; text-align: center; }
.sched-wrap { overflow-x: auto; }
.sched { display: grid; grid-template-columns: 110px repeat(10, minmax(66px, 1fr)); min-width: 780px; }
.sched .hd { font-size: 12px; font-weight: 700; color: var(--muted); padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.sched .day { grid-column: span 2; font-size: 13px; color: var(--ink); border-left: 1px solid var(--line); }
.sched .day.today { background: var(--tint); }
.sched .who { font-weight: 700; font-size: 14px; padding: 6px 8px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.slot { border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); min-height: 52px; padding: 3px; }
.slot.pm { border-left-style: dashed; }
.slot.over { background: var(--tint); }
.slot.armed { cursor: copy; }
.slot.armed:hover { background: var(--tint); }
.booked { height: 100%; min-height: 44px; border-radius: 6px; background: var(--c); color: #fff; font-size: 12px; font-weight: 700; padding: 4px 6px; display: flex; justify-content: space-between; gap: 4px; line-height: 1.2; }
.booked button { border: 0; background: rgba(0,0,0,.18); color: #fff; border-radius: 4px; width: 18px; height: 18px; line-height: 1; font-size: 12px; flex: none; }
.hint { font-size: 13px; color: var(--muted); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .months { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: env(safe-area-inset-top, 0px); height: auto; z-index: 10; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand-name, .brand-sub, .side-foot { display: none; }
  .nav { flex-direction: row; }
  .nav button { white-space: nowrap; padding: 8px 10px; }
  .main { padding: 18px 16px 40px; }
  .plan { grid-template-columns: minmax(0, 1fr); }
  .pool { flex-direction: row; flex-wrap: wrap; }
  .pool > h2, .pool > p { flex-basis: 100%; }
  .pchip { width: auto; flex: 1 1 150px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .months { grid-template-columns: minmax(0, 1fr); }
  .kpi-v { font-size: 22px; }
  .form { grid-template-columns: minmax(0, 1fr); }
  .jours { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .add-line { grid-template-columns: minmax(0, 1fr); }
  .nav svg { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide .18s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* --- Compléments application --- */
a { color: var(--link); }
a.btn, a.chip, .nav a { text-decoration: none; color: inherit; }
.nav a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 700; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--tint); color: var(--ink); }
.nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.side-foot form { margin-top: 6px; }
.side-foot button { border: 0; background: none; padding: 0; color: var(--link); font-weight: 700; font-size: 12px; }
.brand { text-decoration: none; color: inherit; }
.flash { border-radius: 10px; padding: 10px 14px; font-weight: 700; font-size: 14px; }
.flash.notice { background: var(--ok-bg); color: var(--ok); }
.flash.alert { background: var(--bad-bg); color: var(--bad); }
.inline { display: inline; }
.btn-danger { color: var(--bad); }
.row-link { color: inherit; text-decoration: none; display: block; }
.page { display: flex; flex-direction: column; gap: 16px; max-width: 880px; }
.page-wide { max-width: none; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.errors ul { margin: 4px 0 0; padding-left: 18px; }
.field textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-height: 80px; width: 100%; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.fieldset-t { grid-column: 1 / -1; font-family: var(--font-display); font-size: 15px; margin: 8px 0 0; }
.cmd .actions { display: flex; gap: 6px; align-items: center; }
.cmd form { margin: 0; }
.btn-icon { border: 0; background: none; color: var(--muted); padding: 2px 6px; font-size: 16px; line-height: 1; }
.btn-icon:hover { color: var(--bad); }
.slot form, .booked form { margin: 0; }
.booked { color: #fff; }
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(400px, 100%); padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.settings ul { list-style: none; margin: 0; padding: 0; }
.settings li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.settings li.off { color: var(--muted); }
.settings form.add { display: flex; gap: 8px; padding: 12px 16px; }
.settings form.add input[type="text"] { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.month-nav { display: flex; gap: 8px; align-items: center; }
@media (max-width: 820px) {
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .nav-sep { display: none; }
  .settings, .result-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) { .nav a svg { display: none; } }

/* Rentabilité */
.margins { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; border-bottom: 1px solid var(--line); }
.margins .kpi { padding: 0; }
.calc-table td { cursor: default; }
.calc-table tr:hover { background: none; }
.calc-table tr.sub td { font-weight: 700; background: var(--surface-2); }
@media (max-width: 560px) { .margins { grid-template-columns: minmax(0, 1fr); } }
td.num, td.right { white-space: nowrap; }
.profit-form { grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.profit-form .label { font-size: 12px; font-weight: 700; color: var(--muted); }
.profit-form .static { padding: 8px 0; }
.profit-form .profit-hint { margin: 0; grid-column: 1 / -1; }
@media (max-width: 820px) { .profit-form { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .profit-form { grid-template-columns: minmax(0, 1fr); } }
