:root {
  --bg: #0b1f17;
  --panel: #11271d;
  --card: #16332589;
  --line: #2c5a47;
  --accent: #25d366;
  --accent2: #7cf5c0;
  --text: #e8fff5;
  --muted: #8fb3a3;
  --danger: #e53935;
  --warn: #ef6c00;
  --sidebar-w: 200px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}

#app { display: flex; height: 100vh; width: 100%; }

#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: #0a160f; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 40;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 12px; font-weight: 800; font-size: 17px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand .logo { font-size: 22px; }
#nav { flex: 1; padding: 8px 6px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 11px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  cursor: pointer; text-align: left; transition: background .15s, color .15s;
}
.nav-item:hover { background: #0d2519; color: var(--text); }
.nav-item.active { background: #1a4d35; color: var(--accent2); }
.nav-item.nav-settings { margin-top: auto; border-top: 1px solid var(--line); border-radius: 0; padding-top: 14px; }
.nav-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--line); }

.menu-btn {
  display: none; position: fixed; top: 10px; left: 10px; z-index: 50;
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: #0a160f; color: var(--text); font-size: 22px; cursor: pointer;
}

#workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#topbar {
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  padding: 10px 16px; background: #0a160f; border-bottom: 1px solid var(--line);
}
#pageTitle { margin: 0; font-size: 18px; font-weight: 700; flex: 1; }
#topbar .status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #888; }
.dot.on { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

#body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

.map-area {
  position: relative; flex: 1; min-height: 180px;
  border-bottom: 1px solid var(--line);
}
.map-area.hidden { display: none; }
#map { position: absolute; inset: 0; }
.map-hint {
  position: absolute; bottom: 10px; left: 10px; right: 10px; z-index: 15;
  background: rgba(10,22,15,.92); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
}

#pages {
  flex: 0 0 auto; max-height: 48vh; overflow-y: auto;
  background: var(--panel); padding: 12px;
}
#pages.pages-full { max-height: none; flex: 1; }
.page.hidden { display: none !important; }
.page-chat { display: flex; flex-direction: column; min-height: 280px; }
.hidden { display: none !important; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.card-title { font-weight: 700; margin-bottom: 6px; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
.sep-line { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.row.spread { justify-content: space-between; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.radio-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 14px; }

input[type=text], input[type=tel], input[type=number] {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: #0d2519; color: var(--text); font-size: 14px; margin: 4px 0;
}
input[type=range] { width: 100%; accent-color: var(--accent); }

.btn {
  background: var(--accent); color: #05291c; border: 0; border-radius: 9px;
  padding: 10px 14px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.btn.ghost { background: transparent; color: var(--accent2); border: 1px solid var(--accent2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 6px; }
.icon-btn { background: transparent; border: 0; font-size: 22px; cursor: pointer; color: var(--text); padding: 6px; }
.icon-btn.send { color: var(--accent2); }

.floor-cal { font-size: 13px; display: flex; align-items: center; gap: 4px; }
.floor-input { width: 64px; padding: 6px 8px; margin: 0; border-radius: 8px; border: 1px solid var(--line); background: #0d2519; color: var(--text); font-size: 14px; text-align: center; }

.ptt {
  width: 100%; height: 80px; border-radius: 16px; border: 0; cursor: pointer;
  background: var(--accent); color: #05291c; font-size: 17px; font-weight: 800; margin: 6px 0;
  user-select: none; touch-action: none;
}
.ptt.active { background: var(--danger); color: #fff; }

.peer-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.peer-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: #0d2519; border-radius: 8px; }

.skill-list { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.65; }
.skill-list li { margin-bottom: 6px; }
.page-section { font-size: 15px; font-weight: 700; color: var(--accent2); margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.page-section:first-child { margin-top: 0; }
.card-danger { border-color: var(--danger); }
.med-preview { margin-top: 8px; padding: 10px; background: #0d2519; border-radius: 8px; border: 1px solid var(--line); white-space: pre-wrap; }

.sos-flash {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; align-items: center; justify-content: center;
}
.sos-flash.on { background: #fff; }
.sos-flash-inner { text-align: center; color: #fff; }
.sos-flash.on .sos-flash-inner { color: #000; }
.sos-flash-text { font-size: 48px; font-weight: 900; letter-spacing: 8px; }
.sos-flash-inner p { opacity: .8; font-size: 14px; }
.peer-stale { opacity: .65; border: 1px dashed var(--muted); }
.peer-stale-tag { color: var(--warn); font-size: 11px; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.bubble { max-width: 85%; padding: 8px 10px; border-radius: 12px; font-size: 14px; word-break: break-word; }
.bubble.me { align-self: flex-end; background: #1f6f4a; }
.bubble.them { align-self: flex-start; background: #16382a; }
.bubble .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.bubble img { max-width: 200px; border-radius: 8px; }
.bubble .voice { cursor: pointer; }
.chat-input { display: flex; align-items: center; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); flex-shrink: 0; }
.chat-input input[type=text] { margin: 0; flex: 1; }
.icon-btn.recording { color: var(--danger); }

.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #3a4d44; border-radius: 30px; transition: .2s; }
.slider:before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(22px); }

.banner {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 20;
  background: var(--warn); color: #fff; padding: 10px 12px; border-radius: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.banner.danger { background: var(--danger); }
.emergency-links { display: flex; gap: 6px; }
.emergency-links .btn { background: #fff; color: var(--danger); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 80; display: flex; align-items: center; justify-content: center; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 88%; max-width: 360px; }
.modal-card h3 { margin: 0 0 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }

.my-code { font-size: 24px; font-weight: 800; letter-spacing: 3px; color: var(--accent2); font-family: monospace; }
.code-area { width: 100%; min-height: 56px; resize: vertical; margin: 6px 0; padding: 8px; border-radius: 9px; border: 1px solid var(--line); background: #0d2519; color: var(--text); font-family: monospace; font-size: 11px; word-break: break-all; }
.qr-img { width: 260px; max-width: 72vw; margin: 8px auto; background: #fff; padding: 10px; border-radius: 10px; }
.qr-img img { width: 100%; display: block; }
.scan-video { width: 100%; max-width: 320px; border-radius: 10px; background: #000; }
code { background: #0d2519; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.conv-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px; flex-shrink: 0; }
.conv-chip { flex: 0 0 auto; padding: 6px 12px; border-radius: 16px; background: #0d2519; border: 1px solid var(--line); color: var(--text); cursor: pointer; font-size: 13px; position: relative; }
.conv-chip.active { background: var(--accent); color: #05291c; font-weight: 700; }
.conv-chip .unread { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; }
.sep { align-self: center; background: #0d2519; border: 1px solid var(--line); color: var(--muted); font-size: 11px; padding: 3px 12px; border-radius: 12px; margin: 8px 0; }
.bubble .meta { font-size: 10px; color: var(--muted); margin-top: 2px; text-align: right; }
.maplibregl-popup-content { color: #111; }

@media (min-width: 900px) {
  #body { flex-direction: row; }
  .map-area { flex: 1; min-height: 0; border-bottom: 0; border-right: 1px solid var(--line); }
  #pages { flex: 0 0 400px; max-height: none; overflow-y: auto; }
  #pages.pages-full { flex: 1; max-width: 520px; }
}

@media (max-width: 899px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  #sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  #topbar { padding-left: 56px; }
  #pages { max-height: 42vh; }
  #pages.pages-full { max-height: none; flex: 1; }
  .map-area.hidden + #pages { max-height: none; flex: 1; }
}
