:root {
  --bg: #F2F5FB; --surface: #FFFFFF; --surface2: #E7ECF7; --ink: #0E1B3D; --muted: #55607A; --line: #DCE3F1;
  --brand: #2F5BFF; --brand-ink: #FFFFFF; --brand-soft: #E8EEFF; --brand-text: #2A50E6;
  --ok: #17603C; --ok-bg: #DDF3E8; --warn: #85470D; --warn-bg: #FBEBD3; --bad: #A32A1E; --bad-bg: #FCE3E0;
  --purple: #5A32B3; --purple-bg: #ECE4FA; --info: #1F4BB8; --info-bg: #E1EAFF; --gray-bg: #E9ECF3; --gray: #4A5470;
  --shadow: 0 1px 2px rgba(14,27,61,.08), 0 4px 14px rgba(14,27,61,.05);
  --radius: 18px; color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0A1020; --surface: #131B2F; --surface2: #1B2642; --ink: #E9EEFC; --muted: #9DA9C7; --line: #26314F;
  --brand: #7A97FF; --brand-ink: #0A1024; --brand-soft: #1D2A55; --brand-text: #A9BEFF;
  --ok: #7BE0AC; --ok-bg: #123526; --warn: #FFC680; --warn-bg: #3A2A0C; --bad: #FF9E94; --bad-bg: #421B1B;
  --purple: #C7B4FF; --purple-bg: #2B2350; --info: #9DB8FF; --info-bg: #1B2A55; --gray-bg: #222C47; --gray: #B6C0DB;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--brand-text); text-decoration: none; }
button { font-family: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -.7px; }
h2 { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.bold { font-weight: 700; }
.mono { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.center { text-align: center; }
.hide { display: none !important; }
svg { flex-shrink: 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
:root[data-theme="dark"] .btn-ok { color: #06210f; background: #5FD497; border-color: #5FD497; }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-lg { min-height: 54px; font-size: 16px; padding: 0 24px; width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }
.icon-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-family: inherit; font-size: 15px; font-weight: 500; }
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.input.big { font-size: 26px; font-weight: 800; min-height: 58px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--line); transition: .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; transition: .15s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(22px); }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--surface2); gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font-weight: 700; padding: 0 16px; min-height: 38px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* surfaces */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border: 1px solid var(--line); }
.card.flat { box-shadow: none; }
.card h2 { margin-bottom: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--gray-bg); color: var(--gray); white-space: nowrap; }
.pill.new { background: var(--gray-bg); color: var(--gray); }
.pill.assigned { background: var(--info-bg); color: var(--info); }
.pill.in_progress { background: var(--warn-bg); color: var(--warn); }
.pill.light { background: var(--warn-bg); color: var(--warn); }
.pill.qc_review { background: var(--purple-bg); color: var(--purple); }
.pill.rework { background: var(--bad-bg); color: var(--bad); }
.pill.approved, .pill.ok, .pill.paid { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
:root[data-theme="dark"] .badge { background: #FF7A6E; color: #2a0805; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex-shrink: 0; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.banner { padding: 14px 16px; border-radius: 14px; display: flex; gap: 12px; align-items: flex-start; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.info { background: var(--info-bg); color: var(--info); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* office shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 21px; letter-spacing: -.5px; color: var(--ink); }
.brand-img { display: block; object-fit: contain; flex-shrink: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; justify-content: center; }
.nav { display: flex; gap: 4px; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.nav a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; color: var(--muted); font-weight: 700; font-size: 14px; white-space: nowrap; }
.nav a.on { background: var(--brand-soft); color: var(--brand-text); }
.page { max-width: 1400px; margin: 0 auto; padding: 24px 28px 60px; display: flex; flex-direction: column; gap: 20px; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat .n { font-size: 30px; font-weight: 800; letter-spacing: -.8px; }
.stat.alert { border-color: var(--warn); }

/* board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(188px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.bcol { background: var(--surface2); border-radius: 20px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 160px; }
.bcol h3 { display: flex; align-items: center; gap: 8px; padding: 2px 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.cnt { margin-left: auto; font-size: 12px; font-weight: 800; color: var(--muted); background: var(--surface); border-radius: 999px; padding: 2px 9px; }
.kcard { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); border: 1px solid var(--line); cursor: pointer; }
.kcard:hover { border-color: var(--brand); }
.kcard .num { font-weight: 800; font-size: 14px; white-space: nowrap; }

/* table */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 14px; background: var(--surface2); white-space: nowrap; }
table.t td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--brand-soft); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 700; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.photogrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.ph { position: relative; border-radius: 14px; overflow: hidden; background: var(--surface2); border: 2px solid var(--line); display: flex; flex-direction: column; }
.ph.flag { border-color: var(--bad); }
.ph.missing { border-style: dashed; }
.ph .img { aspect-ratio: 4 / 3; background: var(--surface2) center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: zoom-in; }
.ph .cap { padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.ph .cap b { font-size: 13px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; }
.kv + .kv { border-top: 1px solid var(--line); }
.total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; margin-top: 6px; border-top: 2px solid var(--line); }
.total .n { font-size: 30px; font-weight: 800; letter-spacing: -.6px; }
.tl { display: flex; flex-direction: column; gap: 10px; }
.tl div { font-size: 13px; padding-left: 14px; border-left: 3px solid var(--line); }

/* modal, toast, tray */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(6,12,30,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); color: var(--ink); border-radius: 22px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { max-width: 980px; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 12px; display: block; margin: 0 auto; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100% - 32px); max-width: 460px; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
:root[data-theme="dark"] .toast.ok { color: #06210f; background: #5FD497; }
#tray { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; flex-direction: column; gap: 6px; padding: 0 12px calc(env(safe-area-inset-bottom, 0px) + 74px); pointer-events: none; }
#tray.notab { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
.tray-item { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.18); max-width: 560px; width: 100%; margin: 0 auto; }
.tray-item .thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--surface2) center / cover; flex-shrink: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--surface2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--brand); width: 0; transition: width .2s; }
.bar.done i { background: #1B9A62; }
.bar.err i { background: var(--bad); }

/* technician (mobile-first) */
.tshell { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.thead { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bg); }
.tmain { padding: 4px 16px 140px; display: flex; flex-direction: column; gap: 14px; flex: 1 1 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 12px calc(env(safe-area-inset-bottom, 0px) + 6px); }
.tabbar > div { display: flex; width: 100%; max-width: 560px; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; justify-content: center; color: var(--muted); font-size: 12px; font-weight: 700; }
.tabbar a.on { color: var(--brand-text); }
.jobcard { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--ink); }
.paybar { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-radius: 18px; background: var(--brand); color: var(--brand-ink); }
.paybar .n { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.step { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; min-height: 64px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--line); }
.step.todo { border-color: var(--brand); }
.step.flag { border-color: var(--bad); }
.step .mark { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: #1B9A62; color: #fff; }
.step .mark.todo { background: transparent; border: 2px dashed var(--muted); }
.step .mark.busy { background: var(--brand-soft); color: var(--brand-text); }
.step .thumb { width: 48px; height: 48px; border-radius: 10px; background: var(--surface2) center / cover; flex-shrink: 0; }
.submitbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 14px); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 20px rgba(14,27,61,.08); }
.submitbar > div { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.segs { display: flex; gap: 6px; }
.segs i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.segs i.done { background: #1B9A62; }
.segs i.now { background: var(--brand); }
.camview { height: 250px; border-radius: 24px; background: #0E1B3D; color: #B8C4EC; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; position: relative; overflow: hidden; background-size: cover; background-position: center; }
.shutter { width: 84px; height: 84px; border-radius: 50%; border: 4px solid var(--brand); background: var(--surface); padding: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.shutter i { width: 62px; height: 62px; border-radius: 50%; background: var(--brand); display: block; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 420px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.pulse { animation: pl 1.6s ease-in-out infinite; }
@keyframes pl { 50% { opacity: .55; } }

@media (max-width: 1000px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 10px 14px; gap: 10px; }
  .page { padding: 16px 14px 60px; }
  .brand span.t { display: none; }
}
@media print {
  body { background: #fff; color: #000; }
  .topbar, .tabbar, #tray, #toasts, .noprint { display: none !important; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .photogrid { grid-template-columns: repeat(3, 1fr); }
}
