/* ACS fiche de visite: phone-first styles.
   Sizes favour legibility on site (gloves, sunlight): 17px base text, 52px inputs,
   and 16px+ input font so iOS doesn't zoom on focus. */

:root {
  --brand: #374a99;        /* ACS logo blue */
  --brand-dark: #24316e;
  --brand-soft: #e8ecf8;
  --bg: #f2f4f9;
  --surface: #ffffff;
  --text: #1b2033;
  --muted: #5d6478;
  --line: #d9deea;
  --ok: #1f7a4d;
  --ok-soft: #e3f4ea;
  --warn-bg: #fdeeee;      /* soft red for unusual readings: a hint, not an error */
  --warn-line: #e3a3a3;
  --warn-text: #a33a3a;
  --radius: 14px;
  --tabbar-h: 66px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  min-height: 60px; padding: 8px 12px;
  background: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(20, 30, 70, .18);
}
.appbar .logo { height: 34px; background: #fff; border-radius: 8px; padding: 4px 8px; }
.appbar .titles { flex: 1; min-width: 0; }
.appbar h1 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.2; }
.appbar .sub { font-size: 14px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: inherit;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.icon-btn svg { width: 26px; height: 26px; }
.save-state { font-size: 13px; opacity: .9; white-space: nowrap; }
.save-state.error { color: #ffd2d2; font-weight: 600; }

/* ---------- Layout ---------- */
main { padding: 14px 12px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); max-width: 720px; margin: 0 auto; }
.home main { padding-bottom: 40px; }

.section-title {
  margin: 22px 4px 10px; font-size: 14px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.section-title:first-child { margin-top: 6px; }

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(20, 30, 70, .06), 0 0 0 1px var(--line);
}
.card h2 { margin: 0 0 12px; font-size: 18px; color: var(--brand-dark); }
.card h2 .hint { font-weight: 400; font-size: 14px; color: var(--muted); }

/* ---------- Home lists ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; border: 0; background: var(--surface);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  box-shadow: 0 0 0 1px var(--line);
}
.list-item:active { background: var(--brand-soft); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .name { font-weight: 700; font-size: 17px; }
.list-item .meta { color: var(--muted); font-size: 15px; }
.list-item .chev { color: var(--muted); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge.todo { background: var(--brand-soft); color: var(--brand); }
.badge.draft { background: #fff3d6; color: #8a5a00; }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.empty { color: var(--muted); padding: 8px 4px 16px; }
.link-btn { border: 0; background: none; color: var(--brand); padding: 10px 4px; font-weight: 600; }
.home-footer { display: flex; justify-content: space-between; margin-top: 24px; }

/* ---------- Form fields ---------- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field > .label {
  display: block; margin-bottom: 6px; font-size: 15px; font-weight: 600; color: var(--muted);
}
.input, select.input, textarea.input {
  display: block; width: 100%; min-height: 52px;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; font-size: 18px;
  transition: border-color .15s, background-color .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(55, 74, 153, .15); }
.input[readonly], .input:disabled { background: #f6f7fb; color: var(--muted); }
textarea.input { min-height: 180px; resize: vertical; line-height: 1.5; }
/* Compact input for dense blocks (visit header, added work lines, parts rows) */
.input.compact { min-height: 44px; padding: 8px 10px; font-size: 16px; border-radius: 10px; }

/* Compact label/value block (preset visit header) */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; align-items: center; }
.kv dt { color: var(--muted); font-size: 15px; }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.kv dd .input { text-align: right; }

/* Card title with an action button on the right (e.g. + on Travaux prévus) */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.add-btn { display: grid; place-items: center; width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 12px; background: var(--brand); color: #fff; }
.add-btn svg { width: 24px; height: 24px; }

.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.unit-wrap { position: relative; }
.unit-wrap .input { padding-right: 44px; }
.unit-wrap .unit {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px; pointer-events: none;
}

/* Unusual reading: soft red highlight plus a short note. Never blocks typing. */
.input.unusual { background: var(--warn-bg); border-color: var(--warn-line); }
.unusual-note { margin-top: 5px; font-size: 14px; color: var(--warn-text); }

/* Date field: text input with a calendar button inside it on the right */
.date-wrap { position: relative; }
/* Tight padding so jj/mm/aaaa fits in a half-width field next to the button on a 360px phone */
.date-wrap .input { padding-left: 10px; padding-right: 40px; }
.date-btn { position: absolute; right: 1px; top: 50%; transform: translateY(-50%); width: 40px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--brand); display: grid; place-items: center; }
.date-btn:active { background: var(--brand-soft); }
.date-btn svg { width: 22px; height: 22px; }
.input.invalid { border-color: var(--warn-line); background: var(--warn-bg); }

