:root {
  --ink: #16212C;
  --navy: #0F2A47;
  --navy-2: #1B4B7A;
  --blue: #0E5BB5;
  --blue-press: #0B4A96;
  --bench: #EDF0F3;
  --panel: #FFFFFF;
  --line: #D3D9E0;
  --line-soft: #E4E8ED;
  --text: #16212C;
  --muted: #5B6875;
  --ok: #148A55;
  --ok-bg: #E3F4EB;
  --bad: #C9372A;
  --bad-bg: #FBE7E4;
  --idle: #C3CAD2;
  --warn: #B7791F;
  --warn-bg: #FFF4DB;
  --radius: 6px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bench: #0E141B; --panel: #17202A; --line: #2B3745; --line-soft: #222D39;
    --text: #E8EDF2; --muted: #93A1B0; --ok: #35C987; --ok-bg: #12362A; --bad: #FF6B5E; --bad-bg: #3B1B18;
    --idle: #3A4655; --warn-bg: #3A2D12; --warn: #E0A93B; --blue: #4A98F0; --blue-press: #3A84DA;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bench); color: var(--text); font-family: var(--font);
  font-size: 16px; line-height: 1.5; min-height: 100vh; min-height: 100dvh;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
input, textarea, select { -webkit-user-select: text; user-select: text; font: inherit; color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media print { body * { display: none !important; } body::before { content: "不可列印"; display: block; } }

/* ---------- 浮水印 ---------- */
#wm { position: fixed; inset: 0; pointer-events: none; z-index: 90; opacity: .07; background-repeat: repeat; }
@media (prefers-color-scheme: dark) { #wm { opacity: .1; } }

/* ---------- 頂欄 ---------- */
.bar {
  position: sticky; top: 0; z-index: 30; background: var(--navy); color: #fff;
  padding-top: env(safe-area-inset-top);
  border-bottom: 3px solid var(--navy-2);
}
.bar-in { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 16px; }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; color: inherit; text-align: left; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand b { display: block; font-size: 16px; letter-spacing: .04em; line-height: 1.15; }
.brand small { display: block; font-size: 12px; opacity: .72; line-height: 1.2; }
.grow { flex: 1; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; opacity: .9; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: #2FD08A; box-shadow: 0 0 0 3px rgba(47,208,138,.25); }
.lamp.stale { background: #F0B429; box-shadow: 0 0 0 3px rgba(240,180,41,.25); }
.lamp.fail { background: #FF6B5E; box-shadow: 0 0 0 3px rgba(255,107,94,.28); }
.bar select, .bar .chip {
  background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius); padding: 6px 10px; min-height: 36px; font-size: 14px;
}
.bar select option { color: #111; }
.bar .chip:hover { background: rgba(255,255,255,.18); }
.who { font-size: 13px; opacity: .92; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .who, .sync span { display: none; } .brand small { display: none; } }

/* ---------- 版面 ---------- */
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px calc(40px + env(safe-area-inset-bottom)); }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 4px; font-weight: 700; letter-spacing: .02em; }
h2 { font-size: 15px; margin: 0; font-weight: 700; }
.sub { color: var(--muted); font-size: 14px; margin: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stack > * + * { margin-top: 16px; }

/* ---------- 登入 ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); background: var(--navy); }
.login-side { display: none; }
.login-main { display: flex; flex-direction: column; justify-content: center; padding: 24px 20px; background: var(--bench); }
.login-card { width: 100%; max-width: 380px; margin: 0 auto; }
.login-card .mark { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 18px; display: block; }
.field { display: block; margin-top: 16px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); font-size: 16px;
}
.input:focus { border-color: var(--blue); outline: 3px solid color-mix(in srgb, var(--blue) 25%, transparent); outline-offset: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: var(--radius); border: 1.5px solid transparent; font-weight: 700; background: var(--blue); color: #fff;
}
.btn:hover { background: var(--blue-press); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 22px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--line-soft); }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 14px; }
.msg { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; background: var(--bad-bg); color: var(--bad); border-left: 4px solid var(--bad); }
.msg.info { background: var(--warn-bg); color: var(--warn); border-left-color: var(--warn); }
.hint { margin-top: 14px; font-size: 13px; color: var(--muted); }
.login-foot { max-width: 380px; margin: 28px auto 0; width: 100%; display: flex; gap: 12px; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); }
.login-foot select { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; min-height: 36px; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px 0; font-size: 13px; }
@media (min-width: 900px) {
  .login-wrap { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .login-side { display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; color: #fff; position: relative; overflow: hidden; }
  .login-side::before { content: ""; position: absolute; inset: 0;
    background: repeating-linear-gradient(90deg, rgba(255,255,255,.045) 0 1px, transparent 1px 48px),
                repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 48px); }
  .login-side > * { position: relative; }
  .login-side strong { font-size: 30px; letter-spacing: .06em; display: block; }
  .login-side span { opacity: .75; }
  .strip-demo { display: flex; gap: 3px; margin-bottom: 28px; }
  .strip-demo i { width: 14px; height: 40px; background: #2FD08A; border-radius: 2px; opacity: .9; }
  .strip-demo i.n { background: #3C5875; }
  .strip-demo i.b { background: #FF6B5E; }
}

/* ---------- 大廳 ---------- */
.strip-card { padding: 18px; }
.strip-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.strip-head .big { font-size: 30px; font-weight: 700; line-height: 1; }
.strip { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.strip-area { display: flex; gap: 3px; }
.seg { width: 12px; height: 30px; border-radius: 2px; background: var(--idle); border: 0; padding: 0; }
.seg.ok { background: var(--ok); } .seg.bad { background: var(--bad); }
@media (max-width: 560px) { .seg { width: 9px; height: 26px; } }
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 16px; font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 2px; background: var(--idle); display: inline-block; }
.legend i.ok { background: var(--ok); } .legend i.bad { background: var(--bad); }
.mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.mod {
  text-align: left; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  border-left: 5px solid var(--navy-2); min-height: 88px; display: block; width: 100%;
}
.mod:hover:not(:disabled) { border-color: var(--blue); border-left-color: var(--blue); }
.mod:disabled { opacity: .6; cursor: default; border-left-color: var(--idle); }
.mod b { display: block; font-size: 17px; }
.mod small { display: block; color: var(--muted); margin-top: 2px; font-size: 13px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--line-soft); color: var(--muted); margin-left: 8px; font-weight: 600; vertical-align: 1px; }

/* ---------- 檢點板 ---------- */
.tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.seg-ctl { display: inline-flex; border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg-ctl button { border: 0; background: none; padding: 0 14px; min-height: 40px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg-ctl button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.date-in { min-height: 40px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.areas > section { margin-top: 14px; }
.area-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); gap: 8px; flex-wrap: wrap; }
.area-head .own { font-size: 13px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; padding: 12px; }
.tile {
  position: relative; text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px 8px 14px; min-height: 64px; overflow: hidden;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--idle); }
.tile.ok::before { background: var(--ok); } .tile.bad::before { background: var(--bad); }
.tile.bad { background: var(--bad-bg); border-color: var(--bad); }
.tile:hover { border-color: var(--blue); }
.tile b { display: block; font-size: 16px; line-height: 1.2; word-break: break-all; }
.tile small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.ok small { color: var(--ok); font-weight: 600; } .tile.bad small { color: var(--bad); font-weight: 700; }
.tile.dim { opacity: .35; }
.banner { padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); border-left: 4px solid var(--warn); font-size: 14px; margin-top: 14px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- 檢點視窗 ---------- */
.dlg-back { position: fixed; inset: 0; z-index: 60; background: rgba(10,20,30,.55); display: flex; align-items: flex-end; justify-content: center; }
.dlg {
  width: 100%; max-width: 640px; max-height: 94dvh; max-height: 94vh; display: flex; flex-direction: column; background: var(--panel);
  border-radius: 14px 14px 0 0; border: 1px solid var(--line); overflow: hidden;
}
@media (min-width: 700px) { .dlg-back { align-items: center; } .dlg { border-radius: var(--radius); max-height: 90vh; } }
.dlg-head { padding: 14px 16px; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px; }
.dlg-head b { font-size: 20px; display: block; line-height: 1.2; }
.dlg-head small { opacity: .75; }
.dlg-head button { margin-left: auto; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: var(--radius); min-height: 40px; padding: 0 14px; }
.dlg-body { padding: 14px 16px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.dlg-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; background: var(--panel); }
.dlg-foot .btn:last-child { flex: 1; }
.grp { margin-top: 14px; }
.grp > h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.item p { margin: 0; flex: 1; font-size: 15px; line-height: 1.4; }
.vx { display: inline-flex; flex: none; border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.vx button { width: 54px; min-height: 44px; border: 0; background: var(--panel); font-weight: 800; font-size: 17px; color: var(--muted); }
.vx button.v[aria-pressed="true"] { background: var(--ok); color: #fff; }
.vx button.x[aria-pressed="true"] { background: var(--bad); color: #fff; }
.vx button + button { border-left: 1.5px solid var(--line); }
textarea.input { min-height: 84px; resize: vertical; }
.toolrow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

/* ---------- 其他 ---------- */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); z-index: 100; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center; border-left: 5px solid var(--ok); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { border-left-color: var(--bad); }
.center { min-height: 60vh; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 24px; }
.spin { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: sp .8s linear infinite; display: inline-block; vertical-align: -5px; margin-right: 8px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } #toast { transition: none; } }

/* ---------- 作業員首頁、派工表 ---------- */
.sub-h { margin: 18px 0 0; font-size: 14px; color: var(--muted); font-weight: 700; }
.tiles.flat { padding: 10px 0 0; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); margin-left: 6px; vertical-align: 1px; }
.dispatch .dis-head, .dispatch .dis-row { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(130px, 1.6fr) 64px 76px; gap: 10px; align-items: center; padding: 10px 14px; }
.dispatch .dis-head { font-size: 13px; border-bottom: 1px solid var(--line-soft); padding-top: 6px; padding-bottom: 6px; }
.dispatch .dis-row { border-bottom: 1px solid var(--line-soft); }
.dispatch .dis-row:last-child { border-bottom: 0; }
.dis-area small, .dis-owner small { display: block; font-size: 12px; }
.dis-owner { font-weight: 600; }
.dis-prog { text-align: right; font-weight: 700; }
@media (max-width: 560px) {
  .dispatch .dis-head { display: none; }
  .dispatch .dis-row { grid-template-columns: 1fr auto; grid-template-areas: "a p" "o b"; row-gap: 6px; }
  .dis-area { grid-area: a; } .dis-prog { grid-area: p; } .dis-owner { grid-area: o; } .dispatch .dis-row .btn { grid-area: b; }
}

.hidden { display: none !important; }
.dis-single { margin-top: 4px; font-weight: 500; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.chk { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 10px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--panel); cursor: pointer; }
.chk:has(input:checked) { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 10%, var(--panel)); }
.chk input { width: 20px; height: 20px; accent-color: var(--blue); flex: none; }
.chk b { display: block; font-size: 15px; line-height: 1.2; }
.chk small { display: block; font-size: 12px; color: var(--muted); }

/* ---------- 叫修單 ---------- */
.tile.hastk { border-color: var(--warn); }
.tkchip { display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 99px; line-height: 18px; background: var(--warn-bg); color: var(--warn); max-width: 100%; white-space: normal; line-height: 16px; padding-top: 1px; padding-bottom: 1px; border-radius: 9px; }
.tkchip.tk-wait { background: var(--bad-bg); color: var(--bad); }
.tkchip.tk-test { background: color-mix(in srgb, var(--blue) 14%, var(--panel)); color: var(--blue); }
.tblock { margin-top: 0; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; padding: 12px; }
.tcard { border: 1.5px solid var(--line); border-left-width: 6px; border-radius: var(--radius); padding: 10px 12px; background: var(--panel); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.tcard:hover { border-color: var(--blue); }
.tcard.urg { border-left-color: var(--warn); } .tcard.down { border-left-color: var(--bad); background: var(--bad-bg); }
.tc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tc-head b { font-size: 17px; }
.tc-desc { margin: 0; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tc-full { margin: 0 0 10px; font-size: 16px; white-space: pre-wrap; }
.tc-meta { font-size: 12px; } .tc-act { margin-top: 6px; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 9px; border-radius: 99px; background: var(--line-soft); color: var(--muted); }
.pill.p-wait { background: var(--bad-bg); color: var(--bad); } .pill.p-fix { background: var(--warn-bg); color: var(--warn); }
.pill.p-test { background: color-mix(in srgb, var(--blue) 14%, var(--panel)); color: var(--blue); } .pill.p-done { background: var(--ok-bg); color: var(--ok); }
.pill.p-ud { background: var(--bad); color: #fff; } .pill.p-ug { background: var(--warn); color: #fff; }
.tcount { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line-soft); }
.tcount > div { padding: 12px 14px; text-align: left; } .tcount b { display: block; font-size: 26px; line-height: 1.1; } .tcount span { font-size: 13px; color: var(--muted); }
.tkbanner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 10px; }
.kv { display: flex; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; } .kv > span:first-child { flex: 0 0 84px; }
.tl { list-style: none; margin: 8px 0 0; padding: 0; border-left: 3px solid var(--line); }
.tl li { padding: 4px 0 8px 12px; position: relative; font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tl li::before { content: ""; position: absolute; left: -8px; top: 9px; width: 11px; height: 11px; border-radius: 50%; background: var(--navy-2); border: 2px solid var(--panel); }
.tl li p { flex-basis: 100%; margin: 0; color: var(--text); }
details.tblock > summary { cursor: pointer; list-style: none; } details.tblock > summary::-webkit-details-marker { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip-x { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); font-size: 14px; font-weight: 600; }
.chip-x button { border: 0; background: transparent; color: inherit; width: 28px; height: 28px; border-radius: 50%; font-size: 18px; line-height: 1; cursor: pointer; }
.chip-x button:hover { background: rgba(0,0,0,.08); }
