/* ------------------------------------------------------------------
   app.css — Progress Monitor Field App
   ------------------------------------------------------------------
   Written for a gloved hand in daylight, not a mouse in an office.

   - Minimum tap target 52 px; primary actions 60 px.
   - No hover state carries meaning. Nothing needs a right-click.
   - Contrast is deliberately high: body text sits at or above 7:1 on its
     background, status chips above 4.5:1, because the screen will be
     read outdoors at an angle.
   - Layout: tablet shows model and list together; phone shows one at a
     time with a fixed switcher. Both work in portrait and landscape.
------------------------------------------------------------------- */

:root {
  --bg: #0f141a;
  --bg-2: #171e26;
  --bg-3: #1f2832;
  --line: #2f3b47;
  --line-2: #435265;
  --ink: #f2f6fa;
  --ink-2: #c2ced9;
  --ink-3: #93a3b2;

  --red: #d64545;
  --amber: #e09e2a;
  --green: #34a86e;
  --blue: #3d8bd4;
  --grey: #78848f;

  --accent: #4aa3e0;
  --accent-ink: #06121c;
  --danger: #d64545;
  --ok: #34a86e;

  --tap: 52px;
  --tap-lg: 60px;
  --r: 10px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body { display: flex; flex-direction: column; overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* ------------------------------- app bar ------------------------------ */

.bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-height: calc(56px + var(--safe-t));
}
.bar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.bar .brand img { width: 26px; height: 26px; border-radius: 6px; display: block; }
.bar .spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; min-height: 44px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--grey); flex: 0 0 auto; }
.chip.online { color: #b9e6cf; border-color: #245c42; background: #14291f; }
.chip.online .dot { background: var(--green); }
.chip.offline { color: #ffd9a6; border-color: #6a4c15; background: #2a2010; }
.chip.offline .dot { background: var(--amber); }
.chip.queue { color: #cfe6ff; border-color: #2a4d70; background: #13202c; }
.chip.queue.zero { color: var(--ink-3); border-color: var(--line); background: var(--bg-3); }
.chip.queue.zero .dot { background: var(--grey); }
.chip.queue .dot { background: var(--accent); }

.iconbtn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r); background: var(--bg-3); border: 1px solid var(--line);
  color: var(--ink); font-size: 20px;
}
.iconbtn:active { background: var(--line); }

/* -------------------------------- layout ------------------------------ */

.main { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

.pane-3d {
  flex: 1 1 auto; min-width: 0; position: relative;
  background: var(--bg);
}
.pane-3d canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.pane-list {
  flex: 0 0 380px; min-width: 0; display: flex; flex-direction: column;
  background: var(--bg-2); border-left: 1px solid var(--line);
  padding-right: var(--safe-r);
}

@media (max-width: 900px) {
  .pane-list { flex-basis: 320px; }
}

/* Phone: one at a time, with a fixed switcher (brief §4). */
@media (max-width: 700px) {
  .main { display: block; }
  .pane-3d, .pane-list {
    position: absolute; inset: 0; flex: none; width: 100%; border-left: 0;
  }
  body[data-view="list"] .pane-3d { visibility: hidden; pointer-events: none; }
  body[data-view="model"] .pane-list { display: none; }
  .switcher { display: flex !important; }
}

.switcher {
  display: none;
  flex: 0 0 auto; gap: 8px; padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  background: var(--bg-2); border-top: 1px solid var(--line);
}
.switcher button {
  flex: 1; min-height: var(--tap); border-radius: var(--r);
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--ink-2); font-weight: 700;
}
.switcher button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --------------------------- floating controls ------------------------ */

.view-tools {
  position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 5;
}
.view-tools .iconbtn { background: rgba(23,30,38,.92); backdrop-filter: blur(6px); }

.hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(23,30,38,.94); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; color: var(--ink-2);
  pointer-events: none; z-index: 4; max-width: 92%; text-align: center;
}

/* ------------------------------ list pane ----------------------------- */

.search-row { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.search-row input {
  flex: 1; min-height: var(--tap); padding: 0 14px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--r);
  color: var(--ink);
}
.search-row input::placeholder { color: var(--ink-3); }

.filters { flex: 0 0 auto; display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto;
  scrollbar-width: none; border-bottom: 1px solid var(--line); }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: 0 0 auto; }
.filters button {
  min-height: 40px; padding: 0 13px; border-radius: 999px; white-space: nowrap;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2); font-size: 14px; font-weight: 600;
}
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.list-empty { padding: 28px 18px; color: var(--ink-3); text-align: center; }

