:root {
  /* Couleurs MJS Telecom (logo) : bleu #313F93, anthracite #323232 */
  --navy: #262f6e;
  --navy-2: #313f93;
  --ink: #323232;
  --muted: #5f6b7a;
  --line: #dfe3e9;
  --bg: #f3f5f8;
  --card: #ffffff;
  --accent: #313f93;
  --accent-soft: #e8eaf6;
  --accent-ink: #ffffff;
  --green: #11865a;
  --green-bg: #e3f5ec;
  --red: #c62f2f;
  --red-bg: #fbe7e7;
  --amber-bg: #fff4dc;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + var(--safe-b));
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* --- barre du haut --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: #fff; color: var(--ink);
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 2px 10px rgba(49,63,147,.08);
}
.brand-logo { height: 34px; width: auto; display: block; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; letter-spacing: .2px; font-size: 13px; color: var(--accent); }
.brand-sub { font-size: 12px; color: var(--muted); }
.brand-text { border-left: 1px solid var(--line); padding-left: 10px; }
@media (max-width: 380px) { .brand-text { display: none; } }
.icon-btn { background: transparent; border: 0; color: var(--ink); padding: 8px; border-radius: 10px; cursor: pointer; }
.icon-btn:active { background: var(--accent-soft); }
.demo-banner { background: var(--amber-bg); color: #6b4a00; font-size: 13px; padding: 8px 16px; text-align: center; }

/* --- contenu --- */
.app { max-width: 760px; margin: 0 auto; padding: 16px; }
.app.wide { max-width: 1200px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* --- formulaires --- */
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 6px; }
label .req { color: var(--red); }
input, select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px; /* évite le zoom iOS */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  font-weight: 600; cursor: pointer; min-height: 46px; text-decoration: none; color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--red); border-color: #efc4c4; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* --- pointage --- */
.clock-card { text-align: center; padding: 22px 16px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.status-pill.in { background: var(--green-bg); color: var(--green); }
.status-pill.out { background: #eef1f5; color: var(--muted); }
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.status-pill.in .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.timer { font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 14px 0 4px; letter-spacing: 1px; }
.punch-btn {
  width: 190px; height: 190px; border-radius: 50%; border: 0; margin: 18px auto 10px; display: grid; place-items: center;
  font-size: 22px; font-weight: 800; color: #fff; cursor: pointer; box-shadow: 0 10px 30px rgba(0,0,0,.15);
  text-transform: uppercase; letter-spacing: .5px; line-height: 1.15;
}
.punch-btn.in { background: radial-gradient(circle at 30% 30%, #2bb37c, var(--green)); }
.punch-btn.out { background: radial-gradient(circle at 30% 30%, #ef5b5b, var(--red)); }
.punch-btn[disabled] { opacity: .6; }
.punch-btn small { display: block; font-size: 13px; font-weight: 600; text-transform: none; opacity: .9; }
.gps-line { font-size: 13px; color: var(--muted); }
.gps-line a { color: inherit; }

/* --- matériel --- */
.mat-row { display: grid; grid-template-columns: 1fr 90px 100px 44px; gap: 8px; margin-bottom: 10px; align-items: center; }
@media (max-width: 560px) {
  .mat-row { grid-template-columns: 1fr 1fr 44px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .mat-row .m-item { grid-column: 1 / -1; }
}
.mat-del { border: 0; background: var(--red-bg); color: var(--red); border-radius: 10px; height: 44px; cursor: pointer; font-size: 20px; }
.mat-box { border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px; }
.mat-box.error { border-color: var(--red); background: #fff8f8; }
.error-text { color: var(--red); font-size: 14px; margin-top: 6px; }

/* --- listes --- */
.list-item { padding: 12px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: #eef1f5; color: var(--navy-2); }
.tag.orange { background: var(--accent-soft); color: var(--accent); }
.tag.blue { background: #e3ecfb; color: #1d4fa8; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.red { background: var(--red-bg); color: var(--red); }
.mats { margin: 6px 0 0; padding-left: 18px; font-size: 14px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: #f8f9fb; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }

.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.seg button { flex: none; border: 1px solid var(--line); background: #fff; padding: 8px 12px; border-radius: 999px; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* --- barre d'onglets --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: center; background: #fff; border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b));
}
.tabbar button {
  flex: 1; max-width: 140px; border: 0; background: transparent; padding: 6px 4px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); cursor: pointer;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.on { color: var(--accent); font-weight: 700; }

/* --- connexion --- */
.auth-wrap { max-width: 400px; margin: 6vh auto 0; }
.auth-wrap .card { padding: 22px; }
.auth-title { font-size: 24px; font-weight: 800; margin: 0 0 4px; }

/* --- toast & modale --- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #323232; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 15px; max-width: 92vw;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
.modal { position: fixed; inset: 0; background: rgba(30,34,60,.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: #fff; width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + var(--safe-b)); max-height: 90vh; overflow-y: auto; }
@media (min-width: 640px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } }
.menu-list button { display: block; width: 100%; text-align: left; padding: 14px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 16px; cursor: pointer; }
.menu-list button:last-child { border-bottom: 0; }
.install-tip { background: #eef5ff; border: 1px solid #cfe0fb; color: #173f7a; }

/* ---------------- soumissions ---------------- */
.qhead, .qline { display: grid; grid-template-columns: 120px minmax(200px,1fr) 80px 100px 100px 150px 58px; gap: 6px; align-items: start; }
.qhead { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #fff; background: var(--accent); padding: 8px; border-radius: 8px 8px 0 0; margin-top: 12px; font-weight: 700; }
.qline { padding: 8px; border-bottom: 1px solid var(--line); }
.qline:nth-child(even) { background: #fafbfe; }
.qline input, .qline textarea { padding: 8px; font-size: 15px; border-radius: 8px; }
.qline textarea { min-height: 40px; resize: vertical; overflow: hidden; }
.qline .l-total { padding: 9px 4px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.qline .l-qty, .qline .l-price { text-align: right; }
.qline.text .l-desc { font-style: italic; background: #fffdf3; }
.l-tools { display: flex; gap: 4px; }
.l-tools button { width: 26px; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; padding: 0; }
.l-tools .l-del { color: var(--red); background: var(--red-bg); border-color: #f2c9c9; }
@media (max-width: 860px) {
  .qhead { display: none; }
  .qline { grid-template-columns: 1fr 1fr 1fr; border: 1px solid var(--line); border-radius: 12px; margin-top: 10px; background: #fff !important; }
  .qline .l-code { grid-column: 1 / 3; }
  .qline .l-tools { grid-column: 3; justify-content: flex-end; }
  .qline .l-desc { grid-column: 1 / -1; order: 0; }
  .qline .l-code, .qline .l-tools { order: -1; }
  .qline .l-notes { grid-column: 1 / -1; }
  .qline .l-total { align-self: center; }
}
.qbottom { display: flex; gap: 14px; flex-wrap: wrap; }
.qtotals .row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.qtotals .total-row { border: 0; background: var(--accent); color: #fff; margin: 8px -16px -16px; padding: 12px 16px; border-radius: 0 0 var(--radius) var(--radius); font-size: 18px; }
.qactions { position: sticky; bottom: calc(70px + var(--safe-b)); display: flex; gap: 8px; flex-wrap: wrap; background: rgba(243,245,248,.94); backdrop-filter: blur(6px); padding: 10px 0; z-index: 5; }
.qactions .btn { flex: 1; min-width: 130px; }
.pk-item { display: flex; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; }
.pk-item.on { border-color: var(--accent); background: var(--accent-soft); }
.pk-qty { width: 80px; margin-top: 4px; padding: 6px 8px; text-align: right; }

/* ---------------- terrain : hors ligne, travaux, photos, signature ---------------- */
.net-banner { position: sticky; top: 0; z-index: 19; background: #323232; color: #fff; font-size: 13px; padding: 8px 16px; text-align: center; }
.job { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin-top: 10px; background: #fff; }
.job.done { opacity: .6; border-left-color: var(--green); }
.job a { color: var(--accent); }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb-edit { position: relative; }
.thumb-edit button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--red); color: #fff; cursor: pointer; line-height: 1; }
.sig-wrap { position: relative; border: 2px dashed var(--accent); border-radius: 12px; background: #fff; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; height: 170px; touch-action: none; }
.sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; font-size: 15px; }
