/* ============ Paysage 360 — Design tokens ============ */
:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --border: #e2e5dc;
  --text: #17201a;
  --text-2: #4d5650;
  --muted: #7d867f;
  --brand: #2f6b3a;
  --brand-2: #3f8a4c;
  --brand-soft: #e6f1e7;
  --sidebar: #16301d;
  --sidebar-text: #cfe1d2;
  /* chart tokens (validated reference palette) */
  --chart-surface: #fcfcfb;
  --series-1: #2a78d6;
  --grid: #e7e7e3;
  /* status (reserved) */
  --good: #1d7f43;  --good-bg: #e3f4e8;
  --warn: #9a6200;  --warn-bg: #fdf1d8;
  --crit: #b42318;  --crit-bg: #fde7e5;
  --info: #1c5cab;  --info-bg: #e3eefb;
  --shadow: 0 1px 2px rgba(16,24,20,.06), 0 4px 16px rgba(16,24,20,.05);
  --radius: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111412;
  --surface: #1a1d1b;
  --surface-2: #202421;
  --border: #2e332f;
  --text: #eef1ec;
  --text-2: #c3c8c1;
  --muted: #8e968f;
  --brand: #5fb070;
  --brand-2: #74c284;
  --brand-soft: #1f3324;
  --sidebar: #0c1a10;
  --sidebar-text: #b9cfbd;
  --chart-surface: #1a1a19;
  --series-1: #3987e5;
  --grid: #2c2c2a;
  --good: #5fcf8a;  --good-bg: #173322;
  --warn: #f0b64d;  --warn-bg: #3a2c10;
  --crit: #ff8a80;  --crit-bg: #3d1916;
  --info: #86b6ef;  --info-bg: #142740;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  display: grid; grid-template-columns: 240px 1fr; min-height: 100vh;
}
a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ============ Sidebar ============ */
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { padding: 20px 18px; display: flex; gap: 10px; align-items: center; color: #fff; }
.logo-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-2); display: grid; place-items: center; font-size: 20px; }
.logo b { display: block; font-size: 16px; }
.logo span { font-size: 11px; opacity: .7; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; overflow-y: auto; flex: 1; }
.nav a { color: var(--sidebar-text); text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; }
.nav .count { margin-left: auto; background: #d9534f; color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.nav-sep { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 14px 12px 4px; }
.sidebar-foot { padding: 14px 18px; font-size: 11px; opacity: .6; }

/* ============ Topbar ============ */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 12px 24px; }
.topbar h1 { font-size: 19px; }
.topbar .date { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.icon-btn { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; height: 36px; min-width: 36px; cursor: pointer; color: var(--text); font-size: 16px; }
.icon-btn .dot { position: absolute; top: -5px; right: -5px; background: #d9534f; color: #fff; border-radius: 10px; font-size: 10px; padding: 1px 6px; }
#view { padding: 22px 24px 48px; }

/* ============ Buttons / forms ============ */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--crit); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.grid-form .span2 { grid-column: span 2; }
.grid-form .full { grid-column: 1 / -1; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.check-grid label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 13px; }
.check-grid label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 0 0 12px; }
legend { font-weight: 600; font-size: 13px; padding: 0 6px; }

/* ============ Cards & layout ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-h h3 { font-size: 15px; }
.card-h .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.mt { margin-top: 16px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=search] { width: 260px; }
.toolbar select { width: auto; }

/* KPI tiles */
.kpi { padding: 14px 16px; }
.kpi .lbl { font-size: 12px; color: var(--text-2); }
.kpi .val { font-size: 24px; font-weight: 650; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--brand); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 9px 12px; font: inherit; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer; color: var(--text-2); }
.seg button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: none; }
.t tbody tr:hover { background: var(--surface-2); }
.t .link { cursor: pointer; font-weight: 600; color: var(--text); }
.t .link:hover { color: var(--brand); text-decoration: underline; }
.empty { text-align: center; padding: 28px; color: var(--muted); }