.row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap-lg); padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  width: 100%; text-align: left;
}
.row:active { background: var(--bg-3); }
.row[aria-selected="true"] { background: #14283a; box-shadow: inset 3px 0 0 var(--accent); }
.row .sw { width: 12px; align-self: stretch; border-radius: 3px; flex: 0 0 auto; background: var(--grey); }
.row .txt { flex: 1; min-width: 0; }
.row .t1 { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t2 { display: block; font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .badge {
  flex: 0 0 auto; font-size: 12px; font-weight: 700; padding: 3px 8px;
  border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2);
}
.row .badge.unsent { background: #13202c; border-color: #2a4d70; color: #cfe6ff; }

/* ------------------------------ sheets -------------------------------- */

.sheet-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  display: none;
}
@media (min-width: 900px) { .sheet-back { background: rgba(0,0,0,.18); } }
.sheet-back.open { display: block; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 88vh; display: none; flex-direction: column;
  background: var(--bg-2); border-top: 1px solid var(--line-2);
  border-radius: 16px 16px 0 0;
  padding-bottom: var(--safe-b);
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
}
.sheet.open { display: flex; }
@media (min-width: 900px) {
  .sheet { left: 16px; right: auto; bottom: 16px; width: 430px; border-radius: 14px; max-height: 82vh; border: 1px solid var(--line-2); }
}
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 10px auto 4px; flex: 0 0 auto; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 8px 14px 12px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.sheet-head .txt { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-head p { margin: 3px 0 0; font-size: 13px; color: var(--ink-3); overflow-wrap: anywhere; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
.sheet-foot { flex: 0 0 auto; padding: 12px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 10px; }

/* ------------------------------ controls ------------------------------ */

.statuses { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.statuses button {
  min-height: var(--tap-lg); border-radius: var(--r); font-weight: 700; font-size: 15px;
  border: 2px solid transparent; color: #0d1116; padding: 0 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
}
.statuses button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(255,255,255,.16); }
.statuses button .tick { font-size: 18px; }

label.fld { display: block; margin: 16px 0 6px; font-size: 13px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .4px; }
textarea.note {
  width: 100%; min-height: 96px; padding: 12px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--r); color: var(--ink);
  resize: vertical;
}

.btn {
  min-height: var(--tap-lg); padding: 0 18px; border-radius: var(--r);
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--ink);
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { background: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: #38191b; border-color: #6b2b2e; color: #ffc9c9; }
.btn.wide { width: 100%; }
.btn.grow { flex: 1; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg-3); border: 1px solid var(--line); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph .pend { position: absolute; right: 4px; bottom: 4px; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 999px; background: rgba(19,32,44,.92); color: #cfe6ff; border: 1px solid #2a4d70; }
.photos .add {
  aspect-ratio: 1; border-radius: 8px; border: 2px dashed var(--line-2); color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 13px; font-weight: 700;
}
.photos .add span:first-child { font-size: 22px; }

/* ------------------------------- screens ------------------------------ */

.screen {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: none; flex-direction: column;
  padding: calc(var(--safe-t)) calc(var(--safe-r)) calc(var(--safe-b)) calc(var(--safe-l));
}
.screen.open { display: flex; }
.screen .inner { flex: 1 1 auto; overflow-y: auto; padding: 22px 18px 28px; max-width: 620px; width: 100%; margin: 0 auto; }
.screen h1 { font-size: 22px; margin: 6px 0 4px; }
.screen p.lede { color: var(--ink-2); margin: 0 0 20px; }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }
.card p:last-child { margin-bottom: 0; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--r); color: var(--ink);
}
.field .pw { position: relative; display: flex; }
.field .pw input { padding-right: 58px; }
.field .pw button { position: absolute; right: 4px; top: 4px; bottom: 4px; width: 50px; border-radius: 8px; color: var(--ink-2); }

.msg { padding: 12px 14px; border-radius: var(--r); font-size: 14px; margin-bottom: 14px; border: 1px solid; }
.msg.err { background: #2a1416; border-color: #6b2b2e; color: #ffc9c9; }
.msg.warn { background: #2a2010; border-color: #6a4c15; color: #ffd9a6; }
.msg.ok { background: #14291f; border-color: #245c42; color: #b9e6cf; }
.msg.info { background: #13202c; border-color: #2a4d70; color: #cfe6ff; }

.progress { height: 12px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); overflow: hidden; margin: 10px 0 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .18s linear; }
.progress-note { font-size: 13px; color: var(--ink-3); display: flex; justify-content: space-between; gap: 10px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-3); }
.kv .v { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ------------------------------- toasts ------------------------------- */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(10px + var(--safe-t)); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; width: min(520px, 92vw); pointer-events: none;
}
/* On a tablet the toasts used to sit over the search box and the top of the
   list. Tuck them out of the way, over the 3D pane. */
@media (min-width: 900px) {
  .toasts { left: 88px; transform: none; top: auto; bottom: 84px; width: min(460px, 42vw); }
}
.toast {
  padding: 12px 15px; border-radius: var(--r); font-size: 14px; font-weight: 600;
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--ink);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.ok { background: #14291f; border-color: #245c42; color: #d6f3e5; }
.toast.err { background: #2a1416; border-color: #6b2b2e; color: #ffd6d6; }
.toast.warn { background: #2a2010; border-color: #6a4c15; color: #ffe6c2; }

/* ------------------------------ banners ------------------------------- */

.banner {
  flex: 0 0 auto; display: none; align-items: center; gap: 10px;
  padding: 10px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l));
  font-size: 14px; font-weight: 600; border-bottom: 1px solid;
}
.banner.show { display: flex; }
.banner .spacer { flex: 1; }
.banner button { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid currentColor; font-weight: 700; }
.banner.warn { background: #2a2010; border-color: #6a4c15; color: #ffd9a6; }
.banner.err { background: #2a1416; border-color: #6b2b2e; color: #ffc9c9; }
.banner.info { background: #13202c; border-color: #2a4d70; color: #cfe6ff; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
