/* Dark by default, mobile-first: phone layout is the base; tablet/desktop widen at 761px+. */
[hidden] { display: none !important; } /* beats display:inline-flex on buttons */
:root {
  --bg: #111418; --panel: #1a1f25; --line: #2a313a; --text: #e8ecf0; --muted: #8b96a3;
  --accent: #4aa3ff; --open: #8b96a3; --doing: #f5b942; --done: #3ecf8e; --danger: #ff6b6b;
  --tap: 44px; --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, .btn, select, input { font: inherit; color: inherit; min-height: var(--tap); border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); padding: 0 14px; }
button, .btn { cursor: pointer; display: inline-flex; align-items: center; }
button:active { transform: scale(.98); }
.ghost { background: transparent; border-color: transparent; }
.danger { border-color: var(--danger); color: var(--danger); }
.muted { color: var(--muted); }
.msg { color: var(--doing); min-height: 1.4em; margin: 6px 0; font-size: 15px; }
.spacer { flex: 1; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }

.signin-card { max-width: 380px; margin: 12vh auto; padding: 28px; background: var(--panel);
  border-radius: var(--r); display: grid; gap: 14px; }
.signin-card label { display: grid; gap: 6px; font-size: 15px; color: var(--muted); }
.signin-card button { background: var(--accent); border: 0; color: #00172e; font-weight: 600; justify-content: center; }

.topbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs [role=tab] { background: transparent; border-color: transparent; color: var(--muted); }
.tabs [aria-selected=true] { color: var(--text); background: var(--panel); border-color: var(--line); }
.who { color: var(--muted); font-size: 14px; }

.tab { padding: 12px; }
.board { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 12px; }
.col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.actions { display: flex; gap: 6px; }
.inbox, .jobs { background: var(--panel); border-radius: var(--r); padding: 12px; min-width: 0; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo-grid img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; border: 2px solid transparent; }
.photo-grid img.sel { border-color: var(--accent); }
.empty { color: var(--muted); padding: 16px 4px; }
.pin-bar { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center; padding-top: 10px; background: var(--panel); flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; cursor: pointer; }
.card h4 { margin: 0 0 6px; font-size: 18px; }
.strip { display: flex; gap: 4px; overflow-x: auto; margin: 8px 0; }
.strip img { height: 56px; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 14px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); }
.chip.open { color: var(--open); } .chip.doing { color: var(--doing); border-color: var(--doing); } .chip.done { color: var(--done); border-color: var(--done); }

.mine { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; max-width: 720px; }
.mine li { background: var(--panel); border-radius: var(--r); padding: 14px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }

.help { max-width: 640px; }
.help .flow { font-size: 22px; color: var(--accent); margin: 8px 0 20px; }
.help dt { font-weight: 600; margin-top: 12px; } .help dd { margin: 2px 0 0; color: var(--muted); }

