/* Socle visuel commun aux apps du hub pro : sobre, lisible, dense sur ordinateur, confortable sur téléphone. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --ink: #17202e;
  --muted: #5d6878;
  --line: #e1e5eb;
  --brand: #2453c7;
  --brand-soft: #e7eefc;
  --brand-ink: #ffffff;
  --good: #137a4b;
  --good-soft: #e2f4ea;
  --bad: #c43a3a;
  --bad-soft: #fbe7e7;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1e2734; --ink: #e6eaf0; --muted: #9aa5b5; --line: #2a3443;
    --brand: #6f9bff; --brand-soft: #1c2a47; --brand-ink: #0b1220;
    --good: #4cc38a; --good-soft: #15302a; --bad: #f07070; --bad-soft: #3a1d22; --warn: #f0b252; --warn-soft: #3a2c14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--brand); }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; }
.narrow { max-width: 420px; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .home { font-size: 1.3rem; text-decoration: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.topbar .home:hover { background: var(--surface-2); }
.topbar .app-title { font-weight: 650; display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .org-name, .topbar .org-switch { color: var(--muted); font-size: .9rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .org-switch { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s); padding: 6px 8px; }
.topbar .me {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; text-decoration: none;
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Blocs */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; flex: 1; min-width: 200px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty h1, .empty h2 { color: var(--ink); }

/* Chiffres clés */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .value.good { color: var(--good); } .stat .value.bad { color: var(--bad); }

/* Badges */
.badge { display: inline-block; font-size: .74rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.green { background: var(--good-soft); color: var(--good); }
.badge.red { background: var(--bad-soft); color: var(--bad); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }

/* Listes */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main .t { font-weight: 600; }
.list .main .s { color: var(--muted); font-size: .86rem; }
.row-link { text-decoration: none; color: inherit; }
.row-link:hover .t { color: var(--brand); }

/* Tableaux (cartes empilées sur téléphone) */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }
table.data tfoot td { font-weight: 700; border-bottom: 0; }
@media (max-width: 640px) {
  table.data.stack thead { display: none; }
  table.data.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
  table.data.stack td { border: 0; padding: 0; }
  table.data.stack td[data-k]::before { content: attr(data-k) " · "; color: var(--muted); font-size: .8rem; }
  table.data.stack td.main-cell { grid-column: 1 / -1; font-weight: 600; }
}

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

/* Filtres */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { min-height: 38px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); }

/* Formulaires */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); min-height: 40px;
}
.filters input, .filters select { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .86rem; font-weight: 600; }
.field small { color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 600; font-size: .92rem; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 10px 0 0; font-size: .92rem; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* Dialogue */
dialog.dlg { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog.dlg::backdrop { background: rgba(15, 20, 27, .45); }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }

/* Cases à cocher (tâches) */
.check-btn { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; flex: none; padding: 0; color: #fff; font-size: .8rem; }
.check-btn.on { background: var(--good); border-color: var(--good); }
.done .t { text-decoration: line-through; color: var(--muted); }

/* Barre de progression */
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.good > span { background: var(--good); }

/* Notifications */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-s); box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 600; transition: opacity .3s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print {
  .topbar, .btn, .tabs, .filters, .no-print { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; border: 0; padding: 0; }
}

/* Correctifs de mise en page */
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; margin: 0; accent-color: var(--brand); vertical-align: -2px; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }
.grid > .card + .card { margin-top: 0; }
@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .org-name { display: none; }
  .topbar .org-switch { max-width: 34vw; }
}
table.data th.num { text-align: right; }
