/* 豐譽內部視覺規則：暖白底、teal 主色、gold 副色、Noto Sans TC、線條圖示 */
:root {
  --teal: #007A87; --teal-d: #00555E; --teal-l: #e1eef0;
  --gold: #BE8B55; --gold-d: #8a6334; --gold-l: #f1e7d6;
  --bg: #F5F1E8; --bg2: #EFE9DC; --card: #ffffff;
  --top: #e6f0ef; --top-line: #d6e4e2;
  --rule: #E3DCCB; --border: #d8cfb9;
  --text: #3a4233; --muted: #7a7b6d; --faint: #a39f8e;
  --danger: #b3261e;
  --sh-menu: 0 10px 28px rgba(60, 66, 51, .16);
  --sh-tag: 0 1px 4px rgba(60, 66, 51, .2);
  --f: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --panel-w: 392px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--f); color: var(--text); background: var(--bg);
  line-height: 1.6; -webkit-font-smoothing: antialiased; overflow: hidden;
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
.ico { width: 18px; height: 18px; flex: none; }

/* ---------- 頂列 ---------- */
.topbar {
  flex: none; height: 64px; display: flex; align-items: center; gap: 24px; padding: 0 20px;
  background: var(--top); border-bottom: 1px solid var(--top-line); position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 34px; height: 34px; position: relative; flex: none; }
