/*
 * Fieldkit — the field stylesheet.
 *
 * Designed against three constraints that are not aesthetic:
 *
 *   1. A 10" Android tablet held in one hand, outdoors, sometimes in sun. Hence
 *      the contrast, the type size and the absence of anything grey-on-grey.
 *   2. 48 px minimum touch targets everywhere. ROADMAP §5: a routine all-BON
 *      door completes, signature included, in under 20 seconds. Every mis-tap is
 *      two taps, and at 96 doors a day a 2 % mis-tap rate is a lost quarter hour.
 *   3. No hover. Nothing in this file may only be discoverable with a pointer.
 *
 * One system font stack, no webfont: a webfont is a network request on a screen
 * that must open with no network, and it buys nothing a technician can use.
 */

:root {
  --navy: #14213d;
  --navy-soft: #22335c;
  --paper: #f7f8fa;
  --ink: #10131a;
  --ink-soft: #495062;
  --line: #d3d8e2;
  --amber: #fca311;
  --green: #1b873f;
  --red: #c02526;
  --blue: #1256a0;

  --tap: 48px;
  --pad: 12px;
  --radius: 10px;

  font-family:
    system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/*
 * ⚠️ Load-bearing, not a reset nicety. Several components below set an explicit
 * `display`, and an explicit display beats the UA stylesheet's `[hidden]` rule —
 * so `element.hidden = true` silently did nothing, and both the queue banner and
 * the « suspendre cet accès » switch stayed on screen permanently.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  /* The app is a full-screen form. Nothing scrolls at the body level; each
     screen owns its own scroll container so a sticky footer stays put. */
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.boot {
  margin: auto;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------------------
   Chrome: a header that always says where you are, and a queue banner
   -------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(env(safe-area-inset-top), 8px) var(--pad) 8px;
  background: var(--navy);
  color: #fff;
  flex: 0 0 auto;
}

.topbar__back {
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  border-radius: var(--radius);
}

.topbar__back:active {
  background: var(--navy-soft);
}

.topbar__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 18px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__sub {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
}

/*
 * The queue banner. ARCH-5 has no background drain, so this is where the
 * technician (and, through the heartbeat, the office) learns the queue is deep.
 * It is never hidden when non-zero.
 */
.queuebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--pad);
  background: #fff4dd;
  border-bottom: 1px solid var(--amber);
  font-size: 15px;
  flex: 0 0 auto;
}

.queuebar--offline {
  background: #ffe6e6;
  border-bottom-color: var(--red);
}

.queuebar__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  flex: 0 0 auto;
}

.queuebar--offline .queuebar__dot {
  background: var(--red);
}

/* --------------------------------------------------------------------------
   Screens
   -------------------------------------------------------------------------- */

.screen {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 96px;
}

.search {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 8px var(--pad);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.search input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  font-size: 17px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.search input:focus {
  outline: none;
  border-color: var(--blue);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px var(--pad);
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  font: inherit;
  color: inherit;
}

.row:active {
  background: #eaeef6;
}

.row__main {
  flex: 1 1 auto;
  min-width: 0;
}

/* Both are spans, so both need an explicit block: the door number and its
   location ran together as « 79M013Entrée principale » otherwise. */
.row__title {
  display: block;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.row__meta {
  display: block;
  font-size: 14px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.badge--todo {
  background: #e7edf7;
  color: var(--blue);
}

.badge--done {
  background: #e2f3e7;
  color: var(--green);
}

.badge--pending {
  background: #fff0d4;
  color: #8a5a00;
}

.badge--old {
  background: #eef0f4;
  color: var(--ink-soft);
}

.empty {
  padding: 32px var(--pad);
  text-align: center;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------------------
   The sticky action bar — « accès suivant à faire », Valider
   -------------------------------------------------------------------------- */

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 8px var(--pad) max(env(safe-area-inset-bottom), 8px);
  background: rgba(247, 248, 250, 0.97);
  border-top: 1px solid var(--line);
  z-index: 10;
}

.btn {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 0 16px;
  border: 2px solid var(--navy);
  border-radius: var(--radius);
  background: #fff;
  color: var(--navy);
  font: inherit;
  font-weight: 650;
}

.btn:active {
  background: #e6eaf3;
}

.btn--primary {
  background: var(--navy);
  color: #fff;
}

.btn--primary:active {
  background: var(--navy-soft);
}

.btn--wide {
  flex: 2 1 auto;
}

.btn:disabled {
  opacity: 0.45;
}

/* --------------------------------------------------------------------------
   The bilan header — pre-filled, NOT editable
   -------------------------------------------------------------------------- */

.header-card {
  margin: var(--pad);
  padding: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.header-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 15px;
}

.header-card dt {
  color: var(--ink-soft);
}

.header-card dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/*
 * The visit number. ROADMAP §5: "system-issued visit number, minted offline at
 * form-open — never displayed as a placeholder". It is rendered like the
 * pre-printed red number on the paper carnet because that is what it replaces.
 */
.visit-number {
  font-size: 20px;
  font-weight: 750;
  color: var(--red);
  letter-spacing: 0.5px;
}

/* --------------------------------------------------------------------------
   The grid
   -------------------------------------------------------------------------- */

.section {
  margin: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.section__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--pad);
  background: #eef1f7;
  border-bottom: 1px solid var(--line);
}

.section__title {
  flex: 1 1 auto;
  font-weight: 680;
  font-size: 16px;
}

.section__state {
  font-size: 13px;
  color: var(--ink-soft);
}

.section__toggle {
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: transparent;
  font-size: 20px;
  color: var(--navy);
}

/*
 * One-tap « tout BON ». ROADMAP §8a marks it NEVER CUT: at 36 rows the naïve
 * grid is 40 taps a door before the off-grid items, and this is the difference
 * between a tool that is adopted and one that is abandoned after the training.
 */
.section__fill {
  min-height: var(--tap);
  padding: 0 14px;
  border: 2px solid var(--green);
  border-radius: var(--radius);
  background: #fff;
  color: var(--green);
  font: inherit;
  font-weight: 700;
}

.section__fill:active {
  background: #e2f3e7;
}

.section--filled .section__fill {
  background: var(--green);
  color: #fff;
}

.section__rows {
  display: block;
}

.section--collapsed .section__rows {
  display: none;
}

.grid-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--pad);
  border-bottom: 1px solid #eceff5;
}

