* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: #0d1117; color: #c9d1d9; font-family: -apple-system, "Helvetica Neue", "Segoe UI", Roboto, sans-serif; font-size: 14px; }

/* ---------- header ---------- */
header {
  position: fixed; top: 0; left: 0; right: 0; height: 48px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: rgba(13,17,23,0.92); border-bottom: 1px solid #30363d;
  z-index: 10;
}
.brand { flex-shrink: 0; }
.brand strong { color: #58a6ff; margin-right: 12px; }
.brand .byline { color: #8b949e; font-size: 12px; }
.header-stats { flex: 1; color: #8b949e; font-size: 12px; text-align: right; padding-right: 12px; }
.header-stats span.k { color: #c9d1d9; font-weight: 600; }
.badge { font-size: 11px; padding: 4px 8px; border-radius: 4px; background: #21262d; color: #c9d1d9; flex-shrink: 0; }
.badge.ok { background: #1a3a1f; color: #3fb950; }
.badge.bad { background: #3a1d1d; color: #f85149; }

/* ---------- filter bar ---------- */
#filter-bar {
  position: fixed; top: 48px; left: 0; right: 0; height: 36px;
  display: flex; align-items: center; gap: 6px; padding: 0 14px;
  background: rgba(13,17,23,0.92); border-bottom: 1px solid #30363d; font-size: 12px;
  z-index: 9; overflow-x: auto;
}
.filter-label { color: #6e7681; margin-right: 4px; }
.filter-pill {
  background: #21262d; color: #c9d1d9; border: 1px solid #30363d; border-radius: 12px;
  padding: 3px 10px; font-size: 11px; cursor: pointer; white-space: nowrap;
}
.filter-pill:hover { background: #30363d; }
.filter-pill.active { background: #1f6feb; color: white; border-color: #1f6feb; }
.filter-pill.action { background: transparent; border-color: #58a6ff; color: #58a6ff; }
.filter-pill.action:hover { background: rgba(88,166,255,0.1); }
.filter-sep { color: #30363d; margin: 0 4px; }
.visible-counter { color: #6e7681; margin-left: auto; font-size: 11px; }

/* ---------- main layout ---------- */
main { position: absolute; top: 84px; bottom: 32px; left: 0; right: 0; display: flex; }
#cesiumContainer { flex: 1; height: 100%; position: relative; }

/* ---------- zoom controls ---------- */
#zoom-controls {
  position: absolute; bottom: 14px; right: 14px; display: flex; flex-direction: column; gap: 4px;
  z-index: 5;
}
.zoom-btn {
  width: 36px; height: 36px; background: rgba(22,27,34,0.92); color: #c9d1d9;
  border: 1px solid #30363d; border-radius: 6px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: #30363d; }
.zoom-btn.active { background: #1f6feb; color: white; border-color: #1f6feb; }

/* ---------- detail card ---------- */
aside#detail-card {
  position: absolute; top: 14px; right: 14px; width: 340px;
  max-height: calc(100% - 28px); overflow-y: auto;
  background: rgba(22,27,34,0.96); border: 1px solid #30363d; border-radius: 8px;
  padding: 14px 16px 12px 16px; z-index: 6; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
aside#detail-card.hidden { display: none; }
#detail-card h3 { margin: 0 0 6px 0; color: #58a6ff; font-size: 15px; padding-right: 24px; word-break: break-all; }
#detail-card .close-btn {
  position: absolute; top: 8px; right: 10px; background: transparent; color: #8b949e;
  border: 0; font-size: 20px; cursor: pointer; line-height: 1;
}
#detail-card .close-btn:hover { color: #f85149; }
.detail-status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-bottom: 10px; }
.detail-status.operational { background: #1a3a1f; color: #3fb950; }
.detail-status.maintenance { background: #3a2e1a; color: #d29922; }
.detail-status.faulty { background: #3a1d1d; color: #f85149; }
.detail-status.decommissioned { background: #21262d; color: #8b949e; }
.detail-status.stolen { background: #2d1f3a; color: #a371f7; }
table.detail-table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-bottom: 12px; }
table.detail-table td { padding: 3px 4px; vertical-align: top; }
table.detail-table td:first-child { color: #6e7681; width: 40%; }
table.detail-table td:last-child { color: #c9d1d9; word-break: break-word; }
.telemetry-panel { border-top: 1px solid #30363d; padding-top: 10px; }
.telemetry-header { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #8b949e; margin-bottom: 6px; }
.telemetry-status { color: #6e7681; font-size: 10.5px; }
.telemetry-charts { display: flex; flex-direction: column; gap: 6px; }
.telemetry-chart { background: #0d1117; padding: 4px 6px; border-radius: 4px; }
.telemetry-label { font-size: 10px; color: #6e7681; margin-bottom: 2px; }
.telemetry-chart svg { width: 100%; height: 36px; display: block; }
.telemetry-chart svg path { fill: none; stroke: #58a6ff; stroke-width: 1.5; }
.telemetry-chart svg .axis { stroke: #30363d; stroke-width: 0.5; }
.telemetry-chart.no-data svg { opacity: 0.3; }
.detail-footer { margin-top: 10px; padding-top: 8px; border-top: 1px solid #30363d; font-size: 11px; }
.detail-link { background: transparent; border: 0; color: #58a6ff; cursor: pointer; padding: 0; font-size: 11px; }
.detail-link:hover { text-decoration: underline; }

/* ---------- chat panel ---------- */
aside#chat-panel {
  width: 380px; background: #161b22; border-left: 1px solid #30363d;
  display: flex; flex-direction: column; flex-shrink: 0;
}
#chat-header { padding: 10px 14px; border-bottom: 1px solid #30363d; display: flex; justify-content: space-between; align-items: center; }
#chat-header button { background: transparent; border: 1px solid #30363d; color: #c9d1d9; cursor: pointer; padding: 2px 8px; border-radius: 4px; }
#chat-header button:hover { background: #21262d; }
#chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; }
.msg { margin-bottom: 12px; }
.msg.user { color: #58a6ff; }
.msg.user::before { content: "you · "; color: #6e7681; }
.msg.bot { color: #c9d1d9; }
.msg.bot::before { content: "assistant · "; color: #6e7681; }
.msg .meta { color: #6e7681; font-size: 11px; margin-top: 4px; }
.msg .device-link { color: #58a6ff; cursor: pointer; text-decoration: underline; }
.msg .device-link:hover { color: #79c0ff; }
.msg.bot.thinking::after { content: " ▍"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
#chat-form { display: flex; padding: 10px 12px; border-top: 1px solid #30363d; background: #0d1117; }
#chat-input { flex: 1; background: #21262d; color: #c9d1d9; border: 1px solid #30363d; border-radius: 4px; padding: 8px 10px; font-size: 13px; }
#chat-input:focus { outline: none; border-color: #58a6ff; }
#chat-input:disabled { opacity: 0.5; }
#chat-form button { background: #238636; color: white; border: 0; padding: 8px 14px; border-radius: 4px; margin-left: 8px; cursor: pointer; min-width: 44px; }
#chat-form button:hover { background: #2ea043; }
#chat-form button:disabled { background: #30363d; cursor: wait; }
.chat-submit-spinner { animation: spin 1s linear infinite; display: inline-block; }
.chat-submit-spinner.hidden { display: none; }
.chat-submit-text.hidden { display: none; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

#trace-details { padding: 0 14px 12px 14px; color: #8b949e; font-size: 12px; }
#trace-details summary { cursor: pointer; padding: 8px 0; }
#trace-log { background: #0d1117; padding: 8px; border-radius: 4px; font-size: 11px; max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* ---------- footer ---------- */
footer {
  position: fixed; bottom: 0; left: 0; right: 0; height: 32px;
  display: flex; justify-content: space-around; align-items: center;
  padding: 0 16px; background: rgba(13,17,23,0.92);
  border-top: 1px solid #30363d; font-size: 11px; color: #8b949e;
}
footer a { color: #58a6ff; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ---------- Cesium tweaks ---------- */
.cesium-credit-lightbox-overlay { z-index: 1000 !important; }
.cesium-viewer-toolbar, .cesium-viewer-fullscreenContainer { display: none !important; }
.cesium-credit-textContainer { font-size: 10px !important; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  aside#chat-panel { width: 320px; }
  aside#detail-card { width: 280px; }
}