.mark i { position: absolute; width: 22px; height: 22px; border-radius: 6px; }
.mark i:first-child { left: 0; top: 0; background: #00748D; }
.mark i:last-child { right: 0; bottom: 0; background: var(--gold); mix-blend-mode: multiply; }
.brand-t { display: flex; flex-direction: column; line-height: 1.25; }
.brand-t b { font-size: 17px; font-weight: 700; color: var(--teal-d); white-space: nowrap; }
.brand-t span { font-size: 12px; color: var(--muted); }
.project { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; padding-left: 24px; border-left: 1px solid var(--top-line); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .16em; color: var(--gold-d); }
.project-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.date-field {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--border); color: var(--teal-d);
}
.date-field { position: relative; cursor: pointer; }
.date-field input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; opacity: 0; cursor: pointer; }
.date-field input { border: 0; background: none; font: 600 14px var(--f); color: var(--text); outline: none; width: 128px; }
.date-field:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-l); }
.wd { font-size: 13px; color: var(--muted); margin-left: -4px; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: 11px; font-size: 11px; font-weight: 800; letter-spacing: .06em; white-space: nowrap; }
.pill.demo { background: var(--gold); color: #fff; box-shadow: var(--sh-tag); }

/* ---------- 主畫面 ---------- */
.stage { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr var(--panel-w); }
.viewport { position: relative; isolation: isolate; overflow: hidden; background: #efe9dc; touch-action: none; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.label-layer { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* 3D 標籤 */
.rtag {
  pointer-events: auto; display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
  border-radius: 20px; border: 1.5px solid color-mix(in oklch, var(--c) 45%, white);
  background: #fff; box-shadow: var(--sh-tag); white-space: nowrap; text-align: left;
  margin-bottom: 6px; translate: 0 calc(var(--lift, 0px) * -1);
  transition: translate .18s ease, border-color .18s ease;
}
.rtag::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 8px; height: 8px; margin-left: -4px;
  background: #fff; border-right: 1.5px solid color-mix(in oklch, var(--c) 45%, white); border-bottom: 1.5px solid color-mix(in oklch, var(--c) 45%, white);
  transform: rotate(45deg);
}
.rtag:hover, .rtag.on { border-color: var(--c); }
.rtag.on::after { border-color: var(--c); }
.rtag-ico { width: 28px; height: 28px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; }
.rtag-ico .ico { width: 16px; height: 16px; }
.rtag-t { display: flex; flex-direction: column; line-height: 1.2; }
.rtag-t b { font-size: 13px; font-weight: 700; color: var(--text); }
.rtag-t small { font-size: 11px; color: var(--muted); }
.gb {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; border: 1.5px solid var(--gold-d); color: var(--gold-d);
  font: 600 11px var(--mono); box-shadow: var(--sh-tag);
}

/* 樓層索引 */
.rail {
  position: absolute; left: 16px; top: 16px; bottom: 84px; width: 104px; z-index: 5;
  display: flex; flex-direction: column; background: rgba(255, 255, 255, .92);
  border: 1px solid var(--rule); border-radius: 16px; box-shadow: var(--sh-menu); overflow: hidden;
}
.rail-h { flex: none; font-size: 12px; font-weight: 700; letter-spacing: .16em; color: var(--gold-d); padding: 10px 14px 6px; border-bottom: 1px solid var(--rule); }
.rail-list { flex: 1; overflow-y: auto; padding: 4px 6px 8px; scrollbar-width: thin; }
.fl {
  width: 100%; display: flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border: 0; background: none; border-radius: 8px; text-align: left; transition: background .18s ease;
}
.fl.minor { height: 15px; }
.fl.minor .fl-n { font-size: 9.5px; color: var(--faint); }
.fl-n { font: 500 11.5px var(--mono); color: var(--muted); width: 50px; flex: none; }
.fl.has .fl-n { color: var(--text); font-weight: 600; }
.fl-d { display: flex; gap: 3px; align-items: center; }
.fl-d i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.fl-d em { font: 600 10px var(--mono); color: var(--muted); font-style: normal; }
.fl:hover { background: var(--bg2); }
.fl.on { background: var(--teal); }
.fl.on .fl-n { color: #fff; }
.fl.on .fl-d i { box-shadow: 0 0 0 1.5px #fff; }

/* 工具列 */
.toolbar {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 5px; border-radius: 22px;
  background: #fff; border: 1px solid var(--rule); box-shadow: var(--sh-menu);
}
.seg { display: flex; gap: 2px; padding: 2px; background: var(--bg2); border-radius: 18px; }
.seg button, .tb {
  height: 36px; border: 0; background: none; border-radius: 16px; display: flex; align-items: center; gap: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--muted); transition: background .18s ease, color .18s ease;
}
.seg button { padding: 0 14px; }
.seg button[aria-pressed=true] { background: var(--teal); color: #fff; }
.seg button:not([aria-pressed=true]):hover { color: var(--teal-d); background: #fff; }
.tb-tools { display: flex; gap: 2px; padding-right: 2px; }
.tb { width: 38px; justify-content: center; }
.tb:hover { background: var(--bg2); color: var(--teal-d); }
.tb[aria-pressed=true] { color: var(--teal); background: var(--teal-l); }

.loader {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg); color: var(--muted); font-size: 14px; transition: opacity .25s ease;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader.error { color: var(--danger); }
.loader.error .spin { display: none; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--rule); border-top-color: var(--teal); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 面板 ---------- */
.panel { position: relative; background: var(--bg); border-left: 1px solid var(--rule); min-height: 0; display: flex; flex-direction: column; }
.sheet-handle { display: none; }
.panel-body { flex: 1; overflow-y: auto; padding: 20px 20px 28px; display: flex; flex-direction: column; gap: 22px; scrollbar-width: thin; }
.sec { display: flex; flex-direction: column; gap: 12px; }
.sec-head { display: flex; align-items: center; gap: 10px; }
.sec-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--teal-d); white-space: nowrap; }
.sec-head .rule { flex: 1; height: 1px; background: var(--rule); }
.count { min-width: 24px; height: 20px; padding: 0 7px; border-radius: 10px; background: var(--teal); color: #fff; font: 700 12px var(--mono); display: grid; place-items: center; }
.link { border: 0; background: none; color: var(--teal); font-size: 13px; font-weight: 600; padding: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--rule); border-radius: 18px; padding: 10px 12px; display: flex; flex-direction: column; line-height: 1.2; }
.stat b { font: 600 26px var(--mono); color: var(--teal-d); letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.warn b { color: var(--danger); }
.stat.mid b { color: var(--gold-d); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 36px; display: flex; align-items: center; gap: 6px; padding: 0 10px 0 4px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--bg2); font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background .18s ease, border-color .18s ease;
}
.chip-ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #cfc8b6; color: #fff; }
.chip-ico .ico { width: 15px; height: 15px; }
.chip-n { font: 600 12px var(--mono); color: var(--faint); }
.chip.on { background: #fff; border-color: color-mix(in oklch, var(--c) 40%, white); color: var(--text); }
.chip.on .chip-ico { background: var(--c); }
.chip.on .chip-n { color: var(--c); }
.chip:hover { border-color: var(--c); }

.fgroup { display: flex; flex-direction: column; gap: 8px; }
.fg-name { font: 600 12px var(--mono); color: var(--gold-d); letter-spacing: .06em; padding-left: 4px; }
.wcard {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px 12px 12px; text-align: left;
  background: var(--card); border: 1px solid var(--rule); border-radius: 18px;
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.wcard:hover { border-color: var(--c); transform: translateY(-2px); box-shadow: 0 10px 22px rgba(60, 66, 51, .1); }
.leaf {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center; color: var(--c);
  background: color-mix(in oklch, var(--c) 13%, white);
  border-radius: 5% 95% 10% 90% / 85% 15% 85% 15%;
}
.leaf.lg { width: 56px; height: 56px; }
.leaf.lg .ico { width: 26px; height: 26px; }
.wc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.wc-main b { font-size: 12px; font-weight: 700; color: var(--c); }
.wc-main span { font-size: 14.5px; font-weight: 700; color: var(--text); }
.wc-main small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl { flex: none; height: 22px; min-width: 30px; padding: 0 8px; border-radius: 11px; font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; }
.lvl.l3 { background: #fbe4e1; color: var(--danger); }
.lvl.l2 { background: var(--gold-l); color: var(--gold-d); }
.lvl.l1 { background: var(--teal-l); color: var(--teal-d); }
.empty { margin: 0; padding: 22px; text-align: center; color: var(--muted); font-size: 13px; background: var(--bg2); border-radius: 18px; }
.skip { margin: 0; display: flex; gap: 8px; font-size: 12px; color: var(--danger); line-height: 1.55; }

/* 詳細 */
.back { flex: none; align-self: flex-start; display: flex; align-items: center; gap: 2px; height: 36px; padding: 0 12px 0 6px; border-radius: 18px; border: 1px solid var(--border); background: #fff; font-size: 13.5px; font-weight: 600; color: var(--teal-d); }
.back:hover { border-color: var(--teal); }
.dhead { display: flex; gap: 14px; align-items: center; }
.dhead-t { flex: 1; min-width: 0; }
.dhead .eyebrow { color: var(--c); letter-spacing: .1em; }
.dhead h2 { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.35; text-wrap: pretty; }
.ddesc { margin: -8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.55; }
.fields { margin: 0; background: #fff; border: 1px solid var(--rule); border-radius: 18px; padding: 4px 16px; }
.fields div { display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.fields div:last-child { border-bottom: 0; }
.fields dt { font-size: 12.5px; color: var(--muted); }
.fields dd { margin: 0; font-size: 14px; font-weight: 600; display: flex; flex-direction: column; align-items: flex-start; }
.fields dd small { font-size: 12px; font-weight: 400; color: var(--muted); }
.mono { font-family: var(--mono); }
.check { list-style: none; margin: -8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.check li { display: flex; gap: 10px; font-size: 13.5px; line-height: 1.5; }
.check .ico { width: 16px; height: 16px; color: var(--teal); margin-top: 2px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; height: 40px; border-radius: 20px; border: 0; background: var(--teal); color: #fff; font-size: 13.5px; font-weight: 600; }
.btn:hover { background: var(--teal-d); }

/* ---------- 編輯：按鈕、表單、區域 ---------- */
[hidden] { display: none !important; }
.actions, .row { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn, .row .btn { flex: 1; }
.btn { padding: 0 16px; white-space: nowrap; }
.btn .ico { width: 16px; height: 16px; }
.btn:disabled { background: #cfc8b6; cursor: default; }
.btn.ghost { background: #fff; color: var(--teal-d); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--teal); background: #fff; }
.btn.ghost.warn { color: var(--danger); }
.btn.ghost.warn:hover { border-color: var(--danger); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f1e18; }
.btn.sm { height: 36px; font-size: 13px; padding: 0 14px; }
.link.muted { color: var(--muted); align-self: flex-start; text-decoration: underline; text-underline-offset: 3px; }
.ptop { display: flex; align-items: center; gap: 12px; }
.ptop h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; color: var(--teal-d); }
.hint { margin: -6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.55; text-wrap: pretty; }
.tips { margin: 0; padding: 12px 16px 12px 30px; background: var(--bg2); border-radius: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.note { margin: 0; font-size: 12px; color: var(--muted); }
.floor-now { display: flex; align-items: baseline; gap: 10px; }
.floor-now b { font: 600 18px var(--mono); color: var(--text); }
.muted { color: var(--muted); font-size: 12.5px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 18px;
  border: 1px solid var(--border); background: #fff; color: var(--teal-d); font-size: 13px; font-weight: 600;
  transition: border-color .18s ease, background .18s ease;
}
.tool .ico { width: 22px; height: 22px; }
.tool:hover { border-color: var(--teal); }
.tool.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.zcard { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; background: #fff; border: 1px solid var(--rule); border-radius: 18px; transition: border-color .18s ease; }
.zcard.hl { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-l); }
.zcard.edit { padding: 12px; flex-direction: column; align-items: stretch; }
.zc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.zc-main b { font-size: 14.5px; }
.zc-main small { font-size: 12px; color: var(--muted); }
.zc-act { display: flex; gap: 2px; }
.tb.warn:hover { color: var(--danger); background: #fbe4e1; }
.confirm { flex-basis: 100%; display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 16px; background: #fbe4e1; }
.confirm p { margin: 0; font-size: 13px; color: var(--text); line-height: 1.55; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > span { font-size: 13px; font-weight: 600; color: var(--text); }
.fld em { font-style: normal; font-weight: 400; color: var(--faint); margin-left: 6px; font-size: 12px; }
.inp {
  height: 40px; width: 100%; padding: 0 14px; border-radius: 14px; border: 1px solid var(--border); background: #fff;
  font: 500 14px var(--f); color: var(--text); outline: none; transition: border-color .18s ease, box-shadow .18s ease;
}
.inp.mono { font-family: var(--mono); }
.inp:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-l); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 12px; align-items: baseline; font-size: 13px; color: var(--muted); }
.kv b { font: 600 15px var(--mono); color: var(--text); }
.typepick .chip { padding-right: 12px; }
.zsel { display: flex; flex-wrap: wrap; gap: 6px; }
.zpill { display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px 0 12px; border-radius: 15px; border: 0; background: var(--c); color: #fff; font-size: 12.5px; font-weight: 600; }
.zpill .ico { width: 14px; height: 14px; }
.zlist { display: flex; flex-direction: column; gap: 6px; }
.zrow { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px 0 10px; border-radius: 14px; border: 1px solid var(--rule); background: #fff; text-align: left; font-size: 14px; font-weight: 600; transition: border-color .18s ease; }
.zrow span { flex: 1; }
.zrow small { font: 500 12px var(--mono); color: var(--muted); }
.zrow .box { width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--border); display: grid; place-items: center; color: #fff; flex: none; }
.zrow .box .ico { width: 14px; height: 14px; }
.zrow.on { border-color: var(--c); }
.zrow.on .box { background: var(--c); border-color: var(--c); }
.zrow:hover { border-color: var(--c); }
.show-m { display: none; }

.actionbar {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 18px; border-radius: 22px; max-width: calc(100% - 32px);
  background: #fff; border: 1px solid var(--rule); box-shadow: var(--sh-menu);
}
.ab-info { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ab-info.err { color: var(--danger); white-space: normal; }
.actionbar .tb:disabled { color: var(--faint); background: none; cursor: default; }

.zlabel {
  pointer-events: none; display: flex; flex-direction: column; align-items: center; line-height: 1.2;
  padding: 4px 10px; border-radius: 12px; background: #fff; border: 1px solid color-mix(in oklch, var(--c) 35%, white);
  box-shadow: var(--sh-tag); white-space: nowrap; text-align: center;
}
.zlabel.pick { pointer-events: auto; cursor: pointer; }
.zlabel b { font-size: 12px; font-weight: 700; color: var(--text); }
.zlabel small { font-size: 10.5px; color: var(--muted); }
.zlabel.on { background: var(--c); border-color: var(--c); }
.zlabel.on b, .zlabel.on small { color: #fff; }
.dimtag { padding: 2px 8px; border-radius: 10px; background: var(--text); color: #fff; font: 600 11.5px var(--mono); white-space: nowrap; pointer-events: none; }

.toast {
  position: fixed; left: 50%; top: 80px; z-index: 50; display: flex; align-items: center; gap: 10px;
  padding: 10px 18px 10px 10px; border-radius: 22px; background: var(--text); color: #fff; font-size: 13.5px; font-weight: 500;
  box-shadow: 0 12px 32px rgba(60, 66, 51, .34); transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast .ico { width: 26px; height: 26px; padding: 5px; border-radius: 50%; background: var(--teal); }
.toast.warn .ico { background: var(--danger); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 手機 ---------- */
@media (max-width: 767px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .project { display: none; }
  .brand-t b { font-size: 15px; }
  .top-right { gap: 8px; }
  .date-field { height: 36px; padding: 0 10px; }
  .date-field input { width: 118px; font-size: 13px; }
  .date-field .ico, .wd { display: none; }
  .pill.demo { display: none; }
  .stage { display: block; position: relative; }
  .viewport { position: absolute; inset: 0; }
  .rail { left: 10px; top: 10px; bottom: auto; max-height: calc(100% - 230px); width: 92px; }
  .rail-h { padding: 8px 12px 4px; }
  .rail:not(.editing) .fl:not(.has):not(.on) { display: none; }
  .rail.editing { width: 78px; max-height: calc(100% - 250px); }
  .rail.editing .fl-d { display: none; }
  .show-m { display: flex; }
  .actionbar { bottom: 146px; }
  .toast { top: 66px; max-width: calc(100% - 32px); }
  .fl { height: 30px; }
  .fl-n { width: 44px; font-size: 11px; }
  .toolbar { bottom: 148px; padding: 4px; gap: 4px; }
  .seg button { padding: 0 10px; white-space: nowrap; gap: 4px; }
  .seg button span { font-size: 12.5px; }
  .tb { width: 34px; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; height: 72%; z-index: 8;
    border-left: 0; border-top: 1px solid var(--rule); border-radius: 18px 18px 0 0; box-shadow: 0 -10px 28px rgba(60, 66, 51, .16);
    transform: translateY(calc(100% - 132px)); transition: transform .25s ease;
  }
  .panel.open { transform: none; }
  .sheet-handle { display: grid; place-items: center; flex: none; height: 26px; border: 0; background: none; }
  .sheet-handle i { width: 40px; height: 4px; border-radius: 2px; background: var(--border); }
  .panel-body { padding: 0 16px 24px; gap: 18px; }
  .leaf.lg { width: 44px; height: 44px; }
  .dhead h2 { font-size: 17px; }
  .stat b { font-size: 22px; }
  .rtag { padding: 3px 10px 3px 3px; gap: 6px; }
  .rtag-ico { width: 24px; height: 24px; }
  .rtag-t b { font-size: 12px; }
  .rtag-t small { font-size: 10px; }
}
/* ---------- P3：多危害、資料維護 ---------- */
.rtag-icos { display: flex; }
.rtag-icos .rtag-ico + .rtag-ico { margin-left: -8px; box-shadow: 0 0 0 2px #fff; }
.wc-main b i { font-style: normal; }
.hz { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; background: #fff; border: 1px solid var(--rule); border-left: 4px solid var(--c); border-radius: 18px; }
.hz-h { display: flex; align-items: center; gap: 10px; }
.hz-h b { flex: 1; font-size: 14.5px; }
.hz .chip-ico { background: var(--c); }
.hz .ddesc, .hz .check { margin: 0; }
.top-right .btn.sm { height: 38px; }
.top-right .btn .ico { width: 16px; height: 16px; }

.maint {
  position: absolute; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; min-height: 0;
}
.m-head { flex: none; display: flex; align-items: center; gap: 18px; padding: 14px 24px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.m-head h2 { margin: 0; font-size: 19px; font-weight: 700; color: var(--teal-d); }
.m-tabs { display: flex; gap: 4px; padding: 3px; background: var(--bg2); border-radius: 18px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.m-tabs button { white-space: nowrap; flex: none; }
.m-tabs button { height: 36px; display: flex; align-items: center; gap: 6px; padding: 0 14px; border: 0; background: none; border-radius: 16px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.m-tabs button[aria-selected=true] { background: var(--teal); color: #fff; }
.m-tabs button:not([aria-selected=true]):hover { background: #fff; color: var(--teal-d); }
.m-tabs .ico { width: 16px; height: 16px; }
.m-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.m-bar { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 24px; background: #fbe4e1; font-size: 13.5px; font-weight: 600; }
.m-bar span { flex: 1; }
.m-body { flex: 1; min-height: 0; overflow: auto; padding: 18px 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.m-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; position: sticky; left: 0; }
.m-tools .grow { flex: 1; }
.m-dirty { font-size: 13px; font-weight: 700; color: var(--gold-d); }
.m-search { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 4px 0 12px; border: 1px solid var(--border); border-radius: 18px; background: #fff; color: var(--muted); }
.m-search .inp { border: 0; height: 32px; width: 180px; padding: 0 8px; box-shadow: none; }
.seg.sm button { height: 32px; padding: 0 12px; font-size: 13px; }
.inp.sm { height: 34px; padding: 0 10px; font-size: 13.5px; border-radius: 10px; }
textarea.inp.sm { height: auto; padding: 8px 10px; line-height: 1.55; resize: vertical; }
.inp.bad, .cell-pick.bad { border-color: var(--danger); box-shadow: 0 0 0 3px #fbe4e1; }
.inp:disabled { background: var(--bg2); color: var(--faint); }

/* 工項表 */
.wt { --cols: minmax(190px, 2fr) minmax(120px, 1.1fr) 136px 136px minmax(170px, 1.4fr) minmax(190px, 1.7fr) 116px 96px minmax(130px, 1fr) 76px;
  display: flex; flex-direction: column; min-width: 1450px; background: #fff; border: 1px solid var(--rule); border-radius: 18px; }
.wt-row { display: grid; grid-template-columns: var(--cols); gap: 8px; align-items: center; padding: 8px 12px 8px 10px; border-bottom: 1px solid var(--rule); border-left: 4px solid transparent; }
.wt-row:last-child { border-bottom: 0; }
.wt-h { position: sticky; top: -18px; z-index: 2; background: var(--bg2); border-radius: 18px 18px 0 0; font-size: 12.5px; font-weight: 700; color: var(--muted); padding-top: 10px; padding-bottom: 10px; }
.wt-row.st-new { border-left-color: var(--teal); background: #f4f9f9; }
.wt-row.st-mod { border-left-color: var(--gold); background: #fbf7ef; }
.wt-row.st-del { border-left-color: var(--danger); background: #fbf1ef; }
.wt-row.st-del .inp, .wt-row.st-del .cell-pick { text-decoration: line-through; }
.wt-act { display: flex; gap: 2px; justify-content: flex-end; }
.wt-err { grid-column: 1 / -1; margin: 0; display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--danger); }
.wt-err .ico { width: 15px; height: 15px; }
.cell-pick { width: 100%; min-height: 34px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 10px; background: #fff; text-align: left; }
.cell-pick:hover:not(:disabled) { border-color: var(--teal); }
.cell-pick em { font-style: normal; font-size: 13px; color: var(--faint); padding-left: 4px; }
.mini { display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 8px 0 4px; border-radius: 12px; font-style: normal; font-size: 12px; font-weight: 600; color: #fff; background: var(--c); white-space: nowrap; }
.mini .ico { width: 13px; height: 13px; }
.mini.area { background: var(--teal-l); color: var(--teal-d); padding: 0 8px; }

/* 彈出選單 */
.pop { position: absolute; z-index: 40; display: flex; flex-direction: column; gap: 6px; padding: 10px; overflow-y: auto; background: #fff; border: 1px solid var(--rule); border-radius: 16px; box-shadow: var(--sh-menu); }
.pop-h { display: flex; align-items: baseline; justify-content: space-between; font-size: 13.5px; font-weight: 700; color: var(--teal-d); padding: 2px 4px 4px; }
.pop .zrow { height: 38px; flex: none; }
.pop-list { display: flex; flex-direction: column; gap: 8px; }
.pop-st { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 8px; border-top: 1px solid var(--rule); }
.pop-st b { width: 100%; font: 600 12.5px var(--mono); color: var(--gold-d); }
.zrow.sm { height: 32px; padding: 0 10px 0 6px; font-size: 13px; gap: 6px; border-radius: 10px; --c: var(--teal); }
.zrow.sm .box { width: 18px; height: 18px; border-radius: 5px; }

/* 危害類別 */
.tt { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.tcard { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: #fff; border: 1px solid var(--rule); border-top: 4px solid var(--c); border-radius: 18px; }
.tcard.st-new { background: #f4f9f9; } .tcard.st-mod { background: #fbf7ef; } .tcard.st-del { opacity: .85; background: var(--bg2); }
.tc-top { display: grid; grid-template-columns: 40px 1.6fr 1fr auto; gap: 10px; align-items: end; }
.tc-mid { display: grid; grid-template-columns: 72px 1fr auto 1fr; gap: 10px; }
.fld.chk { align-items: center; }
.fld.chk input { width: 22px; height: 22px; margin: 6px 0; accent-color: var(--teal); }
.chip-ico.big { width: 40px; height: 40px; background: var(--c); color: #fff; }
.chip-ico.big .ico { width: 20px; height: 20px; }
.inp.color { padding: 2px 4px; }
.tc-act { padding-bottom: 2px; }
.tc-act .tb:disabled { color: var(--faint); background: none; cursor: not-allowed; }

/* 登入 */
.login { flex: 1; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; background: #fff; border: 1px solid var(--rule); border-radius: 26px; box-shadow: var(--sh-menu); }
.login-card h2 { margin: 0; font-size: 19px; font-weight: 700; color: var(--teal-d); }
.login-card .leaf { color: var(--teal); }
.login-card .link { align-self: center; }

@media (max-width: 767px) {
  .top-right .btn.sm span { display: none; }
  .m-head { padding: 10px 16px; gap: 10px; }
  .m-right .muted { display: none; }
  .m-body { padding: 12px 16px 24px; }
  .m-search .inp { width: 120px; }
  /* 工項表在手機改成卡片 */
  .wt { min-width: 0; background: none; border: 0; gap: 10px; }
  .wt-h { display: none; }
  .wt-row { grid-template-columns: 1fr 1fr; background: #fff; border: 1px solid var(--rule); border-left-width: 4px; border-radius: 18px; padding: 12px; }
  .wt-row > span[data-l] { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .wt-row > span[data-l]::before { content: attr(data-l); font-size: 11.5px; font-weight: 600; color: var(--muted); }
  .wt-row > span[data-l="工項名稱"], .wt-row > span[data-l="危害因子"], .wt-row > span[data-l="施工樓層／區域"], .wt-row > span[data-l="備註"] { grid-column: 1 / -1; }
  .wt-act { grid-column: 1 / -1; }
  .tt { grid-template-columns: 1fr; }
  .tc-top { grid-template-columns: 40px 1fr 1fr auto; }
}

.sec-head h2.danger { color: var(--danger); }
.count.danger { background: var(--danger); }
.ccard { display: flex; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; border-radius: 18px; border: 1px solid #f0c9c4; background: #fdf1ef; transition: border-color .18s ease; }
.ccard.l2 { border-color: var(--gold-l); background: #fbf6ec; }
.ccard:hover { border-color: var(--danger); }
.cc-ico { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--danger); color: #fff; }
.ccard.l2 .cc-ico { background: var(--gold); }
.cc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; line-height: 1.4; }
.cc-main b { font-size: 14px; color: var(--danger); }
.ccard.l2 .cc-main b { color: var(--gold-d); }
.cc-main span { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-main span i { font-style: normal; font-weight: 600; color: var(--gold-d); margin-right: 8px; }
.cc-main small { font-size: 12px; color: var(--muted); }
.notice { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--gold-l); background: #fbf6ec; color: var(--gold-d); font-size: 13px; font-weight: 600; text-align: left; }
.src { font-style: normal; font-weight: 600; font-size: 11px; color: var(--muted); background: var(--bg2); border-radius: 8px; padding: 1px 6px; margin-left: 6px; }
.rtag.warn { border-color: var(--danger); box-shadow: 0 0 0 3px #f6d5d1, var(--sh-tag); }
.rtag.warn::after { border-color: var(--danger); }

.wt-row .nm { display: flex; align-items: center; gap: 6px; }
.wt-row .nm .src { margin: 0; flex: none; }
.wt-row.pend { box-shadow: inset 0 0 0 2px #f0c9c4; }
.rt { display: grid; grid-template-columns: repeat(auto-fill, minmax(560px, 1fr)); gap: 8px; }
.rrow { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; background: #fff; border: 1px solid var(--rule); border-left: 4px solid transparent; border-radius: 14px; }
.rrow.st-new { border-left-color: var(--teal); } .rrow.st-mod { border-left-color: var(--gold); } .rrow.st-del { border-left-color: var(--danger); opacity: .7; }
.hzts { display: flex; flex-wrap: wrap; gap: 4px; }
.hzt { display: inline-flex; align-items: center; gap: 3px; height: 28px; padding: 0 9px 0 6px; border-radius: 14px; border: 1px solid var(--border); background: #fff; font-size: 12.5px; font-weight: 600; color: var(--faint); }
.hzt .ico { width: 14px; height: 14px; }
.hzt.on { background: var(--c); border-color: var(--c); color: #fff; }
.mt { display: flex; flex-direction: column; gap: 6px; }
.mrow { display: grid; grid-template-columns: minmax(240px, 2fr) 1fr 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; background: #fff; border: 1px solid var(--rule); border-radius: 14px; font-size: 13px; }
.mrow > span { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.ilog { background: #fff; border: 1px solid var(--rule); border-radius: 16px; overflow: hidden; }
.il-h { width: 100%; display: flex; align-items: center; gap: 18px; padding: 12px 16px; border: 0; background: none; text-align: left; font-size: 13.5px; }
.il-h b { font-size: 14.5px; }
.il-h .bad, .il-r.bad { color: var(--danger); }
.il-h .ico { margin-left: auto; transform: rotate(180deg); transition: transform .18s ease; color: var(--muted); }
.ilog.open .il-h .ico { transform: none; }
.il-d { border-top: 1px solid var(--rule); padding: 6px 16px 12px; display: flex; flex-direction: column; }
.il-r { display: grid; grid-template-columns: 36px minmax(260px, 2fr) 1fr 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--rule); font-size: 13px; align-items: center; }
.il-r:last-child { border-bottom: 0; }
.il-r > span:last-child { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
@media (max-width: 767px) {
  .rt { grid-template-columns: 1fr; } .rrow { grid-template-columns: 1fr auto; } .rrow .hzts { grid-column: 1 / -1; }
  .mrow, .il-r { grid-template-columns: 1fr; } .il-h { flex-wrap: wrap; gap: 6px 14px; }
}

.more { display: flex; flex-direction: column; gap: 8px; }
.more summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--gold-d); padding: 4px 2px; }
.more[open] summary { margin-bottom: 8px; }
.more .ccard + .ccard { margin-top: 8px; }

/* 整棟／分層檢視：建物左右兩側的樓層標籤 */
.callout-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.callout-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.callout-lines polyline { fill: none; stroke-width: 1.5; opacity: .85; }
.callout {
  position: absolute; left: 0; top: 0; pointer-events: auto; display: grid; grid-template-columns: auto 1fr; gap: 0 10px; align-items: center;
  width: 238px; padding: 6px 12px 6px 10px; text-align: left; border-radius: 14px; background: #fff;
  border: 1.5px solid color-mix(in oklch, var(--c) 40%, white); border-left: 5px solid var(--c); box-shadow: var(--sh-tag);
}
.callout.right { border-left-width: 1.5px; border-right: 5px solid var(--c); }
.callout:hover { border-color: var(--c); }
.callout.warn { box-shadow: 0 0 0 3px #f6d5d1, var(--sh-tag); border-color: var(--danger); }
.callout b { grid-row: span 2; font-size: 17px; font-weight: 700; color: var(--text); min-width: 54px; }
.co-hz { display: flex; gap: 3px; }
.co-hz i { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; }
.co-hz i .ico { width: 13px; height: 13px; }
.callout small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.callout-layer.compact .callout { width: auto; grid-template-columns: auto auto; padding: 3px 10px 3px 8px; }
.callout-layer.compact .callout small { display: none; }
.callout-layer.compact .callout b { grid-row: auto; font-size: 14px; min-width: 0; }
.callout-layer.compact .co-hz i { width: 18px; height: 18px; }
.callout-layer.compact .co-hz i .ico { width: 11px; height: 11px; }
/* 只有電視尺寸（1920×1080）才放大看板的樓層標籤；筆電測試時維持一般大小，才不會蓋住建物 */
@media (min-width: 1800px) and (min-height: 1000px) {
  body.board .callout { width: 300px; padding: 8px 14px 8px 12px; }
  body.board .callout b { font-size: 22px; min-width: 66px; }
  body.board .co-hz i { width: 28px; height: 28px; }
  body.board .co-hz i .ico { width: 16px; height: 16px; }
  body.board .callout small { font-size: 14px; }
}
@media (max-width: 767px) { .callout { width: 150px; grid-template-columns: 1fr; } .callout b { grid-row: auto; font-size: 14px; } .callout small { display: none; } }

/* ---------- 門口看板（?mode=board，1920×1080） ---------- */
body.board .topbar, body.board .rail, body.board .sheet-handle, body.board .actionbar, body.board .tb-tools { display: none !important; }
/* 看板開放人員操作「整棟／分層／單層」 */
body.board .toolbar { bottom: 28px; padding: 6px; }
body.board .seg button { height: 52px; padding: 0 26px; font-size: 20px; }
body.board .seg .ico { width: 24px; height: 24px; }
body.board .stage { grid-template-columns: 1fr calc(660px * var(--bs, 1)); }
body.board .panel-body, body.board .bd-cap { zoom: var(--bs, 1); }
body.board .panel { background: #fff; }
body.board .panel-body { padding: 32px 36px 24px; gap: 26px; overflow: hidden; }
body.board .rtag { padding: 5px 16px 5px 5px; }
body.board .rtag-ico { width: 36px; height: 36px; }
body.board .rtag-ico .ico { width: 20px; height: 20px; }
body.board .rtag-t b { font-size: 17px; }
body.board .rtag-t small { font-size: 13.5px; }
.bd-cap { position: absolute; left: 32px; top: 28px; z-index: 5; display: flex; align-items: center; gap: 18px; padding: 14px 26px; border-radius: 22px; background: #fff; border: 1px solid var(--rule); box-shadow: var(--sh-menu); }
.bd-cap b { font-size: 44px; font-weight: 700; color: var(--teal-d); line-height: 1; }
.bd-cap span { display: flex; gap: 8px; font-size: 22px; font-weight: 600; color: var(--muted); }
.bd-cap i, .bd-hz i { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px 0 10px; border-radius: 19px; background: var(--c); color: #fff; font-style: normal; font-size: 20px; font-weight: 700; }
.bd-cap i .ico, .bd-hz i .ico { width: 22px; height: 22px; }
.bd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.bd-head h1 { margin: 0; font-size: 44px; font-weight: 800; color: var(--teal-d); line-height: 1.15; letter-spacing: .04em; }
.bd-site { margin: 8px 0 0; font-size: 20px; font-weight: 600; color: var(--muted); line-height: 1.35; }
.bd-clock { text-align: right; flex: none; display: flex; flex-direction: column; }
.bd-clock b { font-size: 52px; font-weight: 600; line-height: 1; color: var(--text); }
.bd-clock span { font-size: 18px; color: var(--muted); margin-top: 6px; }
.bd-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.bd-stats div { background: var(--bg); border-radius: 22px; padding: 16px 20px; display: flex; flex-direction: column; }
.bd-stats b { font: 600 54px var(--mono); line-height: 1; color: var(--teal-d); }
.bd-stats span { font-size: 18px; color: var(--muted); margin-top: 8px; }
.bd-stats .hi b { color: var(--danger); }
.bd-stats .mid b { color: var(--gold-d); }
.bd-sec { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.bd-sec.grow { flex: 1; overflow: hidden; }
body.board .bd-foot { flex: none; margin-top: auto; }
.bd-sec h2 { margin: 0; display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 700; color: var(--teal-d); }
.bd-sec h2.danger { color: var(--danger); }
.bd-sec h2 .ico { width: 26px; height: 26px; }
.bd-sec h2 small { margin-left: auto; font: 500 18px var(--mono); color: var(--muted); }
.bd-warn { display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; border-radius: 18px; background: #fdf1ef; border-left: 6px solid var(--danger); }
.bd-warn.l2 { background: #fbf6ec; border-left-color: var(--gold); }
.bd-warn b { font-size: 22px; color: var(--danger); }
.bd-warn.l2 b { color: var(--gold-d); }
.bd-warn span { font-size: 19px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bd-warn span i { font-style: normal; font-weight: 700; color: var(--gold-d); margin-right: 10px; }
.bd-warn span em { font-style: normal; color: var(--danger); font-weight: 700; margin: 0 14px; }
.bd-more, .bd-empty { margin: 0; font-size: 18px; color: var(--muted); }
.bd-fl { display: grid; grid-template-columns: 112px 1fr; gap: 2px 14px; align-items: center; padding: 8px 14px; border-radius: 16px; border: 1px solid var(--rule); }
.bd-fl.on { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-l); }
.bd-fl b { font-size: 28px; font-weight: 700; color: var(--text); grid-row: span 2; }
.bd-hz { display: flex; flex-wrap: wrap; gap: 8px; }
.bd-hz i { height: 30px; font-size: 16px; padding: 0 10px 0 8px; }
.bd-hz i .ico { width: 18px; height: 18px; }
.bd-fl small { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.board .bd-sec { gap: 10px; }
.bd-foot { font-size: 16px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.bd-foot.off { color: var(--danger); font-weight: 700; }
iframe.rot { position: fixed; inset: 0; width: 100vw; height: 100vh; border: 0; z-index: 200; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
body.rot-away iframe.rot { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