.grid-row:last-child {
  border-bottom: 0;
}

.grid-row__label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
}

/* A row filled by the section default, not touched individually. The
   distinction is an acceptance criterion: « état visible (rempli en masse /
   coché à la main) ». */
.grid-row--bulk .grid-row__label {
  color: var(--ink-soft);
}

.grid-row--bulk .grid-row__label::after {
  content: " ·";
  color: var(--green);
  font-weight: 700;
}

.choices {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.choice {
  min-width: 52px;
  min-height: var(--tap);
  padding: 0 8px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-soft);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
}

.choice[aria-pressed="true"] {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

.choice--bon[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--green);
}

.choice--hs[aria-pressed="true"] {
  border-color: var(--red);
  background: var(--red);
}

.choice--so[aria-pressed="true"] {
  border-color: var(--ink-soft);
  background: var(--ink-soft);
}

.qty {
  width: 56px;
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  font: inherit;
}

/* --------------------------------------------------------------------------
   Switches, free text, signature
   -------------------------------------------------------------------------- */

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px var(--pad);
  border: 0;
  border-bottom: 1px solid #eceff5;
  background: #fff;
  font: inherit;
  text-align: left;
}

.switch__label {
  flex: 1 1 auto;
}

.switch__box {
  flex: 0 0 auto;
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background 0.12s;
}

.switch__box::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.12s;
}

.switch[aria-pressed="true"] .switch__box {
  background: var(--green);
}

.switch[aria-pressed="true"] .switch__box::after {
  transform: translateX(24px);
}

.field {
  padding: var(--pad);
  background: #fff;
  border-bottom: 1px solid #eceff5;
}

.field label {
  display: block;
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.field textarea,
.field input {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  font: inherit;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.sig {
  margin: var(--pad);
}

.sig canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
}

.sig__hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--ink-soft);
  padding-top: 8px;
}

/* « Effacer » is a corrective action, not the primary one — it does not get to
   be the widest control on the signature screen. */
.sig__hint .btn {
  flex: 0 0 auto;
  min-width: 120px;
}

/*
 * The read-back line. ROADMAP §7.3: the one error class the form cannot design
 * away is a perfectly valid bilan filled on the WRONG DOOR, so the door is
 * restated, in full, immediately above the signature.
 */
.readback {
  margin: var(--pad);
  padding: var(--pad);
  border: 2px solid var(--navy);
  border-radius: var(--radius);
  background: #fff;
  font-size: 16px;
}

.readback__lead {
  display: block;
}

/*
 * 🔴 The size here is an acceptance criterion, not a taste: « le n° de porte +
 * son libellé sont lisibles à bout de bras avant signature ». The tablet is
 * being held out towards a client at the moment this is read, and at that
 * distance the door number has to be the largest thing on the screen — bigger
 * than the section titles, bigger than the visit number in the header.
 * scripts/offline-acceptance.ts measures the computed value.
 */
.readback__door {
  display: block;
  font-size: 32px;
  line-height: 1.15;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

.readback__where {
  display: block;
  font-size: 20px;
  font-weight: 600;
}

/* Block E' — what a correction does NOT change. */
.readback__note {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line, #d8dce4);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  z-index: 40;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.toast--error {
  background: var(--red);
}
