/*
 * world.css — 「重庆世界」实况视图（agents.jiavi.cn 首页，2026-07-11 上线）
 * 全屏真实地图 + 游戏 HUD：顶部态势条、底部事件流、左下卫星窗、右侧详情面板。
 * 角色 = Leaflet DivIcon（头像+状态环+名牌+气泡），动画全走 CSS。
 */

:root {
  --hud-bg: rgba(17, 24, 39, 0.92);
  --hud-border: rgba(255, 255, 255, 0.12);
  --hud-text: #e5e7eb;
  --hud-dim: #9ca3af;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --busy: #38bdf8;
}

html, body.world-body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #0b1020;
}

#map { position: absolute; inset: 0; z-index: 1; background: #0b1020; }

/* 夜景：给瓦片层上滤镜 */
body.night .leaflet-tile-pane { filter: invert(92%) hue-rotate(185deg) saturate(0.55) brightness(0.92) contrast(0.95); }

/* ---------- 顶部 HUD ---------- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-border);
  color: var(--hud-text);
  backdrop-filter: blur(6px);
}
.hud-brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.hud-logo { font-size: 20px; }
.hud-title { font-weight: 700; font-size: 15px; letter-spacing: 1px; }
.hud-clock { color: var(--hud-dim); font-variant-numeric: tabular-nums; font-size: 13px; margin-left: 6px; }

.hud-situation { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.sit-chip {
  padding: 3px 10px; border-radius: 999px; font-size: 13px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--hud-border);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.sit-alert { cursor: pointer; background: rgba(239,68,68,0.18); border-color: rgba(239,68,68,0.5); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.hud-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.hud-link { color: #93c5fd; text-decoration: none; font-size: 13px; }
.hud-link:hover { text-decoration: underline; }
.hud-user { color: var(--hud-dim); font-size: 13px; }
.hud-btn {
  background: rgba(255,255,255,0.08); color: var(--hud-text);
  border: 1px solid var(--hud-border); border-radius: 6px;
  padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.hud-btn:hover { background: rgba(255,255,255,0.16); }

/* 告警抽屉 */
.alert-drawer {
  position: absolute; top: 46px; left: 0; right: 0; z-index: 999;
  background: rgba(69, 10, 10, 0.95); color: #fecaca;
  border-bottom: 1px solid rgba(239,68,68,0.5);
  padding: 8px 16px; font-size: 13px; max-height: 30vh; overflow-y: auto;
}
.alert-drawer .alert-row { padding: 3px 0; }

/* ---------- 角色（NPC）DivIcon ---------- */
.npc-icon { background: transparent; border: none; }
.npc { position: relative; width: 0; height: 0; cursor: pointer; }
.npc-core {
  position: absolute; left: -26px; top: -26px; width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
}
.npc-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--green);
  background: rgba(17, 24, 39, 0.85);
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  transition: border-color 0.4s;
}
.npc.st-yellow .npc-ring { border-color: var(--yellow); }
.npc.st-red .npc-ring { border-color: var(--red); animation: ringAlarm 1.2s infinite; }
@keyframes ringAlarm { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); } 50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); } }

