:root {
  --navy: #1e2d5a;
  --navy-2: #2a3d74;
  --orange: #c8721a;
  --orange-2: #a95f13;
  --green: #2f7d4f;
  --red: #b42318;
  --bg: #f3f4f7;
  --card: #ffffff;
  --text: #182033;
  --muted: #5b6475;
  --line: #dde1e8;
  --radius: 12px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 16px; line-height: 1.4; }
body.ws-open { overflow: hidden; }
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.02rem; }
a { color: var(--navy); }
button { font: inherit; color: inherit; }
.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer;
  text-decoration: none; color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: .9rem; }
.btn.block { display: flex; width: 100%; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-2); }
.btn.danger-outline { color: var(--red); border-color: #f2b8b2; width: 100%; margin-top: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.link { background: none; border: 0; padding: 6px 0; color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: var(--text); text-decoration: none;
}
.icon-btn.light { color: #fff; }
.icon-btn.ghost { color: var(--navy); }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font: inherit; color: inherit;
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(200, 114, 26, .45); outline-offset: 2px;
}
.input:disabled { background: #f6f7f9; color: var(--muted); }
.field { display: grid; gap: 6px; margin-top: 12px; }
.field-label { font-size: .88rem; font-weight: 600; color: var(--muted); }
.form-error { color: var(--red); min-height: 1.2em; margin: 8px 0; font-size: .92rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- splash & login ---------- */
.splash, .login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 16px; }
.login { justify-content: flex-start; padding-top: calc(12vh + var(--safe-t)); }
.login h1 { margin-top: 8px; }
.login-form { width: 100%; max-width: 380px; display: grid; }
.login-form .link { justify-self: start; }
.logo { height: 34px; width: auto; display: block; }
.logo.big { height: 52px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + var(--safe-t)) 16px 10px; background: #fff; border-bottom: 1px solid var(--line);
}
.me-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 8px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--navy); }
.me-name { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter { padding: 10px 16px 0; }
.content { padding: 12px 16px calc(var(--tabbar) + var(--safe-b) + 24px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1; max-width: 240px; height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: .8rem; font-weight: 600; cursor: pointer;
}
.tabbar button.on { color: var(--orange); }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 0; color: var(--muted); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--orange); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 32px 8px; color: var(--muted); }
.empty p { margin: 6px 0; }

