:root {
    --bg: #0b1220; --surface: #141c2e; --surface2: #1e2b45; --line: #26324a; --text: #e8eefc; --muted: #93a1bd;
    --primary: #1f6feb; --blue: #4da3ff; --red: #ff6b4a; --teal: #2ec4b6; --danger: #ff6b4a;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg: #f4f7fc; --surface: #ffffff; --surface2: #dce6f8; --line: #b4c0d6; --text: #0b1220; --muted: #52607a;
        color-scheme: light;
    }
}
:root[data-theme="light"] {
    --bg: #f4f7fc; --surface: #ffffff; --surface2: #dce6f8; --line: #b4c0d6; --text: #0b1220; --muted: #52607a;
    color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; } body { min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, "Noto Sans TC", "Microsoft JhengHei", sans-serif; overscroll-behavior: none; }
a { color: var(--blue); }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .strong { font-weight: 600; } .break { word-break: break-all; }
.err { color: var(--red); } .pad { padding: 4px 16px; }
.row { display: flex; align-items: center; } .row.gap, .gap { gap: 8px; } .row.wrap, .wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .col { display: flex; flex-direction: column; } .center { align-items: center; }
.grow { flex: 1; min-width: 0; } .spacer { flex: 1; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
#app.screen { display: block; }
.login-box { margin: auto; text-align: center; padding: 24px; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.logo-lg { width: 96px; height: 96px; } .logo { width: 36px; height: 36px; }
.gsi { min-height: 44px; margin-top: 14px; }

.bar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; position: sticky; top: 0; z-index: 1200; background: var(--bg); }
.btn-text { background: none; border: 0; color: var(--blue); padding: 6px 10px; cursor: pointer; border-radius: 8px; text-decoration: none; }
.btn-text:hover { background: var(--surface2); } .btn-text.danger { color: var(--danger); text-align: left; }
.btn { background: var(--primary); color: #fff; border: 0; border-radius: 999px; padding: 9px 20px; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
/* 處理中：文字前面轉圈圈 */
.btn.loading::before { content: ''; display: inline-block; width: .9em; height: .9em; margin-right: .45em; vertical-align: -.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: hl-spin .7s linear infinite; }
@keyframes hl-spin { to { transform: rotate(360deg); } }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; margin-left: 4px; font-size: 12px; }

.chip, .chip-radio span { display: inline-block; background: var(--surface); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 4px 14px; cursor: pointer; font-size: 14px; }
.chip.on, .chip-radio input:checked + span { background: var(--surface2); border-color: var(--blue); color: var(--blue); }
.chip-radio input { display: none; }
.chips { display: flex; gap: 8px; padding: 2px 12px 8px; flex-wrap: wrap; }

.stage { position: relative; height: max(220px, 33dvh); margin: 0 12px; isolation: isolate; border-radius: 14px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
#radar, #map { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Leaflet 內部元件的 z-index 很高（最高 1000），自己關進獨立層級，才不會蓋住選取列與發佈按鈕 */
#map { z-index: 0; isolation: isolate; }
#app[data-size="half"] .stage { height: max(240px, 50dvh); }
/* 全版面：幾乎滿一個螢幕高，底部留一條可往下滑到清單 */
#app[data-size="full"] .stage { height: max(300px, calc(100dvh - 150px)); }
.size-switch { position: absolute; top: 8px; left: 8px; z-index: 1000; display: flex; background: color-mix(in srgb, var(--surface) 88%, transparent); border-radius: 10px; box-shadow: 0 1px 6px rgba(0,0,0,.35); }
.size-switch button { background: none; border: 0; padding: 5px 11px; cursor: pointer; color: var(--text); font-size: 14px; }
.size-switch button.on { color: var(--blue); font-weight: 700; }
.loc-hint { position: absolute; inset: 0; z-index: 900; display: grid; place-content: center; text-align: center; padding: 20px; background: color-mix(in srgb, var(--surface) 85%, transparent); gap: 10px; }
.selbar { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: clamp(260px, 50%, calc(100% - 16px)); z-index: 1000; background: var(--surface); border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.4); padding: 6px 6px 6px 12px; display: flex; align-items: center; gap: 8px; }
.selbar .title { font-weight: 600; word-break: break-word; }

.legend { display: flex; gap: 16px; align-items: center; padding: 8px 16px 0; font-size: 13px; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.req { background: var(--red); } .dot.off { background: var(--teal); }

.list { list-style: none; overflow-y: auto; padding: 10px 12px 90px; display: flex; flex-direction: column; gap: 8px; }
#app > .list { overflow: visible; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.item.sel { background: var(--surface2); border-color: var(--blue); }
.item .grow .t { font-weight: 600; word-break: break-word; } .item .grow .m { color: var(--muted); font-size: 13px; }
.fab { position: fixed; right: 18px; bottom: 18px; z-index: 1500; background: var(--primary); color: #fff; border: 0; border-radius: 16px; padding: 14px 20px; font-size: 16px; box-shadow: 0 4px 14px rgba(0,0,0,.4); cursor: pointer; }

dialog { margin: auto; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog.full { width: min(720px, 100vw); height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
dialog.full .dlg { height: 100%; overflow-y: auto; }
.dlg h2 { font-size: 19px; } .dlg h3 { font-size: 15px; margin-top: 10px; color: var(--muted); font-weight: 600; }
.dlg input[type=text], .dlg input:not([type]), .dlg textarea, #chatText { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; resize: none; }
.label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.chat { padding: 0; gap: 0; height: 100%; }
.chat-head { padding: 8px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; min-height: 80px; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; background: var(--surface2); word-break: break-word; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--primary); color: #fff; }
.msg small { display: block; opacity: .7; font-size: 11px; margin-top: 2px; }
.chat-input { padding: 8px; border-top: 1px solid var(--line); align-items: flex-end; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.chat-input textarea { flex: 1; max-height: 110px; }

.leaflet-container { background: var(--surface); font: inherit; }
.bubble { transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; pointer-events: auto; }
.bubble .box { background: #fff; color: #0b1220; border: 2px solid var(--red); border-radius: 10px; padding: 4px 9px; font-size: 12.5px; max-width: 180px; text-align: center; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.bubble.off .box { border-color: var(--teal); } .bubble.sel .box { border-width: 3px; }
.bubble .tri { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 7px solid #fff; }
.bubble .pt { width: 12px; height: 12px; border-radius: 50%; background: var(--red); border: 2px solid #fff; }
.bubble.off .pt { background: var(--teal); }
.leaflet-div-icon.hl { background: none; border: 0; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 2000; background: var(--surface2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 9px 16px; box-shadow: 0 4px 14px rgba(0,0,0,.4); max-width: calc(100vw - 32px); }

.chip.push { margin-left: auto; }
.chips { align-items: center; }
.type-chips { padding-top: 8px; padding-bottom: 0; }

/* Leaflet 的 divIcon 容器寬度為 0，說明框要自己撐開，否則文字會一字一行 */
.leaflet-div-icon.hl { overflow: visible; }
.bubble { width: max-content; max-width: 190px; }
.bubble .box { width: max-content; max-width: 180px; }

.thumb { height: 52px; width: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.item .thumb { height: 44px; width: 44px; }
.photo-btn { cursor: pointer; }
.msg-img { display: block; max-width: 240px; max-height: 240px; border-radius: 10px; margin-top: 4px; cursor: zoom-in; }
.menu-pop { position: fixed; z-index: 3000; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.45); padding: 4px; min-width: 150px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--surface2); } .menu-item.danger { color: var(--danger); }
.item { touch-action: pan-y; transition: transform .15s ease, opacity .15s ease; }
.item.swiping { transition: none; }
.reason { display: flex; gap: 8px; align-items: center; padding: 6px 4px; }
.apple-signin { display: flex; justify-content: center; margin-top: 4px; }
