/* Design sobre inspiré de Microsoft 365 / Fluent : fond clair, bleu principal, grandes zones tactiles. */
:root {
  --bg: #f5f5f5; --surface: #fff; --surface-2: #fafafa; --text: #242424; --muted: #616161; --line: #e0e0e0; --line-strong: #c7c7c7;
  --primary: #0f6cbd; --primary-hover: #115ea3; --primary-press: #0c3b5e; --primary-soft: #ebf3fc; --on-primary: #fff;
  --ok: #107c10; --ok-soft: #f1faf1; --warn: #8a5300; --warn-soft: #fff9f5; --danger: #c50f1f; --danger-soft: #fdf3f4;
  --radius: 8px; --radius-lg: 12px; --shadow: 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.06); --shadow-lg: 0 8px 24px rgba(0,0,0,.14);
  --tap: 48px; --font: "Segoe UI", "Segoe UI Web (West European)", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 var(--font); color: var(--text); background: var(--bg); min-height: 100vh; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 1.5rem 0 .75rem; }
p { margin: .5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- bandeau ---------- */
#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  height: 56px; padding: 0 16px; padding-left: max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; color: var(--text); text-decoration: none; }
.brand img { max-height: 32px; max-width: 120px; object-fit: contain; }
#page-title { font-size: 1.125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#brand-name { font-weight: 700; color: var(--primary); white-space: nowrap; padding-right: 12px; border-right: 1px solid var(--line); }
@media (max-width: 480px) { #brand-name { display: none; } }
.avatar-wrap { position: relative; }
.avatar { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); font: 600 .95rem var(--font); cursor: pointer; }
.avatar:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.menu { position: absolute; right: 0; top: 48px; min-width: 240px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px 0; z-index: 30; }
.menu .who { padding: 10px 16px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who strong { display: block; }
.menu a, .menu button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--tap); padding: 0 16px; border: 0; background: none;
  color: var(--text); font: 15px var(--font); text-decoration: none; text-align: left; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--bg); }
.menu svg { width: 20px; height: 20px; flex: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 96px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); outline: none; }
main.narrow { max-width: 720px; }

/* ---------- tuiles ---------- */
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); }
.tile { display: flex; flex-direction: column; justify-content: space-between; gap: 12px; min-height: 150px; padding: 20px; border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow); color: var(--text); text-decoration: none; border: 1px solid transparent; transition: box-shadow .15s, border-color .15s; }
.tile:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); }
.tile:active { transform: scale(.99); }
.tile .ico { width: 48px; height: 48px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.tile .ico svg { width: 28px; height: 28px; }
.tile strong { font-size: 1.2rem; font-weight: 600; }
.tile span { color: var(--muted); font-size: .9rem; }

/* ---------- cartes / formulaires ---------- */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.form { display: grid; gap: 18px; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-weight: 600; font-size: .95rem; }
.field .hint { color: var(--muted); font-size: .85rem; }
.field .error { color: var(--danger); font-size: .875rem; }
input, select, textarea { width: 100%; min-height: var(--tap); padding: 10px 12px; font: 16px var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-bottom-color: #616161; border-radius: 6px; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); }
input[readonly], input:disabled, select:disabled, textarea:disabled, textarea[readonly] { background: var(--bg); color: var(--muted); }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
.invalid { border-color: var(--danger) !important; }

/* interrupteur */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: var(--tap); cursor: pointer; font-weight: 600; }
.switch input { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; min-height: 0; border-radius: 15px; background: #8a8886; position: relative; border: 0; cursor: pointer; flex: none; }
.switch input::after { content: ''; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(22px); }
.switch input:disabled { opacity: .45; }

/* choix segmentés (radios) */
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { flex: 1 1 120px; display: flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line-strong);
  border-radius: 6px; background: var(--surface); cursor: pointer; font-weight: 600; text-align: center; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.segmented label:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- boutons ---------- */
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 20px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: 600 16px var(--font); cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--bg); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); }
button.danger, .btn.danger { color: var(--danger); border-color: var(--danger); }
button.danger.solid { background: var(--danger); color: #fff; }
button.link { border: 0; background: none; color: var(--primary); padding: 0 4px; min-height: 36px; text-decoration: underline; font-weight: 400; }
button:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
button.block, .btn.block { width: 100%; }
button svg, .btn svg { width: 20px; height: 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }
/* barre d'actions fixe en bas sur mobile (Envoyer / Annuler toujours accessibles) */
.action-bar { position: sticky; bottom: 0; z-index: 10; display: flex; gap: 12px; padding: 12px 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.action-bar > * { flex: 1; }

/* ---------- listes, tableaux → cartes sur mobile ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1 1 220px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-soft); }
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); box-shadow: var(--shadow); background: var(--surface); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions button, .row-actions .btn { min-height: 40px; padding: 0 14px; font-size: 15px; }
@media (max-width: 720px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { margin: 0 0 12px; border-radius: var(--radius-lg); box-shadow: var(--shadow); background: var(--surface); padding: 8px 4px; }
  table.responsive td { border: 0; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; font-weight: 600; }
  table.responsive td.actions-cell { justify-content: flex-end; }
  table.responsive td.actions-cell::before { content: none; }
  .table-wrap { box-shadow: none; background: none; overflow: visible; }
}

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 12px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.lock { background: #fdf6e3; color: #7a5a00; }
.type-FC { background: #ebf3fc; color: #0f6cbd; } .type-FT { background: #f1faf1; color: #107c10; } .type-PT { background: #f9f0fc; color: #8764b8; }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--primary-soft); border-left: 4px solid var(--primary); margin-bottom: 16px; }
.notice.warn { background: var(--warn-soft); border-color: #f7630c; }
.notice.danger { background: var(--danger-soft); border-color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- autocomplétion ---------- */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; max-height: 320px; overflow-y: auto; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 4px 0; margin: 0; list-style: none; }
.ac-list li { min-height: var(--tap); padding: 8px 14px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; }
.ac-list li small { color: var(--muted); }
.ac-list li[aria-selected=true], .ac-list li:hover { background: var(--primary-soft); }
.ac-list li.add { color: var(--primary); font-weight: 600; border-top: 1px solid var(--line); flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px; }
.ac-list li svg { width: 20px; height: 20px; flex: none; }
.selected-chip { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--primary-soft); }