/* ---------- job cards ---------- */
.cards { display: grid; gap: 10px; }
.job-card {
  position: relative; display: flex; gap: 10px; width: 100%; text-align: left; padding: 12px 12px 12px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; overflow: hidden;
}
.job-card:active { background: #f8f9fb; }
.job-card.st-issue { border-color: #f2b8b2; background: #fff7f6; }
.job-card.st-done { opacity: .8; }
.job-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.job-body { display: grid; gap: 3px; min-width: 0; flex: 1; }
.job-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.job-store { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.banner { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--navy); background: #e8ecf6; padding: 2px 6px; border-radius: 6px; }
.job-title { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.job-addr { font-size: .88rem; }
.job-meta .order { color: var(--orange-2); font-weight: 700; }
.job-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .82rem; color: var(--muted); }
.badge { flex: none; font-size: .74rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #e8ecf6; color: var(--navy); white-space: nowrap; }
.badge.st-done { background: #e3f1e8; color: var(--green); }
.badge.st-issue { background: #fde7e5; color: var(--red); }
.badge.st-new { background: #f1f2f4; color: var(--muted); }
.stop-num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; font-size: .85rem; display: grid; place-items: center; }

/* ---------- calendar ---------- */
.segmented { display: flex; background: #e6e8ee; border-radius: 10px; padding: 3px; }
.segmented button { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.cal-title { background: none; border: 0; font-weight: 700; padding: 8px; cursor: pointer; color: inherit; }
.week { display: grid; gap: 10px; }
.week-day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.week-day.is-today { border-color: var(--orange); }
.week-head { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--navy); color: #fff; border: 0; font-weight: 600; cursor: pointer; }
.week-day .cards { padding: 10px; }
.today-tag { margin-left: 8px; color: #ffd29e; font-size: .8rem; font-weight: 700; }
.count { font-size: .8rem; background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 999px; }
.m-head, .m-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.m-head span { text-align: center; font-size: .78rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.m-grid { gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.m-cell { min-height: 58px; background: #fff; border: 0; padding: 6px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; cursor: pointer; text-align: left; }
.m-cell.out { background: #f8f9fb; color: #9aa1ad; }
.m-num { font-size: .82rem; font-weight: 700; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.m-cell.is-today .m-num { background: var(--orange); color: #fff; }
.dots { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.done { background: #b6bcc7; }
.more { font-size: .68rem; color: var(--muted); font-weight: 700; }

/* ---------- list ---------- */
.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }
.list-head { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 8px; }
.section-title { margin: 18px 0 8px; font-size: .95rem; color: var(--muted); }

/* ---------- route ---------- */
.route-top { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 6px 8px 10px; }
.cal-nav.light .cal-title, .cal-nav.light .icon-btn { color: #fff; }
.cal-nav.light { margin: 0 0 6px; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; min-height: 64px; }
.ws-day { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; border-radius: 10px; border: 0; background: none; color: #fff; cursor: pointer; }
.ws-day.is-today { background: rgba(255,255,255,.14); }
.ws-day.sel { background: var(--orange); }
.ws-dow { font-size: .68rem; text-transform: uppercase; opacity: .85; }
.ws-num { font-size: 1.05rem; font-weight: 700; }
.ws-count { font-size: .7rem; font-weight: 700; min-height: 1em; color: #ffd29e; }
.ws-day.sel .ws-count { color: #fff; }
.route-head { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 10px; }
.route-body .btn.primary { margin-bottom: 12px; }
.stop-row { display: flex; align-items: center; gap: 6px; }
.stop-row .job-card { flex: 1; }

/* ---------- worksheet ---------- */
.worksheet { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ws-header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--navy); color: #fff; padding: calc(6px + var(--safe-t)) 12px 6px 4px;
}
.ws-header-title { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-main { max-width: 720px; margin: 0 auto; padding: 12px 16px 220px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card > h2 { margin-bottom: 8px; }
.notice { background: #fff6e8; border: 1px solid #f3d3a6; color: #7a4b10; border-radius: var(--radius); padding: 12px 14px; margin: 0; }
.store-name { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.store-card .job-title { margin: 4px 0 0; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 14px 0 6px; }
.facts dt { font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.row-link { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); text-decoration: none; font-weight: 600; }
.mini-map { width: 100%; height: 170px; border: 0; border-radius: 10px; margin-top: 8px; background: #e9ecf1; }
.scope { white-space: pre-wrap; margin: 0; overflow-wrap: anywhere; }
.seg-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seg-buttons button { min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.seg-buttons button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.seg-buttons button:disabled { opacity: .6; cursor: default; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; margin-bottom: 10px; cursor: pointer; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 999px; background: #cfd4dc; position: relative; cursor: pointer; flex: none; margin: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch:checked { background: var(--orange); }
.switch:checked::after { transform: translateX(22px); }
.switch:disabled { opacity: .6; }
.photo-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.photo-actions { display: flex; gap: 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #e9ecf1; }
.photo-open { all: unset; display: block; width: 100%; height: 100%; cursor: zoom-in; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-missing { display: grid; place-items: center; height: 100%; font-size: .75rem; color: var(--muted); }
.photo-del { position: absolute; top: 4px; right: 4px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(180,35,24,.92); color: #fff; display: grid; place-items: center; cursor: pointer; }
.sig-wrap { position: relative; margin-top: 12px; }
.sig-canvas { display: block; width: 100%; height: 180px; background: #fff; border: 1.5px dashed #b8bfcc; border-radius: 10px; touch-action: none; }
.sig-hint { position: absolute; left: 12px; bottom: 8px; font-size: .75rem; color: #9aa1ad; pointer-events: none; }
.sig-actions { display: flex; gap: 8px; margin-top: 8px; }
.sig-existing img { width: 100%; max-height: 180px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.sig-existing p { margin: 6px 0 10px; }
.notes { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.notes li { display: grid; gap: 2px; padding: 8px 10px; background: #f6f7f9; border-radius: 8px; white-space: pre-wrap; }
.ws-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 720px; margin: 0 auto;
  background: #fff; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--safe-b));
  box-shadow: 0 -4px 14px rgba(0,0,0,.05);
}
.busy-line { font-size: .85rem; color: var(--muted); min-height: 0; }
.busy-line:not(:empty) { margin-bottom: 8px; }
.is-busy .ws-main { pointer-events: none; opacity: .75; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-close { position: absolute; top: 10px; right: 10px; }

/* ---------- account sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 35, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: #fff; border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); display: grid; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; }
.sheet h2 { margin-top: 4px; }

.toast {
  position: fixed; left: 50%; top: 14px; z-index: 80; transform: translate(-50%, -140%);
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 10px; background: var(--navy); color: #fff;
  font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.18); transition: transform .2s ease;
}
.toast.err { background: var(--red); }
.toast.show { transform: translate(-50%, 0); }

@media (min-width: 560px) {
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* company choice (logins that work for both companies) */
.company-pick { display: grid; gap: 10px; width: 100%; max-width: 420px; }
.company-btn { flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 16px; min-height: 64px; }
.company-btn strong { font-size: 16px; }

/* ---------- office admin page ---------- */
body.admin-page #app { max-width: 1000px; }
.admin-who { display: flex; align-items: center; gap: 10px; }
.admin-main { padding: 16px; display: grid; gap: 14px; }
.admin-main > h1 { margin: 4px 0; }
.admin-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.admin-tools .search { flex: 1 1 260px; }
.admin-tools select.input { flex: 1 1 280px; width: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th { background: #f6f7f9; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table input[type=checkbox] { width: 20px; height: 20px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.pw { font-weight: 700; letter-spacing: .02em; }
.result-card { border-color: var(--orange); }
@media print {
  body.admin-page .topbar, body.admin-page .admin-tools, body.admin-page .card:not(.result-card), body.admin-page .notice { display: none !important; }
  body.admin-page .table-wrap { overflow: visible; border: 0; }
}

/* All crews mode */
.filter.two-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .filter.two-filters { grid-template-columns: 1fr; } }
.job-meta .crew-tag { color: var(--navy); font-weight: 700; }
.route-body .notice { margin-bottom: 10px; }

/* Privacy policy page */
.doc-page { background: #fff; }
.doc { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; line-height: 1.55; }
.doc h1 { font-size: 1.6rem; color: var(--navy); margin: 0 0 4px; }
.doc h2 { font-size: 1.1rem; color: var(--navy); margin: 28px 0 8px; }
.doc ul { padding-left: 20px; }
.doc li { margin: 6px 0; }
.doc .muted { color: var(--muted); margin-top: 0; }
.doc a { color: var(--navy); }

/* ---------- outbox (saved on this phone, not sent yet) ---------- */
.outbox-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; border: 1px solid #f3d3a6; background: #fff6e8;
  color: #7a4b10; font: inherit; font-size: .8rem; font-weight: 700; padding: 6px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.outbox-btn[hidden] { display: none; }
.outbox-btn.failed { border-color: #f5b8b2; background: #fde7e5; color: var(--red); }
.outbox-list { display: grid; gap: 8px; max-height: 55vh; overflow-y: auto; }
.outbox-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 10px 12px; background: #f6f7f9; border-radius: 10px; }
.outbox-item.failed { background: #fdf1f0; }
.outbox-actions { display: grid; gap: 6px; flex: none; }
.wait-tag { flex: none; font-size: .74rem; font-weight: 700; color: #7a4b10; }
.wait-tag.failed, .muted.failed { color: var(--red); }
.wait-line { margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: #fff6e8; color: #7a4b10; }
.wait-line.failed { background: #fde7e5; color: var(--red); }
.notes li.pending { background: #fff6e8; }
.photo.waiting img { opacity: .85; }
.photo-wait {
  position: absolute; left: 4px; right: 4px; bottom: 4px; font-size: .68rem; font-weight: 700; text-align: center;
  padding: 2px 4px; border-radius: 6px; background: rgba(255, 246, 232, .95); color: #7a4b10; pointer-events: none;
}
.photo.failed .photo-wait { background: rgba(253, 231, 229, .95); color: var(--red); }

/* ---------- no signal: using today's jobs saved on this phone ---------- */
.offline-bar { display: flex; gap: 8px; align-items: flex-start; margin: 10px 16px 0; padding: 8px 12px; border-radius: 10px; background: #fff6e8; border: 1px solid #f3d3a6; color: #7a4b10; font-size: .85rem; }
.offline-bar[hidden] { display: none; }
.offline-bar .icon { flex: none; margin-top: 2px; }
.ws-main > .offline-bar { margin: 0; }