.sheet { width: min(860px, 96vw); max-height: 92vh; max-height: 92dvh; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.sheet::backdrop { background: rgba(0,0,0,.6); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.photo-full { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.photo-full img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; }
.photo-full figure { margin: 0; } .photo-full figcaption { font-size: 13px; margin-top: 2px; line-height: 1.25; }
.assignees { list-style: none; padding: 0; display: grid; gap: 6px; }
.assignees li { display: flex; align-items: center; gap: 8px; }
.assign-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.state-seg { display: inline-flex; gap: 2px; } .state-seg button[aria-pressed=true] { border-color: var(--accent); }

.role-worker .lead-only { display: none !important; }

/* Phone / narrow split view: stack Inbox above Jobs (MVP §8). */
@media (max-width: 760px) {
  .board { grid-template-columns: 1fr; }
  .who { display: none; }
  .tabs [role=tab] { padding: 0 10px; }
}

/* ---- first-demo slices: rows, threads, capture ---- */
.panel { background: var(--panel); border-radius: var(--r); padding: 12px; min-width: 0; }
.week { display: grid; gap: 12px; }
.rows { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.rows li { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; }
#tab-requests .rows li { background: var(--panel); }
.thread { display: grid; gap: 8px; }
.msgs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-height: 45vh; max-height: 45dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.msgs li { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.msgs li.me { border-color: var(--accent); }
.msgs time { font-size: 13px; }
.composer, .capture { display: flex; gap: 8px; flex-wrap: wrap; }
.composer input, .capture input:not([type=file]) { flex: 1; min-width: 0; }
.captures { list-style: none; padding: 0; display: grid; gap: 10px; }
.captures img { width: 100%; border-radius: 8px; }
.captures p { margin: 4px 0; }

/* Phone: bottom tab bar, full-screen sheet. */
@media (max-width: 760px) {
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; justify-content: space-around; gap: 0;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
  .tabs .spacer { display: none; }
  .tabs [role=tab] { flex: 1; justify-content: center; font-size: 14px; padding: 0 4px; }
  .topbar { justify-content: flex-end; }
  .tab { padding-bottom: 88px; }
  .sheet { width: 100vw; max-width: 100vw; height: 100vh; height: var(--vvh, 100dvh); max-height: var(--vvh, 100dvh); margin: 0; border-radius: 0; border: 0;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); overflow-y: auto; }
  body.kb-open .tabs { display: none; }
  body.kb-open .tab { padding-bottom: 12px; }
  .tab { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
}
/* Tablet+: This Week side by side, captures in a grid. */
@media (min-width: 761px) {
  .week { grid-template-columns: 1fr 1fr; align-items: start; }
  .captures { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
#d-notes { white-space: pre-line; }

/* Show/hide password eye: on every password field (John's standing rule). */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { flex: 1; min-width: 0; padding-right: 52px; }
.pw-wrap .pw-eye, .signin-card .pw-wrap .pw-eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: var(--tap); height: var(--tap); min-height: var(--tap); padding: 0; justify-content: center;
  background: transparent; border: 0; color: var(--muted); touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.pw-wrap .pw-eye:active { transform: translateY(-50%) scale(.94); }
.pw-wrap .pw-eye:hover, .pw-wrap .pw-eye[aria-pressed=true] { color: var(--text); }
.pw-wrap .pw-eye:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 10px; }
.pw-eye[aria-pressed=false] .slash { display: none; }
.demo-reset { margin-top: 28px; padding-top: 4px; border-top: 1px solid var(--line); }

/* ---- Read-only guest ---- */
.role-guest .write-only { display: none !important; }
.guest-badge { font-size: 13px; font-weight: 600; color: #1d1405; background: var(--warm); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }

/* ---- Section "?" buttons + help card ---- */
.tab, .sheet { position: relative; }
.qhelp { position: absolute; top: 14px; right: 14px; z-index: 2; width: var(--tap); height: var(--tap); min-height: var(--tap);
  padding: 0; border-radius: 50%; justify-content: center; font-weight: 700; font-size: 18px; color: var(--warm);
  border-color: color-mix(in srgb, var(--warm) 55%, var(--line)); background: var(--panel); }
.qhelp:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.sheet-tools { display: inline-flex; gap: 8px; align-items: center; }
.sheet-tools .qhelp { position: static; }
/* keep headers clear of the corner button */
#tab-week .panel:first-child h2, #tab-requests .col-head, #tab-mine > h2, .help > .demo-reset h2, .help > .prefs { padding-right: 52px; }
.board .jobs .col-head { padding-right: 52px; }
.qcard { width: min(420px, 92vw); background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; }
.qcard::backdrop { background: rgba(0,0,0,.55); }
.qc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.qc-head h2 { margin: 0; }
.qc-x { width: var(--tap); padding: 0; justify-content: center; }
.qcard h3 { margin: 14px 0 4px; }
.qcard p { margin: 0; }
.qcard ul { margin: 4px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.help .prefs { margin: 16px 0 8px; }
.switch { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.switch input, .sp-skip input { width: 22px; height: 22px; min-height: 0; accent-color: var(--warm); }

/* ---- Welcome splash ---- */
:root { --warm: #ffb347; --warm2: #ff7a45; }
.splash { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 80% at 50% 0%, #2a1d10 0%, #111418 60%); animation: sp-in .35s ease-out; }
.splash[hidden] { display: none; }
.sp-card { width: min(380px, 100%); text-align: center; display: grid; gap: 10px; justify-items: center; }
.sp-word { font-size: 44px; font-weight: 800; letter-spacing: .02em; line-height: 1;
  background: linear-gradient(90deg, var(--warm), var(--warm2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sp-tag { margin: 0 0 6px; color: var(--muted); font-size: 16px; line-height: 1.35; }
.sp-welcome { margin: 4px 0 0; font-size: 21px; font-weight: 650; }
.sp-last { margin: 0; font-size: 15px; }
.sp-unread { margin-top: 4px; border-color: var(--warm); color: var(--warm); border-radius: 999px; font-weight: 600; }
.sp-continue { margin-top: 8px; width: 100%; justify-content: center; border: 0; font-weight: 700; color: #1d1405;
  background: linear-gradient(90deg, var(--warm), var(--warm2)); }
.sp-skip { display: flex; align-items: center; gap: 10px; min-height: var(--tap); color: var(--muted); font-size: 15px; cursor: pointer; }
.sp-timer { width: 100%; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.sp-timer span { display: block; height: 100%; background: var(--warm); transform-origin: left; animation: sp-timer var(--sp-ms, 4s) linear forwards; }
.splash.held .sp-timer { visibility: hidden; }
.splash.still, .splash.still * { animation: none !important; }
.splash.still .sp-timer { display: none; }
/* Splash crew: three original toy-like plumbers (inline SVG, no images). */
.sp-crew { width: min(340px, 88vw); height: auto; overflow: visible; margin-bottom: 6px; }
.sp-crew .cr-skin { fill: var(--skin); } .sp-crew .cr-shirt { fill: var(--shirt); }
.sp-crew .cr-arm { stroke: var(--shirt); stroke-width: 11; stroke-linecap: round; fill: none; }
.sp-crew .cr-hat, .sp-crew .cr-vest { fill: var(--hat); }
.sp-crew .cr-tape { fill: #f4f1e8; opacity: .9; } .sp-crew .cr-tape2 { fill: rgba(0,0,0,.12); }
.sp-crew .cr-pants { fill: #34405a; } .sp-crew .cr-boot { fill: #1c2029; }
.sp-crew .cr-eye { fill: #1c2029; } .sp-crew .cr-cheek { fill: #ff7d6b; opacity: .45; }
.sp-crew .cr-smile { fill: none; stroke: #1c2029; stroke-width: 2; stroke-linecap: round; }
.sp-crew .cr-shine { fill: rgba(255,255,255,.4); } .sp-crew .cr-shadow { fill: rgba(0,0,0,.35); }
.sp-crew .cr-steel { fill: #c9d1da; }
.sp-crew .cr-pipe path { fill: none; stroke: #d9884a; stroke-width: 7; stroke-linecap: round; }
.sp-crew .cr-fit { fill: #b06a33; }
.sp-crew .cr-in, .sp-crew .cr-bob, .sp-crew .cr-wave, .sp-crew .cr-wrench { transform-box: fill-box; }
.sp-crew .cr-in { transform-origin: 50% 100%; animation: cr-in .7s cubic-bezier(.3,1.5,.5,1) backwards; }
.sp-crew .cr-a .cr-in { animation-delay: .1s; } .sp-crew .cr-b .cr-in { animation-delay: .25s; } .sp-crew .cr-c .cr-in { animation-delay: .4s; }
.sp-crew .cr-bob { transform-origin: 50% 100%; animation: cr-bob 1.9s ease-in-out .9s infinite alternate; }
.sp-crew .cr-b .cr-bob { animation-delay: 1.15s; } .sp-crew .cr-c .cr-bob { animation-delay: 1.4s; animation-duration: 2.1s; }
.sp-crew .cr-wave { transform-origin: 85% 90%; animation: cr-wave .9s ease-in-out .8s infinite alternate; }
.sp-crew .cr-wrench { transform-origin: 50% 100%; animation: cr-swing 1.2s ease-in-out .7s infinite alternate; }
@keyframes cr-in { from { opacity: 0; transform: translateY(26px) scale(.7); } to { opacity: 1; transform: none; } }
@keyframes cr-bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes cr-wave { from { transform: rotate(-14deg); } to { transform: rotate(16deg); } }
@keyframes cr-swing { from { transform: rotate(-18deg); } to { transform: rotate(14deg); } }
@keyframes sp-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sp-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) {
  .splash, .splash * { animation: none !important; }
  .sp-timer { display: none; }
}
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--panel); border: 1px solid var(--warm); color: var(--text); border-radius: 999px; padding: 10px 16px;
  font-size: 15px; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 92vw; }
@media (max-width: 760px) {
  .board .jobs .col-head { padding-right: 0; }
  .board .inbox .col-head { padding-right: 52px; }
  .guest-badge { margin-right: auto; }
}

/* ---- Inbox photo cells: tap to view, corner check to select (Leads) ---- */
.photo-grid .ph { position: relative; display: block; }
.photo-grid .ph img { display: block; cursor: zoom-in; }
.ph-sel { position: absolute; top: 2px; right: 2px; width: var(--tap); height: var(--tap); min-height: var(--tap); padding: 0;
  justify-content: center; border-radius: 50%; background: rgba(17,20,24,.6); border: 2px solid #fff8; color: #fff; font-weight: 700; }
.ph-sel[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #00172e; }
.strip img, .photo-full img, .captures img { cursor: zoom-in; }

/* ---- Lightbox ---- */
body.lb-open { overflow: hidden; position: fixed; left: 0; right: 0; width: 100%; overscroll-behavior: none; }
.lightbox { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: #fff; overflow: hidden; }
.lightbox::backdrop { background: #000; }
.lb-stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; overscroll-behavior: contain; }
.lb-stage img { touch-action: none; }
.lb-stage img { max-width: 100vw; max-height: 100dvh; object-fit: contain; transform-origin: center; will-change: transform; -webkit-user-drag: none; }
.lb-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: linear-gradient(#000a, #0000); pointer-events: none; }
.lb-top > * { pointer-events: auto; }
.lb-count { font-size: 15px; font-variant-numeric: tabular-nums; }
.lb-btn { width: var(--tap); height: var(--tap); padding: 0; justify-content: center; border-radius: 50%; background: #0008; border-color: #fff3; color: #fff; font-size: 20px; }
.lb-prev, .lb-next { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px; }
.lb-prev { left: max(8px, env(safe-area-inset-left)); } .lb-next { right: max(8px, env(safe-area-inset-right)); }
.lb-cap { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(#0000, #000b); font-size: 15px; text-align: center; pointer-events: none; }
.lb-cap:empty { display: none; }
@media (hover: none) { .lb-prev, .lb-next { display: none; } } /* touch: swipe instead */
.ai-badge { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: #fff; background: #5b5bd6; border-radius: 999px; padding: 1px 7px; vertical-align: middle; }

/* iPhone Safari: inputs under 16px make iOS zoom the page on focus. */
input, select, textarea { font-size: max(16px, 1em); }
.composer { position: sticky; bottom: 0; background: inherit; padding-bottom: 4px; }
.msgs li.carried { opacity: .7; }
.msgs li.divider { background: transparent; border: 0; padding: 2px 0; font-size: 13px; text-align: center; }