/* ---------- connexion ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 32px 28px; }
.auth-card .logo { display: flex; justify-content: center; margin-bottom: 20px; min-height: 48px; }
.auth-card .logo img { max-height: 64px; max-width: 220px; object-fit: contain; }
.auth-card .logo .company { font-size: 1.4rem; font-weight: 600; color: var(--primary); }
.auth-card h1 { font-size: 1.3rem; text-align: center; }
.lang-switch { display: flex; justify-content: center; gap: 4px; margin-bottom: 20px; }
.lang-switch button { min-height: 36px; padding: 0 14px; font-size: 14px; }
.lang-switch button[aria-pressed=true] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr img { width: 220px; height: 220px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.code-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; text-align: center; word-break: break-all; background: var(--bg); padding: 8px; border-radius: 6px; }

/* ---------- toasts / modales ---------- */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: min(92vw, 480px);
  padding: 14px 20px; border-radius: var(--radius); background: #242424; color: #fff; box-shadow: var(--shadow-lg); font-weight: 600; }
#toast.ok { background: var(--ok); }
#toast.error { background: var(--danger); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 24px; }
.modal h2 { margin-top: 0; }

.badge svg { width: 14px; height: 14px; flex: none; }
#toast.warn { background: #8a5300; }
.wrap-anywhere { overflow-wrap: anywhere; }
table.top td { vertical-align: top; }
details > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; padding: 4px 0; }
.logo-preview { max-height: 96px; max-width: 100%; object-fit: contain; }
@media (max-width: 720px) { .row-actions button, .row-actions .btn { min-height: var(--tap); } }
/* Tableaux larges (administration) : cartes aussi sur tablette en portrait. */
@media (max-width: 1000px) {
  table.responsive.wide thead { display: none; }
  table.responsive.wide, table.responsive.wide tbody, table.responsive.wide tr, table.responsive.wide td { display: block; width: 100%; }
  table.responsive.wide tr { margin: 0 0 12px; border-radius: var(--radius-lg); box-shadow: var(--shadow); background: var(--surface); padding: 8px 4px; }
  table.responsive.wide td { border: 0; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; }
  table.responsive.wide td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; font-weight: 600; }
  table.responsive.wide td.actions-cell { justify-content: flex-end; }
  table.responsive.wide td.actions-cell::before { content: none; }
}

/* ---------- signature / photos (feuille de travail) ---------- */
.signature { position: relative; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: #fff; touch-action: none; }
.signature canvas { display: block; width: 100%; height: 220px; touch-action: none; }
.thumbs { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 4px; right: 4px; min-height: 36px; width: 36px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 0; }
.thumb.pending::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,.55); }
.thumb.error { outline: 2px solid var(--danger); }
.photo-viewer img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto; object-fit: contain; }
.sig-view { display: block; max-width: 100%; max-height: 160px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.kpi b { display: block; font-size: 1.4rem; }
.spinner { width: 20px; height: 20px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 720px) {
  main { padding: 16px 12px 96px; }
  .tile { min-height: 120px; }
  h1 { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { #topbar, .action-bar, .toolbar, button { display: none !important; } body { background: #fff; } }