/* Badges (status: icon + label, never colour alone) */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-good { background: var(--good-bg); color: var(--good); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-crit { background: var(--crit-bg); color: var(--crit); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11.5px; margin: 1px 2px 1px 0; }

/* Alerts list */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); border-left-width: 4px; background: var(--surface); }
.alert.crit { border-left-color: var(--crit); }
.alert.warn { border-left-color: var(--warn); }
.alert.info { border-left-color: var(--info); }
.alert .ai { font-size: 16px; width: 22px; text-align: center; }
.alert .ab { flex: 1; min-width: 0; }
.alert .at { font-weight: 600; font-size: 13px; }
.alert .ad { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* Progress / meters */
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.meter.warn > span { background: var(--warn); }
.meter.crit > span { background: var(--crit); }
.hbar { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.hbar .track { height: 14px; }
.hbar .track span { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }

/* Charts */
.chart-wrap { position: relative; background: var(--chart-surface); border-radius: 8px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap .axis { fill: var(--muted); font-size: 11px; }
.chart-wrap .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-wrap .bar { fill: var(--series-1); transition: opacity .12s; }
.chart-wrap.hovering .bar { opacity: .4; }
.chart-wrap.hovering .bar.on { opacity: 1; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 7px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); display: none; z-index: 5; }
.tooltip b { display: block; font-size: 13px; }

/* Agenda list */
.agenda-day { font-size: 12px; font-weight: 600; color: var(--text-2); margin: 10px 0 4px; text-transform: capitalize; }
.agenda-item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; }
.agenda-item .time { font-variant-numeric: tabular-nums; font-weight: 600; width: 48px; }
.agenda-item .who { flex: 1; min-width: 0; }
.agenda-item .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.cal .dow { background: var(--surface-2); padding: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal .cell { min-height: 112px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; cursor: pointer; position: relative; }
.cal .cell:nth-child(7n) { border-right: none; }
.cal .cell.out { background: var(--surface-2); color: var(--muted); }
.cal .cell.today .dnum { background: var(--brand); color: #fff; border-radius: 50%; }
.cal .cell.weekend { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.cal .cell:hover { background: var(--brand-soft); }
.cal .dnum { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; }
.cal .load { position: absolute; top: 9px; right: 8px; font-size: 10px; color: var(--muted); }
.ev { display: block; font-size: 11px; padding: 2px 6px; border-radius: 5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid; cursor: pointer; }
.ev.planifiee { background: var(--info-bg); border-color: var(--info); color: var(--text); }
.ev.en_cours { background: var(--warn-bg); border-color: var(--warn); color: var(--text); }
.ev.terminee { background: var(--good-bg); border-color: var(--good); color: var(--text); }
.ev.facturee { background: var(--surface-2); border-color: var(--muted); color: var(--text-2); }
.ev.annulee { background: var(--surface-2); border-color: var(--muted); color: var(--muted); text-decoration: line-through; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week .col { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 380px; }
.week .col h4 { font-size: 12px; text-transform: capitalize; margin-bottom: 6px; display: flex; justify-content: space-between; }
.week .ev { white-space: normal; padding: 6px 8px; font-size: 12px; }

/* Contact matrix */
.matrix td, .matrix th { text-align: center; padding: 6px 4px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.mcell { width: 26px; height: 26px; border-radius: 6px; border: 1px dashed var(--border); display: inline-grid; place-items: center; cursor: pointer; font-size: 12px; background: var(--surface); color: var(--text-2); }
.mcell.on { border-style: solid; border-color: var(--info); background: var(--info-bg); color: var(--info); }
.mcell.done { border-style: solid; border-color: var(--good); background: var(--good-bg); color: var(--good); }
.mcell.cur { outline: 2px solid var(--brand); outline-offset: 1px; }

/* Kanban (URSSAF) */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-height: 200px; }
.kcol h4 { font-size: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px; margin-bottom: 8px; font-size: 12px; }
.kcard b { font-size: 13px; }

/* Timer */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; color: var(--warn); }
.timer-card { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--warn); background: var(--warn-bg); border-radius: 10px; margin-bottom: 8px; }
.timer-card .timer { font-size: 24px; }

/* Price preview */
.price-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13px; }
.price-box .row { display: flex; justify-content: space-between; padding: 3px 0; }
.price-box .row.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 7px; font-weight: 700; font-size: 15px; }
.price-box .row.sap { color: var(--good); }

/* Modal & drawer */
.overlay { position: fixed; inset: 0; background: rgba(10,20,12,.45); display: none; z-index: 50; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; width: min(860px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h2 { font-size: 17px; flex: 1; }
.modal-b { padding: 18px 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100%); background: var(--bg); box-shadow: -10px 0 40px rgba(0,0,0,.2); z-index: 40; transform: translateX(105%); transition: transform .22s ease; overflow-y: auto; }
.drawer.open { transform: none; }
.drawer-h { background: var(--surface); padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.drawer-b { padding: 16px 20px 40px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 14px; }
.timeline .ti { position: relative; padding: 4px 0 12px; }
.timeline .ti::before { content: ""; position: absolute; left: -20px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }

/* Document preview (invoice / receipt / attestation) */
.doc-preview { background: #fff; border: 1px solid var(--border); border-radius: 8px; width: 100%; height: 65vh; display: block; }

/* Toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #16301d; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }

/* Responsive */
@media (max-width: 1200px) { .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kanban { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav-sep, .sidebar-foot { display: none; }
  .g-3, .g-2, .g-21, .kanban, .week { grid-template-columns: 1fr; }
  .grid-form .span2 { grid-column: auto; }
}
@media print { .sidebar, .topbar, .toolbar { display: none; } }

/* CESU pipeline (4 étapes) & devis */
.kanban.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#qLines input[type=number] { padding: 4px 6px; }
@media (max-width: 900px) { .kanban.k4 { grid-template-columns: 1fr; } }

/* WhatsApp */
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.wa:hover { background: #178a45; }
.btn.wa-o { color: #128c4a; border-color: #9fdcb7; }
.btn.wa-o:hover { border-color: #1fa855; background: #e9f8ef; }
:root[data-theme="dark"] .btn.wa-o { color: #5fd38f; border-color: #2f6b47; }
:root[data-theme="dark"] .btn.wa-o:hover { background: #173322; }

/* Absences & imprévus */
.cal .cell.absent, .week .col.absent { background: repeating-linear-gradient(135deg, var(--warn-bg), var(--warn-bg) 6px, var(--surface) 6px, var(--surface) 12px); }
.abs-tag { display: block; margin-top: 4px; font-size: 10.5px; font-weight: 600; color: var(--warn); }
