/* 工地巡查缺失：手機優先樣式（色彩沿用設計部原型：深藍 #123B55 / 藍 #0F5F82） */
:root {
  --ink: #14232F; --muted: #4F6272; --ground: #EEF2F5; --card: #fff; --line: #CBD5DD; --line-strong: #B7C4CE;
  --navy: #123B55; --primary: #0F5F82; --warn: #B45309; --danger: #B42318; --ok: #1B7F4B;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--ink); line-height: 1.5; font-size: 15px;
  font-family: 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', system-ui, sans-serif; }
button, input, select, textarea { font-family: inherit; font-size: 16px; color: var(--ink); }
:focus-visible { outline: 3px solid #F5A524; outline-offset: 2px; }
a { color: var(--primary); }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; display: block; }
.overdue { color: var(--danger); font-weight: 700; }
.pre { white-space: pre-wrap; }

.topbar { background: var(--navy); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 10px 16px; }
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 17px; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0 4px; margin-left: auto; }
.nav a, .link-btn { color: #fff; background: none; border: none; cursor: pointer; padding: 10px 8px; font-size: 14px; min-height: 44px; display: inline-flex; align-items: center; }
.nav-logout { margin: 0; }
.container { max-width: 760px; margin: 0 auto; padding: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.card.empty { text-align: center; color: var(--muted); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1.5px solid var(--navy); background: #fff; color: var(--navy); font-weight: 700; font-size: 15px; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }
.btn:disabled { background: #C3CED7; border-color: #C3CED7; color: #3E4F5D; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; }
.field input, .field select, .filters input[type=search], .filters select, textarea.in, input.in, select.in {
  min-height: 48px; border: 1.5px solid var(--line-strong); border-radius: 10px; padding: 0 12px; background: #fff; width: 100%; }
textarea.in { padding: 10px 12px; min-height: 96px; resize: vertical; }
.login { max-width: 420px; margin: 24px auto; }

/* 清單 */
.stats { display: flex; gap: 10px; margin-bottom: 12px; }
.stat { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.stat b { font-size: 26px; line-height: 1.1; } .stat span { color: var(--muted); font-size: 13px; }
.stat-warn b { color: var(--danger); }
.filters { display: grid; grid-template-columns: 1fr; gap: 8px; }
.filters .check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.filters .check input { width: 22px; height: 22px; min-height: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: block; text-decoration: none; color: var(--ink); }
.row-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.case { font-weight: 700; margin-right: auto; }
.row-loc { font-weight: 700; } .row-work { color: var(--muted); font-size: 14px; }
.row-desc { margin: 6px 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff; }
.sev-none { background: #8A8F98; } .st-pending { background: #8A5A00; } .sev-low { background: #3B5B73; } .sev-mid { background: var(--warn); } .sev-high { background: var(--danger); }
.st-open { background: #6B4E16; } .st-progress { background: var(--primary); } .st-review { background: #5B3F8C; } .st-closed { background: var(--ok); } .st-returned { background: var(--danger); } .st-close { background: #0F6E6E; }
.kv { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 10px; margin: 8px 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photos a { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--muted); font-size: 12px; }
.photos img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.plan-view { position: relative; } .plan-view img { width: 100%; display: block; border: 1px solid var(--line); border-radius: 10px; }
.history { margin: 0; padding-left: 18px; font-size: 14px; }
.table { width: 100%; border-collapse: collapse; } .table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }

/* 圖面標記 */
.pin { position: absolute; pointer-events: none; width: 28px; height: 28px; border-radius: 14px; background: #D92D20; color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center; border: 3px solid #fff; box-shadow: 0 0 0 2px #7A1409; transform: translate(-50%, -50%); }

/* 四步驟精靈 */
.wizard { max-width: 560px; margin: 0 auto; padding-bottom: 150px; }
.wz-head { background: var(--navy); color: #fff; border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; }
.wz-head small { color: #C9DCE8; display: block; font-size: 12px; }
.wz-head strong { font-size: 19px; }
.wz-progress { display: flex; gap: 6px; margin-bottom: 12px; }
.wz-progress div { flex: 1; } .wz-progress i { display: block; height: 5px; border-radius: 3px; background: var(--line); margin-bottom: 4px; }
.wz-progress .on i { background: var(--primary); } .wz-progress span { font-size: 12px; color: var(--muted); } .wz-progress .cur span { color: var(--navy); font-weight: 700; }
.wz-label { font-weight: 700; margin-bottom: 8px; display: block; } .wz-label .req { color: var(--danger); } .wz-label .opt { color: var(--muted); font-weight: 400; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; } .chips.two { display: grid; grid-template-columns: 1fr 1fr; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; text-align: left; background: #fff; border: 1.5px solid var(--line-strong); }
.chip.sel { background: var(--navy); color: #fff; border-color: var(--navy); }
.chips.two .chip, .chips.fill .chip { text-align: center; } .chips.fill .chip { flex: 1; }
.sev-btn { flex: 1; min-height: 52px; border-radius: 10px; font-weight: 700; cursor: pointer; background: #fff; border: 2px solid; }
.sev-btn.sel { color: #fff; }
.plan-wrap { aspect-ratio: var(--plan-ar, 1384 / 1306); overflow: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.plan-box { position: relative; cursor: crosshair; } .plan-box img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.plan-empty { min-height: 120px; border: 1.5px dashed var(--line-strong); border-radius: 10px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 12px 16px; }
.plan-empty.warn { border-color: var(--warn); color: #7A3B07; }
.row-split { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { position: relative; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #D6DEE4; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile button { position: absolute; top: 2px; right: 2px; width: 36px; height: 36px; border-radius: 18px; border: none; background: rgba(20, 35, 47, .85); color: #fff; font-size: 18px; cursor: pointer; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.sum-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid #E1E8ED; }
.sum-row:last-child { border-bottom: none; }
.sum-row .lbl { font-size: 13px; color: var(--muted); }
.sum-mini { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; } .sum-mini img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.note { background: #E3EEF4; border-radius: 12px; padding: 12px 14px; font-size: 13px; color: #24455A; }
.wz-footer { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
.wz-footer-in { max-width: 560px; margin: 0 auto; }
.wz-hint { min-height: 18px; font-size: 13px; color: #7A3B07; margin-bottom: 6px; }
.wz-hint.err { color: var(--danger); font-weight: 700; }
.wz-btns { display: flex; gap: 10px; } .wz-btns .btn { height: 54px; font-size: 16px; border-radius: 12px; } .wz-btns .back { flex: 0 0 104px; } .wz-btns .next { flex: 1; }
.success { text-align: center; padding: 24px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.success .tick { width: 56px; height: 56px; border-radius: 28px; background: var(--ok); color: #fff; font-size: 32px; display: flex; align-items: center; justify-content: center; }

@media (min-width: 640px) { .filters { grid-template-columns: 2fr 1fr 1fr auto auto; align-items: center; } }

/* 判定表單：以 label 包 radio 的選項 */
label.chip { display: inline-flex; align-items: center; gap: 6px; }
label.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
label.chip:has(input:checked) { background: var(--navy); color: #fff; border-color: var(--navy); }
label.chip:has(input:focus-visible) { outline: 3px solid #7FB0D0; outline-offset: 2px; }
.note.err { background: #FDECEA; color: #8A1C12; }
td.actions { display: flex; gap: 8px; flex-wrap: wrap; } td.actions form { margin: 0; }

.plan-wrap.zoomed { overscroll-behavior: contain; touch-action: pan-x pan-y; }
.btn.nowrap { white-space: nowrap; }

.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- 缺失清單：卡片／總表切換 ---- */
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.view-toggle { display: none; gap: 4px; }
.view-table { display: none; }
.print-link { display: inline-block; margin: -6px 0 12px 6px; font-size: 14px; color: var(--navy); padding: 8px 4px; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
@media (min-width: 900px) { .view-toggle { display: flex; } }
body.wide-view .container { max-width: none; }
body.show-table .view-cards { display: none; }
body.show-table .view-table { display: block; }
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.sheet { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 14px; }
.sheet th, .sheet td { border: 1px solid #cfd6dd; padding: 6px 10px; white-space: nowrap; text-align: left; vertical-align: middle; }
.sheet thead th { position: sticky; top: 0; background: #e8eef3; z-index: 2; cursor: default; user-select: none; }
.sheet thead th[data-sort] { cursor: pointer; }
.sheet thead th.asc::after { content: " ▲"; font-size: 11px; } .sheet thead th.desc::after { content: " ▼"; font-size: 11px; }
.sheet tbody tr:nth-child(even) { background: #f7f9fb; }
.sheet tbody tr:hover { background: #eaf3fb; }
.sheet .desc-cell { white-space: normal; min-width: 240px; max-width: 360px; }
.sheet tr.overdue-row td:first-child { box-shadow: inset 4px 0 0 #c0392b; }

/* ---- 圖片檢視器（彈出對話框） ---- */
html.lb-lock, html.lb-lock body { overflow: hidden; }
.lb { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.97); display: grid; grid-template-columns: 56px 1fr 56px; grid-template-rows: auto 1fr; color: #fff; }
.lb[hidden] { display: none; }
.lb-bar { grid-column: 1 / 4; display: flex; align-items: center; gap: 12px; padding: 10px 12px calc(10px) 16px; font-size: 15px; }
.lb-cap { flex: 1; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-open { color: #fff; font-size: 14px; opacity: .8; padding: 8px; }
.lb-close { background: rgba(255,255,255,.15); color: #fff; border: 0; width: 44px; height: 44px; border-radius: 22px; font-size: 20px; cursor: pointer; }
.lb-stage { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: center; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.lb-img { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity .15s; touch-action: pinch-zoom; user-select: none; }
.lb-img.lb-loading { opacity: .3; }
.lb-nav { grid-row: 2; align-self: center; justify-self: center; width: 48px; height: 72px; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 12px; font-size: 38px; line-height: 1; cursor: pointer; }
.lb-nav[hidden] { display: none; }
.lb-prev { grid-column: 1; } .lb-next { grid-column: 3; }
@media (max-width: 600px) {
  .lb { grid-template-columns: 40px 1fr 40px; }
  .lb-nav { width: 36px; height: 64px; font-size: 32px; }
}
.photos a { cursor: zoom-in; }

/* ---- 判定：負責工程師下拉（可複選） ---- */
.msel { position: relative; }
.msel summary { list-style: none; cursor: pointer; min-height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: 16px; }
.msel summary::-webkit-details-marker { display: none; }
.msel summary::after { content: "▾"; margin-left: 8px; opacity: .6; }
.msel[open] summary { border-color: var(--navy); }
.msel .msel-label.empty { color: #8a96a0; }
.msel-panel { margin-top: 6px; border: 1px solid var(--line); border-radius: 12px; background: #fff; max-height: 260px; overflow: auto; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.msel-opt { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; border-bottom: 1px solid #eef1f4; cursor: pointer; font-size: 16px; }
.msel-opt:last-child { border-bottom: 0; }
.msel-opt input { width: 20px; height: 20px; }

/* ---- 工程師回覆 ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .two-col { grid-template-columns: 1fr; } }
.reply-item { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.reply-item:last-of-type { border-bottom: 0; }
.rp-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.rp-photos .rp-ph { position: relative; }
.rp-photos img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.rp-photos button { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 16px; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 16px; cursor: pointer; }

/* ---- 收件夾 ---- */
.nav-inbox { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.bubble { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 999px; background: #e5483b; color: #fff; font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; }
.bubble[hidden] { display: none; }
.inbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.inbox-list li { background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.inbox-list li a { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 12px 14px; color: inherit; text-decoration: none; }
.inbox-unread { border-left: 5px solid #e5483b !important; }
.inbox-unread b { font-weight: 800; }
.inbox-done { opacity: .6; }
.inbox-note { flex-basis: 100%; font-size: 14px; color: #8a2d24; }
.inbox-time { margin-left: auto; font-size: 13px; }