.npc-emoji { position: relative; font-size: 28px; line-height: 1; z-index: 2; }
/* 在忙：小人走路摇摆；活跃：轻微呼吸；空闲：变暗 */
.npc.s-busy .npc-emoji { animation: walk 0.7s infinite; }
.npc.s-active .npc-emoji { animation: breathe 2.4s infinite; }
.npc.s-idle .npc-core { opacity: 0.68; filter: saturate(0.6); }
@keyframes walk { 0%,100% { transform: rotate(-7deg) translateY(0); } 50% { transform: rotate(7deg) translateY(-3px); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* 睡觉徽章（久无动作） */
.npc-zzz { position: absolute; right: -30px; top: -40px; font-size: 15px; display: none; }
.npc.sleeping .npc-zzz { display: block; animation: breathe 2.4s infinite; }

/* 名牌 */
.npc-name {
  position: absolute; top: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,0.88); color: #fff;
  padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
  white-space: nowrap; border: 1px solid var(--hud-border);
}
.npc-place {
  position: absolute; top: 49px; left: 50%; transform: translateX(-50%);
  color: #cbd5e1; font-size: 10px; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
body:not(.night) .npc-place { color: #334155; text-shadow: 0 1px 2px rgba(255,255,255,0.9); }

/* 对话气泡 */
.npc-bubble {
  position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%);
  max-width: 200px; min-width: 60px;
  background: #fff; color: #111827;
  border-radius: 10px; padding: 5px 9px;
  font-size: 12px; line-height: 1.35;
  box-shadow: 0 3px 12px rgba(0,0,0,0.35);
  display: none;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.npc-bubble::after {
  content: ""; position: absolute; bottom: -6px; left: 50%; margin-left: -6px;
  border: 6px solid transparent; border-top-color: #fff; border-bottom: none;
}
.npc.s-busy .npc-bubble, .npc.s-active .npc-bubble { display: block; }
.npc.bubble-error .npc-bubble { background: #fee2e2; color: #991b1b; }
.npc.bubble-error .npc-bubble::after { border-top-color: #fee2e2; }

/* 选中态 */
.npc.selected .npc-ring { border-width: 4px; box-shadow: 0 0 0 6px rgba(56,189,248,0.35), 0 2px 10px rgba(0,0,0,0.45); }

/* 事件到达的水波纹 */
.ping-ripple {
  border-radius: 50%;
  border: 2px solid var(--busy);
  animation: ripple 1.2s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple { from { transform: scale(0.2); opacity: 0.9; } to { transform: scale(1.6); opacity: 0; } }

/* 互动连线 */
.edge-live { stroke-dasharray: 8 10; animation: edgeFlow 1.2s linear infinite; }
@keyframes edgeFlow { to { stroke-dashoffset: -18; } }

/* ---------- 左下卫星窗 ---------- */
.satellite-box {
  position: absolute; left: 12px; bottom: 52px; z-index: 900;
  background: var(--hud-bg); border: 1px solid var(--hud-border);
  border-radius: 10px; padding: 8px 12px; color: var(--hud-text);
  font-size: 12px; min-width: 170px;
}
.sat-head { font-weight: 700; margin-bottom: 6px; color: var(--hud-dim); }
.sat-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.sat-flag { font-size: 14px; }

/* ---------- 底部事件流 ---------- */
.ticker-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 950;
  display: flex; align-items: center; gap: 10px;
  background: var(--hud-bg); border-top: 1px solid var(--hud-border);
  color: var(--hud-text); padding: 6px 14px; font-size: 12.5px;
}
.ticker-label { white-space: nowrap; color: var(--hud-dim); font-weight: 600; }
.ticker-viewport { overflow: hidden; flex: 1; }
.ticker-inner { display: flex; gap: 26px; align-items: center; }
.ticker-item { white-space: nowrap; animation: slideIn 0.4s ease-out; }
.ticker-item .t-time { color: var(--hud-dim); margin-right: 5px; font-variant-numeric: tabular-nums; }
.ticker-item .t-name { color: #93c5fd; margin-right: 4px; }
.ticker-item.t-error { color: #fca5a5; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

/* ---------- 右侧详情面板 ---------- */
.npc-panel {
  position: absolute; top: 56px; right: -380px; bottom: 44px; width: 350px; z-index: 980;
  background: var(--hud-bg); border: 1px solid var(--hud-border); border-right: none;
  border-radius: 12px 0 0 12px; color: var(--hud-text);
  transition: right 0.28s ease; display: flex; flex-direction: column;
  backdrop-filter: blur(6px);
}
.npc-panel.open { right: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.panel-emoji { font-size: 34px; }
.panel-title-wrap { flex: 1; min-width: 0; }
.panel-name { font-size: 17px; font-weight: 700; }
.panel-duty { font-size: 12px; color: var(--hud-dim); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-close { background: none; border: none; color: var(--hud-dim); font-size: 16px; cursor: pointer; padding: 4px 8px; }
.panel-close:hover { color: #fff; }
.panel-status { margin: 0 14px; padding: 7px 10px; border-radius: 8px; font-size: 13px; background: rgba(34,197,94,0.13); border: 1px solid rgba(34,197,94,0.35); }
.panel-status.st-yellow { background: rgba(234,179,8,0.13); border-color: rgba(234,179,8,0.4); }
.panel-status.st-red { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.45); }
.panel-task { margin: 8px 14px 0; font-size: 13px; color: #d1d5db; line-height: 1.45; }
.panel-task .lbl { color: var(--hud-dim); }
.panel-kpis { display: flex; gap: 8px; margin: 10px 14px 0; }
.panel-kpi { flex: 1; background: rgba(255,255,255,0.06); border: 1px solid var(--hud-border); border-radius: 8px; padding: 6px 8px; text-align: center; }
.panel-kpi .v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel-kpi .k { font-size: 11px; color: var(--hud-dim); margin-top: 2px; }
.panel-timeline-head { margin: 12px 14px 6px; font-size: 12px; font-weight: 700; color: var(--hud-dim); }
.panel-timeline { flex: 1; overflow-y: auto; margin: 0 6px 10px 14px; padding-right: 8px; font-size: 12.5px; }
.tl-entry { padding: 5px 0; border-bottom: 1px dashed rgba(255,255,255,0.08); line-height: 1.4; }
.tl-entry .tl-time { color: var(--hud-dim); margin-right: 6px; font-variant-numeric: tabular-nums; }
.tl-entry .tl-kind { margin-right: 4px; }
.tl-entry.tl-error { color: #fca5a5; }
.tl-empty { color: var(--hud-dim); padding: 12px 0; }

/* Leaflet 控件适配深色 HUD */
.leaflet-control-zoom { margin-bottom: 56px !important; }

@media (max-width: 760px) {
  .hud-title { display: none; }
  .npc-panel { width: 88vw; }
  .satellite-box { display: none; }
}
