/* Lean Observer PWA — thème sombre terrain + système de relief (skill relief-ui).
   Seul ce qui se manipule a du volume ; ce qui se lit reste plat ; les champs sont creusés. */
:root {
  --bg: #0d1420;
  --panel: #152034;
  --panel-2: #1b2940;
  --line: #2a3a55;
  --text: #e8eef8;
  --muted: #9aa8bf;
  --signal: #2f7df5;          /* bleu chrono */
  --signal-edge: #163f80;
  --signal-ink: #9cc2ff;
  --va: #22c76f;
  --nva: #f23838;
  --bnva: #ffa614;
  --danger: #c93030;
  --danger-edge: #6a1414;

  /* Jetons de relief */
  --edge: #070b12;
  --face: linear-gradient(180deg, #2b3c5a 0%, #22314b 100%);
  --face-hover: linear-gradient(180deg, #334767 0%, #283a57 100%);
  --sunk: #111a2a;
  --rest: 0 6px 12px -6px rgba(0, 0, 0, .7);
  --lift: 0 12px 18px -8px rgba(0, 0, 0, .8);
  --hi: inset 0 1px 0 rgba(255, 255, 255, .10);
  --ease: cubic-bezier(.22, .61, .36, 1);
  --press-time: 60ms;
  --r: 6px;

  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
a { color: var(--signal-ink); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: .75rem;
  padding: .7rem 1rem; background: rgba(13, 20, 32, .92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 -1px 0 var(--line);
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--text); text-decoration: none; }
.crumb { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app { max-width: 920px; margin: 0 auto; padding: 1rem 1rem 6rem; outline: none; }

/* ---------- Commandes en relief ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem;
  border: 0; border-radius: var(--r);
  background: var(--face); color: var(--text); font-weight: 600; text-decoration: none;
  box-shadow: var(--hi), 0 3px 0 var(--edge), var(--rest);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
  cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { background: var(--face-hover); transform: translateY(-2px); box-shadow: var(--hi), 0 5px 0 var(--edge), var(--lift); }
  .btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #4a90ff, #2f7df5); box-shadow: var(--hi), 0 5px 0 var(--signal-edge), var(--lift); }
  .btn.danger:hover:not(:disabled) { background: linear-gradient(180deg, #e04646, #c93030); box-shadow: var(--hi), 0 5px 0 var(--danger-edge), var(--lift); }
}
.btn:active:not(:disabled) {
  background: var(--sunk); transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), 0 1px 0 var(--edge);
  transition-duration: var(--press-time);
}
.btn.primary { background: linear-gradient(180deg, #3d88ff, #2a6fe0); box-shadow: var(--hi), 0 3px 0 var(--signal-edge), var(--rest); }
.btn.primary:active:not(:disabled) { background: #1f56b3; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .5), 0 1px 0 var(--signal-edge); }
.btn.danger { background: linear-gradient(180deg, #d23c3c, #b72a2a); box-shadow: var(--hi), 0 3px 0 var(--danger-edge), var(--rest); }
.btn.danger:active:not(:disabled) { background: #8f1f1f; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .5), 0 1px 0 var(--danger-edge); }
.btn.small { min-height: 40px; padding: .35rem .7rem; font-size: .9rem; }
.btn.icon { min-width: 44px; padding: .35rem; }
.btn:disabled { background: var(--panel); color: #66748c; box-shadow: none; cursor: not-allowed; }
.btn:focus-visible, .tile:focus-visible, .tab:focus-visible, summary:focus-visible { outline: 3px solid var(--signal-ink); outline-offset: 3px; }
.btn[aria-pressed="true"] {
  background: var(--sunk); transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), inset 0 -2px 0 var(--signal), 0 1px 0 var(--edge);
}

.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: .9rem; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- Cartes / plaques cliquables ---------- */
.card {
  background: var(--panel); border-radius: 8px; padding: 1rem;
  box-shadow: 0 2px 0 var(--edge), var(--rest);
}
.tile {
  display: block; width: 100%; text-align: left;
  background: var(--face); color: var(--text); text-decoration: none;
  border: 0; border-radius: 8px; padding: .9rem 1rem;
  box-shadow: var(--hi), 0 3px 0 var(--edge), var(--rest);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
  touch-action: manipulation; -webkit-touch-callout: none;
}
@media (hover: hover) and (pointer: fine) {
  .tile:hover { background: var(--face-hover); transform: translateY(-2px); box-shadow: var(--hi), 0 5px 0 var(--edge), var(--lift); }
}
.tile:active { background: var(--sunk); transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), 0 1px 0 var(--edge); transition-duration: var(--press-time); }
.tile .t { font-weight: 700; display: block; }
.tile .s { color: var(--muted); font-size: .88rem; display: block; margin-top: .15rem; }
.list { display: grid; gap: .7rem; }

/* ---------- Chips plates ---------- */
.chip { display: inline-block; padding: .1rem .5rem; border-radius: 4px; font-size: .78rem; font-weight: 700; letter-spacing: .03em; background: #24324a; color: var(--muted); }
.chip.VA { background: rgba(34, 199, 111, .16); color: #6fe6a6; }
.chip.NVA { background: rgba(242, 56, 56, .16); color: #ff8a8a; }
.chip.BNVA { background: rgba(255, 166, 20, .16); color: #ffc766; }
.chip.manual { background: rgba(156, 194, 255, .14); color: var(--signal-ink); }

/* ---------- Onglets en languettes ---------- */
.tabs { display: flex; gap: .3rem; box-shadow: inset 0 -2px 0 var(--line); margin: .5rem 0 1rem; }
.tab {
  margin-top: 5px; min-height: 42px; padding: .5rem 1rem; border: 0; border-radius: 8px 8px 0 0;
  background: #1a2539; color: var(--muted); font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center;
  box-shadow: var(--hi), inset 0 -2px 0 var(--line);
}
.tab[aria-selected="true"] {
  margin-top: 0; background: var(--bg); color: var(--text);
  box-shadow: inset 0 3px 0 var(--signal), inset 1px 0 0 var(--line), inset -1px 0 0 var(--line);
}

/* ---------- Champs creusés ---------- */
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; font-size: 16px;
  border: 0; border-radius: var(--r); background: var(--sunk); color: var(--text);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .55), inset 0 0 0 1px var(--line);
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--signal-ink); outline-offset: 1px; }
.form-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
input.cell { min-height: 38px; padding: .3rem .4rem; width: 6.2rem; text-align: right; }

/* ---------- Repli <details> avec pastille ---------- */
details.fold { background: var(--panel); border-radius: 8px; box-shadow: 0 2px 0 var(--edge), var(--rest); }
details.fold > summary {
  list-style: none; display: flex; align-items: center; gap: .7rem; padding: .8rem 1rem; cursor: pointer;
}
details.fold > summary::-webkit-details-marker { display: none; }
.pill {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--face); box-shadow: var(--hi), 0 2px 0 var(--edge), var(--rest);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}
.pill::after {
  content: ""; width: 8px; height: 8px; margin-left: -3px;
  border-right: 2px solid var(--signal-ink); border-bottom: 2px solid var(--signal-ink);
  transform: rotate(-45deg); transition: transform 200ms var(--ease);
}
details.fold[open] > summary .pill::after { transform: rotate(45deg); margin: -4px 0 0; border-color: var(--muted); }
details.fold > summary:active .pill { transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), 0 0 0 var(--edge); }
details.fold > .body { padding: 0 1rem 1rem; }

/* ---------- Tableaux plats ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .45rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td.r, th.r { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 800; border-top: 2px solid var(--line); border-bottom: 0; }

/* ---------- Écran d'observation ---------- */
.obs { display: grid; gap: .9rem; }
.obs-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.obs-task { background: var(--panel); border-radius: 8px; padding: .9rem 1rem; box-shadow: 0 2px 0 var(--edge); }
.obs-task .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.obs-task .name { font-size: 1.35rem; font-weight: 800; margin: .2rem 0; }
.obs-task .next { color: var(--muted); font-size: .9rem; }
.clock { text-align: center; }
.clock .big { font-size: clamp(3rem, 17vw, 5.5rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; }
.clock .sub { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: .3rem; }
.clock.paused .big { color: var(--bnva); }
progress { width: 100%; height: 10px; -webkit-appearance: none; appearance: none; border: 0; border-radius: 5px; background: var(--sunk); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--sunk); border-radius: 5px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); }
progress::-webkit-progress-value { background: var(--signal); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--signal); }

