/* 救援指揮平台：深色、高對比、大按鈕（戴手套、戶外陽光下也要好用） */
:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #30363d;
  --text: #f0f3f6;
  --muted: #9da7b3;
  --ok: #2ea043;
  --warn: #d29922;
  --danger: #f85149;
  --blue: #388bfd;
  --primary: #1f6feb;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: #79c0ff; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: #010409; border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 700; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; min-height: 40px; display: inline-flex; align-items: center; }
.topbar nav a.on { color: var(--text); background: var(--panel-2); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 1.4rem; margin: 4px 0 16px; }
.section-title { font-size: 1.1rem; margin: 24px 0 10px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.count { color: var(--muted); font-size: .9rem; font-weight: 400; }
.hint { color: var(--muted); font-size: .92rem; }
.flash { background: var(--panel-2); border-left: 4px solid var(--primary); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 1.15rem; }

/* 按鈕：至少 48px 高 */
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .7; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.danger { background: #b62324; border-color: #da3633; }
.btn.armed { background: var(--warn); border-color: var(--warn); color: #000; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .92rem; }
.btn.big { min-height: 60px; font-size: 1.1rem; text-align: left; }

input, select {
  min-height: 48px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #0d1117; color: var(--text); font: inherit;
  width: 100%;
}
.row-form { display: flex; gap: 10px; flex-wrap: wrap; }
.row-form input { flex: 1 1 200px; }
.member-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.team-tag { display: inline-block; background: #30363d; color: var(--text); border-radius: 6px; padding: 0 8px; font-size: .85rem; font-weight: 600; }
.tag { display: inline-block; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: .78rem; margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); min-height: 48px; }
.switch input { width: 22px; min-height: 22px; height: 22px; }

.conn { background: var(--warn); color: #000; font-weight: 700; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }

/* 警報 */
.alerts { display: grid; gap: 8px; }
.alert {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: 12px; border: 2px solid; background: var(--panel);
}
.alert.danger { border-color: var(--danger); background: #3b1013; }
.alert.warn { border-color: var(--warn); background: #2e2410; }
.alert.acked { opacity: .65; border-style: dashed; }
.alert .btn { flex: none; white-space: nowrap; }
.alert-level { font-weight: 700; margin-right: 6px; }
.alert-time { color: var(--muted); font-size: .85rem; }
.all-clear { background: #0f2a17; border: 1px solid var(--ok); padding: 12px 14px; border-radius: 12px; margin: 0; }

/* 隊員卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.card.danger { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(248, 81, 73, .25); }
.card.warn { border-color: var(--warn); }
.card.evacuating { background: repeating-linear-gradient(135deg, #2a0d10, #2a0d10 14px, #161b22 14px, #161b22 28px); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.name { font-size: 1.15rem; margin-left: 4px; }
.badge { font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: #0f2a17; color: #56d364; }
.badge.warn { background: #3a2c0d; color: #e3b341; }
.badge.danger { background: #4a1216; color: #ff7b72; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.seen { color: var(--muted); font-size: .88rem; }
.sim { display: grid; gap: 4px; color: var(--muted); font-size: .88rem; border-top: 1px dashed var(--line); padding-top: 8px; }

.led-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .92rem; }
.led { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }
.led-green { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.led-blue { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.led-red { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.blink { animation: blink 0.8s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.metric { background: var(--panel-2); border-radius: 10px; padding: 6px 8px; border: 1px solid transparent; }
.metric.warn { border-color: var(--warn); }
.metric.danger { border-color: var(--danger); background: #3b1013; }
.metric-label { color: var(--muted); font-size: .78rem; }
.metric-value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-value small { font-size: .72rem; color: var(--muted); font-weight: 400; margin-left: 2px; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .85rem; padding: 2px 8px; border-radius: 6px; }
.chip.warn { background: #3a2c0d; color: #e3b341; }
.chip.danger { background: #4a1216; color: #ff7b72; }

/* 隊員畫面 */
.status-banner { border-radius: 16px; padding: 16px; margin-bottom: 12px; border: 2px solid; display: grid; gap: 6px; }
.status-banner.ok { border-color: var(--ok); background: #0f2a17; }
.status-banner.warn { border-color: var(--warn); background: #2e2410; }
.status-banner.danger { border-color: var(--danger); background: #3b1013; }
.status-main { font-size: 1.6rem; font-weight: 800; }

.sos-area { display: grid; gap: 10px; justify-items: center; margin: 24px 0; }
.sos-btn {
  position: relative; overflow: hidden;
  width: min(80vw, 260px); aspect-ratio: 1; border-radius: 50%;
  border: 6px solid #ff7b72; background: #b62324; color: #fff;
  display: grid; place-content: center; gap: 4px;
  font: inherit; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none;
}
.sos-btn.active { background: #ff3b30; animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 18px rgba(255, 59, 48, .25); } }
.sos-text { font-size: 3.2rem; font-weight: 900; letter-spacing: 4px; }
.sos-sub { font-size: .95rem; }
.sos-progress { position: absolute; left: 0; bottom: 0; height: 100%; width: 100%; background: rgba(255, 255, 255, .25); transform: scaleX(0); transform-origin: left; pointer-events: none; }

.evac-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; text-align: center;
  background: #b62324; color: #fff; padding: 24px; animation: flash 1s infinite;
}
@keyframes flash { 50% { background: #5c0f12; } }
.evac-icon { font-size: 5rem; }
.evac-title { font-size: 2rem; font-weight: 900; }
.evac-sub { font-size: 1.2rem; }
.evac-sub.small { font-size: .95rem; opacity: .85; margin-top: 16px; }

/* 設定頁 */
.member-list { display: grid; gap: 10px; margin-bottom: 16px; }
.member-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--panel-2); border-radius: 12px; padding: 10px; }
.member-meta { flex: 1 1 100%; display: flex; gap: 8px; align-items: center; }
.inline-edit { display: flex; gap: 6px; flex: 1 1 260px; min-width: 0; }
.inline-edit input { min-width: 0; }
.inline-edit input.short { max-width: 90px; }
.inline-edit .btn { flex: none; white-space: nowrap; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; align-items: end; margin-bottom: 12px; }
.grid-form label { display: grid; gap: 4px; color: var(--muted); font-size: .9rem; }
.grid-form label.check { display: flex; align-items: center; gap: 8px; }
.grid-form label.check input { width: 22px; min-height: 22px; }
.ok-text { color: #56d364; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

@media (max-width: 420px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .wrap { padding: 12px 16px; }
}