/* Calendar sheet */
.cal-head { display: grid; grid-template-columns: 44px 1fr 96px 44px; gap: 6px; align-items: center; margin-bottom: 8px; color: var(--brand); }
.cal-head .icon-btn:active { background: var(--brand-soft); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .wd { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-grid .day { height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 17px; }
.cal-grid .day:active { background: var(--brand-soft); }
.cal-grid .day.today { box-shadow: inset 0 0 0 1.5px var(--brand); }
.cal-grid .day.selected { background: var(--brand); color: #fff; font-weight: 700; }
.cal-sel { text-align: center; color: var(--muted); margin-top: 10px; font-size: 15px; }
.cal-sel strong { color: var(--brand-dark); }
.cal-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* Segmented choice (OK / bas / NOK) */
.segmented { display: flex; gap: 8px; }
.segmented button {
  flex: 1; min-height: 50px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; font-weight: 600; font-size: 16px;
}
.segmented button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.segmented button[aria-pressed="true"].bad { background: #b84444; border-color: #b84444; }

/* Toggle switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch .text { font-weight: 600; }
.switch input { appearance: none; width: 54px; height: 32px; border-radius: 999px; background: #c9cfdd; position: relative; transition: background .15s; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(22px); }

/* Planned work checklist */
.check-item { display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.check-item:last-child { border-bottom: 0; }
.check-item input[type=checkbox] { width: 28px; height: 28px; accent-color: var(--brand); flex-shrink: 0; }
.check-item label { flex: 1; }
.check-item .input { flex: 1; min-width: 0; }
.check-item input[type=checkbox]:checked + label { color: var(--muted); text-decoration: line-through; }

/* Phase grid (intensité / tension): label column + 3 phase columns */
.phase-grid { display: grid; grid-template-columns: minmax(84px, 1fr) repeat(3, minmax(0, 1.1fr)); gap: 8px; align-items: center; }
.phase-grid .head { text-align: center; font-size: 14px; font-weight: 700; color: var(--muted); }
.phase-grid .rowlabel { font-size: 15px; font-weight: 600; color: var(--muted); line-height: 1.2; }
.phase-grid .input { padding: 10px 6px; text-align: center; min-height: 50px; font-size: 18px; }
.grid-notes .unusual-note { margin-top: 8px; }

/* Machine selector chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px; scrollbar-width: none; }
.chip {
  flex-shrink: 0; min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fff; font-weight: 600; font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.add { color: var(--brand); border-style: dashed; }
.chip .chip-dot { display: inline-block; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: #d65a5a; vertical-align: middle; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 20px; border-radius: 12px; border: 0;
  font-weight: 700; font-size: 17px;
}
.btn.block { width: 100%; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:disabled { background: #aab3d3; }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--line); }
.btn.danger-ghost { background: transparent; color: var(--warn-text); border: 1.5px solid var(--warn-line); }
.btn svg { width: 22px; height: 22px; }
.btn-stack { display: grid; gap: 10px; margin-top: 8px; }

/* ---------- Parts (pièces): one line per item ---------- */
.piece-row { display: grid; grid-template-columns: minmax(0, 1fr) 52px 74px 36px; gap: 6px; align-items: center; padding: 4px 0; }
.piece-row.head { padding: 0 0 2px; font-size: 13px; font-weight: 700; color: var(--muted); }
.piece-row.head span:nth-child(n+2) { text-align: center; }
.piece-row .num { padding: 8px 6px; text-align: right; }
/* Designation wraps instead of being cut off: one line for most items, at most two (longer text scrolls inside).
   Wrapped text gets tighter padding so exactly two lines show. */
.piece-row textarea.input.compact { min-height: 44px; height: 44px; padding: 12px 10px; resize: none; overflow-y: auto; line-height: 1.3; font-size: 14px; }
/* 2 × 20px lines + 2px top padding in a 44px box: the leading of a third line is all that would fit, so nothing shows. */
.piece-row textarea.input.compact.multi { padding: 2px 10px 0; line-height: 20px; }
.piece-row { align-items: start; }
.piece-row.head { align-items: end; }
.remove-btn { width: 36px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: grid; place-items: center; padding: 0; }
.remove-btn:active { background: var(--warn-bg); color: var(--warn-text); }
.remove-btn svg { width: 20px; height: 20px; }
.total-bar { display: flex; justify-content: space-between; align-items: baseline; font-size: 19px; font-weight: 800; color: var(--brand-dark); }
.total-bar small { font-weight: 600; color: var(--muted); font-size: 14px; }
.quick-add { display: flex; flex-wrap: wrap; gap: 8px; }

/* Bottom sheet (catalogue search) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 86vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 14px calc(14px + var(--safe-bottom));
  box-shadow: 0 -6px 24px rgba(15, 20, 40, .25);
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; }
.sheet h3 { margin: 0 0 10px; font-size: 18px; }
.sheet .results { overflow-y: auto; margin-top: 10px; }
.result { display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 14px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.result:active { background: var(--brand-soft); }
.result .r-name { font-weight: 600; }
.result .r-ref { font-size: 13px; color: var(--muted); }
.result .r-price { font-weight: 700; white-space: nowrap; }

/* ---------- Comments + dictation ---------- */
.dictate-wrap { position: relative; }
.dictate-wrap textarea.input { padding-bottom: 64px; }
.mic-btn {
  position: absolute; right: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 999px; border: 0;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 2px 6px rgba(20, 30, 70, .25);
}
.mic-btn svg { width: 22px; height: 22px; }
.mic-btn.listening { background: #c0392b; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, .45); } 50% { box-shadow: 0 0 0 10px rgba(192, 57, 43, 0); } }
.interim { color: var(--muted); font-style: italic; font-size: 15px; min-height: 1.4em; margin-top: 6px; }

/* ---------- Signature ---------- */
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.summary dt { color: var(--muted); font-size: 15px; }
.summary dd { margin: 0; font-weight: 600; text-align: right; }
.summary .warn-line { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-size: 15px; }
.summary .warn-line button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }
.sig-pad-wrap { position: relative; border: 1.5px dashed #aab3d3; border-radius: 12px; background: #fcfcfe; overflow: hidden; }
.sig-pad-wrap canvas { display: block; width: 100%; height: 190px; touch-action: none; }
.sig-pad-wrap .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa3bd; pointer-events: none; font-size: 16px; }
.sig-pad-wrap .baseline { position: absolute; left: 20px; right: 20px; bottom: 44px; border-bottom: 1px solid #d4d9e6; pointer-events: none; }
.sig-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.sig-actions .when { color: var(--muted); font-size: 14px; }
.sig-image { display: block; width: 100%; max-height: 190px; object-fit: contain; border-radius: 12px; background: #fcfcfe; border: 1px solid var(--line); }
.validated-banner { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--ok-soft); color: var(--ok); font-weight: 700; margin-bottom: 12px; }
.validated-banner svg { width: 24px; height: 24px; flex-shrink: 0; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(20, 30, 70, .06);
}
.tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; min-width: 0;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button[aria-selected="true"] { color: var(--brand); }
.tabbar button[aria-selected="true"]::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand);
}
.tabbar .dot { position: absolute; top: 8px; right: calc(50% - 20px); width: 9px; height: 9px; border-radius: 50%; background: #d65a5a; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #222838; color: #fff; font-size: 15px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-card img { display: block; width: 210px; max-width: 80%; margin: 0 auto 8px; }
.login-card h1 { text-align: center; margin: 6px 0 22px; font-size: 20px; color: var(--brand-dark); }
.login-error { margin-bottom: 14px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-size: 15px; }

@media (min-width: 600px) {
  .sheet {
    left: 50%; right: auto; top: 50%; bottom: auto; width: 420px; max-height: 80vh;
    transform: translate(-50%, -50%); border-radius: 18px; padding-bottom: 16px;
  }
  .sheet .grab { display: none; }
  main { padding-left: 20px; padding-right: 20px; }
  .tabbar { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