.top-btn {
  display: block; width: 100%; min-height: 34vh; border: 0; border-radius: 14px;
  background: linear-gradient(180deg, #3d88ff, #2a6fe0); color: #fff;
  font-size: clamp(1.8rem, 9vw, 2.8rem); font-weight: 900; letter-spacing: .04em;
  box-shadow: var(--hi), 0 6px 0 var(--signal-edge), 0 18px 28px -10px rgba(0, 0, 0, .85);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
  cursor: pointer;
}
.top-btn small { display: block; font-size: .95rem; font-weight: 600; letter-spacing: 0; opacity: .85; margin-top: .4rem; }
.top-btn.pressed, .top-btn:active { transform: translateY(5px); background: #1f56b3; box-shadow: inset 0 3px 6px rgba(0, 0, 0, .45), 0 1px 0 var(--signal-edge); transition-duration: var(--press-time); }
.top-btn:disabled { background: var(--panel-2); color: var(--muted); box-shadow: none; transform: none; }
.top-btn:focus-visible { outline: 3px solid var(--signal-ink); outline-offset: 4px; }

.rating { display: flex; align-items: center; justify-content: center; gap: .6rem; }
.rating .val { min-width: 5.5rem; text-align: center; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.laps { display: grid; gap: .35rem; max-height: 30vh; overflow-y: auto; }
.lap { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .2rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.obs-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }

/* ---------- Barre de répartition VA/NVA/BNVA ---------- */
.split { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: var(--sunk); }
.split > span { display: block; height: 100%; }
.split .VA { background: var(--va); }
.split .NVA { background: var(--nva); }
.split .BNVA { background: var(--bnva); }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .85rem; color: var(--muted); margin-top: .4rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.kpi { background: var(--panel); border-radius: 8px; padding: .8rem 1rem; box-shadow: 0 2px 0 var(--edge); }
.kpi .v { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .82rem; }

/* ---------- Dialogue ---------- */
.dlg {
  width: min(560px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto;
  border: 0; border-radius: 10px; padding: 1.1rem; background: var(--panel-2); color: var(--text);
  box-shadow: 0 3px 0 var(--edge), 0 30px 60px -10px rgba(0, 0, 0, .9);
}
.dlg::backdrop { background: rgba(3, 6, 12, .7); }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(3.4rem + env(safe-area-inset-top)); transform: translateX(-50%) translateY(-8px);
  max-width: calc(100vw - 2rem); padding: .6rem 1rem; border-radius: 8px; background: #23324c; color: var(--text);
  box-shadow: 0 3px 0 var(--edge), var(--lift); transition: transform 220ms var(--ease), opacity 220ms var(--ease);
  z-index: 20; pointer-events: none; opacity: 0; visibility: hidden;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.banner { background: rgba(255, 166, 20, .12); color: #ffd28a; border-radius: 8px; padding: .7rem 1rem; }

@media (max-width: 520px) {
  .app { padding: .8rem .8rem 6rem; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .btn:hover, .btn:active, .tile:hover, .tile:active, .top-btn:active, .top-btn.pressed { transform: none !important; }
}
@media print {
  .topbar, .btn, .tabs, .top-btn, .toast { display: none !important; }
  .card, .kpi, details.fold, .tile { box-shadow: none !important; }
  body, html { background: #fff; color: #000; }
}

/* Code de jumelage affiché sur l'ordinateur */
.pair-code { font-size: 2.4rem; letter-spacing: .3em; font-family: ui-monospace, "SF Mono", Menlo, monospace; margin: .3rem 0; }
