:root {
  --bg: #fbeef3; --panel: rgba(255, 255, 255, 0.92); --ink: #3d3450; --ink2: #7a6f8c; --line: #f0dbe4;
  --pink: #ff5f9e; --pink2: #ffe4ee; --mint: #1fb89a; --amber: #ffad3b; --violet: #8a6cf2;
  --shadow: 0 8px 28px rgba(160, 90, 120, 0.16); --r: 16px;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); -webkit-user-select: none; user-select: none; }
.panel, .modal-box, input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 12px; }
button:hover { background: var(--pink2); }
button.primary { background: var(--pink); color: #fff; border-color: var(--pink); font-weight: 700; }
button.primary:hover { background: #ec4a8b; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.icon { padding: 2px 8px; }
input, textarea, select { font: inherit; color: var(--ink); border: 1px solid #e6cfd9; border-radius: 10px; padding: 7px 10px; background: #fff; width: 100%; }
textarea { resize: vertical; min-height: 70px; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 14px; margin: 14px 0 6px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.zone-label { position: absolute; left: 0; top: 0; font-size: 12px; font-weight: 700; color: #9a7b8c; background: rgba(255, 255, 255, 0.7); padding: 2px 9px; border-radius: 99px; white-space: nowrap; z-index: 1 !important; }
.emp-label { position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; background: #fff; border-radius: 12px; padding: 4px 9px 5px; box-shadow: 0 3px 10px rgba(150, 80, 110, 0.18); font-size: 12px; white-space: nowrap; border: 2px solid transparent; }
.emp-label::after { content: ""; position: absolute; bottom: -7px; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.emp-label.sel { border-color: var(--pink); }
.emp-label b { font-size: 13px; }
.emp-label .st, .chip { display: inline-flex; align-items: center; gap: 4px; color: var(--c); font-weight: 700; font-size: 11px; }
.emp-label .st i, .chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); display: inline-block; }
.emp-label .bar { width: 64px; height: 4px; background: #f1e6ec; border-radius: 4px; overflow: hidden; }
.emp-label .bar span { display: block; height: 100%; }
.emp-label .pin { position: absolute; right: -8px; top: -8px; font-size: 12px; }

#topbar { position: fixed; top: 10px; left: 10px; right: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 8px 12px; z-index: 20; backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 6px; }
.logo { font-size: 22px; }
.office-name { border: none; background: transparent; font-size: 18px; font-weight: 800; padding: 2px 6px; color: var(--ink); }
.office-name:hover { background: var(--pink2); }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.tag.warn { background: #fff1c9; color: #a46b00; }
.tag.demo { background: #ffe0e9; color: #c2185b; border: 1px dashed #ff8fb3; }
.tag.ok { background: #d9f6ec; color: #0f8a6c; }
.tag.off { background: #eeeaf3; color: #6f6680; }
.tag.bad { background: #ffe1e1; color: #c62828; }
.stats { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.stats .chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; }
.top-actions { display: flex; gap: 6px; }

.panel { position: fixed; top: 72px; bottom: 10px; width: 290px; background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px; overflow-y: auto; z-index: 15; backdrop-filter: blur(8px); }
.panel.left { left: 10px; transition: transform 0.25s; }
.panel.left.collapsed { transform: translateX(calc(-100% + 34px)); }
.panel.left.collapsed > *:not(.panel-head) { visibility: hidden; }
.panel.right { right: 10px; width: 360px; }
.panel.hidden { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sub { margin-top: 14px; margin-bottom: 6px; }
.tree-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 10px; cursor: pointer; }
.tree-row:hover, .tree-row.sel { background: var(--pink2); }
.tree-row .dot { width: 26px; height: 26px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.tree-row .who { flex: 1; min-width: 0; line-height: 1.2; }
.tree-row .who small { color: var(--ink2); display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: #efe8ff; color: #6a4fd6; }
.rank.r1 { background: #ffe9cc; color: #b8620b; }
.rank.r2 { background: #e3f1ff; color: #1f6fc2; }
.rank.r0 { background: #eee; color: #777; }
.stage { border: 1px solid var(--line); border-radius: 12px; padding: 7px 9px; margin-bottom: 6px; background: #fff; }
.stage-h { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--ink2); }
.stage-item { font-size: 12px; margin-top: 4px; display: flex; gap: 4px; align-items: center; }
.flow-arrow { text-align: center; color: #e2b5c6; font-size: 11px; line-height: 1; margin: -2px 0 4px; }

.emp-head { display: flex; gap: 10px; align-items: center; }
.avatar { width: 48px; height: 48px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); flex: none; }
.emp-head h2 { font-size: 18px; }
.muted { color: var(--ink2); font-size: 12px; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 4px 8px; font-size: 13px; margin-top: 10px; }
.kv dt { color: var(--ink2); }
.kv dd { margin: 0; }
.progress { height: 8px; background: #f3e7ee; border-radius: 6px; overflow: hidden; margin-top: 4px; }
.progress span { display: block; height: 100%; border-radius: 6px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; background: #fff; margin-top: 8px; font-size: 13px; }
.seg { display: flex; gap: 4px; margin: 6px 0; }
.seg button { flex: 1; padding: 5px; font-size: 12px; }
.seg button.on { background: var(--pink); color: #fff; border-color: var(--pink); }
.row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.note { font-size: 11.5px; color: var(--ink2); background: #faf6fb; border-radius: 8px; padding: 6px 8px; margin-top: 6px; line-height: 1.5; }
.cmd { font-size: 12px; border-left: 3px solid #e8d3dd; padding: 3px 8px; margin-top: 6px; }

.approval-card { position: fixed; right: 10px; bottom: 10px; width: 330px; background: #fffaf0; border: 2px solid #ffd27a; border-radius: var(--r); box-shadow: var(--shadow); padding: 10px 12px; z-index: 14; }
.approval-card h2 { display: flex; justify-content: space-between; }
.approval-item { border-top: 1px dashed #f2d9a6; padding-top: 8px; margin-top: 8px; font-size: 13px; }
.approval-item b { color: #c25b00; }
body.emp-open .approval-card { right: 380px; }

.view-controls { position: fixed; left: 310px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; z-index: 14; background: var(--panel); padding: 6px 8px; border-radius: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 680px); }
.view-controls button { width: 34px; height: 34px; padding: 0; font-size: 16px; }
.view-controls button.wide { width: auto; padding: 0 10px; font-size: 12px; }
.view-controls .sep { width: 1px; height: 22px; background: var(--line); }
.view-controls .hint { flex-basis: 100%; font-size: 11px; color: var(--ink2); }
body.team-collapsed .view-controls { left: 54px; }

.modal { position: fixed; inset: 0; background: rgba(80, 40, 60, 0.28); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 20px; width: min(1080px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 20px; position: relative; box-shadow: 0 20px 60px rgba(120, 50, 80, 0.3); }
.modal-box .close { position: absolute; right: 12px; top: 12px; border: none; font-size: 16px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.tabs button.on { background: var(--pink); color: #fff; border-color: var(--pink); }
.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.video-box { aspect-ratio: 16/9; background: linear-gradient(135deg, #ffd6e6, #e0d6ff); border-radius: 14px; display: flex; align-items: center; justify-content: center; text-align: center; color: #7a4a63; padding: 20px; font-size: 14px; }
.video-box video { width: 100%; height: 100%; border-radius: 14px; background: #000; }
.check { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.check input { width: auto; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.board .col { background: #fff7fa; border-radius: 14px; padding: 8px; }
.board .col h3 { margin: 2px 0 6px; font-size: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink2); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 110px 1fr; gap: 8px 10px; align-items: center; font-size: 13px; }
.toast { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); background: #3d3450; color: #fff; padding: 9px 16px; border-radius: 12px; font-size: 13px; z-index: 60; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.err { background: #c62828; }

@media (max-width: 900px) {
  .panel.left { width: 250px; }
  .view-controls { left: 10px; max-width: calc(100vw - 20px); bottom: auto; top: 120px; }
  .view-controls .hint { display: none; }
  .panel.right { left: 10px; right: 10px; width: auto; top: auto; height: 60vh; }
  .approval-card { width: calc(100vw - 20px); }
  body.emp-open .approval-card { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .top-actions button { padding: 5px 8px; font-size: 12px; }
}

/* 手機：基本可用（主要查看裝置尚未決定，完整手機版屬可選延伸） */
@media (max-width: 600px) {
  #topbar { top: 6px; left: 6px; right: 6px; padding: 6px 8px; gap: 6px; }
  .office-name { font-size: 15px; }
  .logo { font-size: 18px; }
  .stats { display: none; }
  #demoBanner { font-size: 10px; }
  .top-actions { width: 100%; }
  .top-actions button { flex: 1; padding: 5px 4px; font-size: 12px; }
  .panel.left { top: 128px; bottom: 170px; }
  .view-controls { top: auto; bottom: 138px; left: 6px; right: 6px; max-width: none; justify-content: center; }
  body.team-collapsed .view-controls { left: 6px; }
  .approval-card { left: 6px; right: 6px; width: auto; bottom: 6px; padding: 8px 10px; font-size: 12px; max-height: 124px; overflow-y: auto; }
  .panel.right { top: 128px; height: auto; bottom: 6px; }
}

/* 第二版：樓層、CEO、名牌細節 */
.view-controls .floors { display: flex; gap: 4px; flex-basis: 100%; }
.view-controls .floors button { height: 30px; }
.view-controls button.on { background: var(--pink); color: #fff; border-color: var(--pink); }
.floor-label { position: absolute; left: 0; top: 0; display: flex; gap: 6px; align-items: center; background: #ff7eb0; color: #fff; border: 2px solid #fff; border-radius: 12px; padding: 4px 10px; font-size: 13px; white-space: nowrap; box-shadow: 0 3px 10px rgba(150, 80, 110, 0.25); }
.floor-label span { background: #fff; color: #1fb89a; border-radius: 99px; padding: 1px 8px; font-size: 11px; font-weight: 800; }
.spare-label { position: absolute; left: 0; top: 0; font-size: 11px; color: #8a7f99; background: rgba(255,255,255,.85); border: 1px dashed #c9bfd6; border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.emp-label .nm { display: flex; gap: 5px; align-items: baseline; }
.emp-label .nm small { color: var(--ink2); font-size: 10.5px; }
.emp-label .task { max-width: 150px; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px; color: var(--ink2); background: #faf3f7; border-radius: 6px; padding: 1px 6px; }
.emp-label.compact .task, .emp-label.compact .nm small, .emp-label.compact .bar { display: none; }
.emp-label.compact { padding: 3px 7px 4px; }
.emp-label.ceo { background: #fff8e1; border-color: #ffd166; }
.emp-label.ceo::after { border-top-color: #fff8e1; }
.tree-row.ceo .dot { display: flex; align-items: center; justify-content: center; font-size: 13px; }
.view-controls { left: 310px; }

/* 第二階段：工作引擎、成果內容、登入 */
.mode-seg button { text-align: left; line-height: 1.3; padding: 8px 10px; }
.mode-seg button small { opacity: .8; font-size: 11px; }
.art-text { white-space: pre-wrap; font-family: inherit; font-size: 13px; background: #fbf7fa; border-radius: 12px; padding: 12px; max-height: 60vh; overflow: auto; }
.login-box { max-width: 380px; margin: 12vh auto; background: #fff; border-radius: 20px; padding: 24px; box-shadow: var(--shadow); }
.login-box h1 { font-size: 20px; margin: 0 0 6px; }
.login-page { overflow: auto; }
.art-text.md { white-space: normal; line-height: 1.7; }
.art-text.md h2, .art-text.md h3 { margin: 14px 0 6px; font-size: 16px; }
.art-text.md h4, .art-text.md h5 { margin: 10px 0 4px; font-size: 14px; }
.art-text.md p { margin: 4px 0; }
.art-text.md hr { border: none; border-top: 1px dashed #e3c9d6; margin: 12px 0; }
.art-text.md table { margin: 8px 0; background: #fff; }
.art-text.md .li { margin: 2px 0 2px 6px; }
