* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1e1e1e;
  --panel: #252526;
  --panel2: #2d2d30;
  --border: #3f3f46;
  --text: #cccccc;
  --text-bright: #ffffff;
  --accent: #007acc;
  --danger: #c42b1c;
  --success: #22c55e;
}

html, body, #app { height: 100%; font-family: "Segoe UI", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }

.shell { display: flex; flex-direction: column; height: 100%; }

.toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: var(--panel2); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.toolbar h1 { font-size: 15px; font-weight: 600; color: var(--text-bright); margin-right: 8px; }
.tb-sep { width: 12px; }

.btn {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 3px;
  background: var(--panel2); color: var(--text-bright); cursor: pointer; font-size: 12px;
}
.btn:hover { background: #3e3e42; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: #5a1e1a; border-color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-xs { padding: 2px 6px; font-size: 11px; }

.badge {
  margin-left: auto; padding: 2px 10px; border-radius: 10px; font-size: 11px;
  background: #3e3e42;
}
.badge.running { background: #14532d; color: #86efac; }
.badge.paused { background: #713f12; color: #fcd34d; }
.badge.replay { background: #4c1d95; color: #e9d5ff; }

.replay-bar {
  position: absolute; left: 10px; right: 10px; bottom: 52px; z-index: 6;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.82); padding: 8px 12px; border-radius: 6px;
  font-size: 12px; color: #fff;
}
.replay-bar input[type="range"] { flex: 1; min-width: 120px; }
.replay-select { width: 100%; padding: 8px; margin: 10px 0; }

.settings-form label {
  display: block; margin: 8px 0; font-size: 12px; color: var(--text);
}
.settings-form input[type="number"],
.settings-form input[type="text"] {
  margin-left: 8px; padding: 4px 8px; width: 120px;
}
.settings-form .muted { font-size: 11px; color: #888; margin: 4px 0; }
.settings-form input.wide { width: 220px; }

.settings-body { max-height: 55vh; overflow: auto; padding: 8px 0; }

.settings-sources .ds-table { font-size: 11px; margin-top: 8px; }
.settings-sources .ds-table th { background: #fff; color: #000; }
.settings-sources .ds-table td { background: #fff; color: #000; }
.settings-toolbar { margin-bottom: 6px; }
.source-editor {
  margin-top: 12px; padding: 12px; border: 1px solid var(--border);
  border-radius: 6px; background: #1a2332;
}

.settings-rules .rules-layout {
  display: flex; gap: 12px; min-height: 280px;
}
.rule-list {
  list-style: none; width: 200px; flex-shrink: 0;
  background: #1a2332; border-radius: 6px; overflow: auto; max-height: 320px;
}
.rule-list li {
  padding: 10px; cursor: pointer; border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.rule-list li.active { background: var(--accent); color: #fff; }
.rule-list li span { display: block; color: #aaa; margin-top: 4px; font-size: 10px; }
.rule-list li.active span { color: #dbeafe; }
.rule-detail { flex: 1; padding: 8px; }
.conn { font-size: 11px; display: flex; align-items: center; gap: 4px; }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.conn-dot.ok { background: var(--success); }
.conn-dot.off { background: var(--danger); }

.main { display: flex; flex: 1; min-height: 0; }

.map-wrap { flex: 1; position: relative; min-width: 0; background: #1e1e1e; }
#map { width: 100%; height: 100%; }

.layer-panel {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  background: rgba(0, 0, 0, 0.72); border-radius: 5px; padding: 10px 12px;
  font-size: 12px; color: #fff; min-width: 160px;
}
.layer-title { font-weight: bold; margin-bottom: 8px; font-size: 12px; }
.layer-panel label { display: flex; align-items: center; gap: 6px; margin: 4px 0; cursor: pointer; }
.layer-style { margin-top: 8px; padding-top: 6px; border-top: 1px solid #555; }
.layer-style select {
  width: 100%; margin-top: 4px; padding: 4px; background: #3f3f46; color: #fff; border: 1px solid #555;
}
.layer-hint { margin-top: 8px; font-size: 10px; color: #aaa; line-height: 1.4; }
.marker-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 120px; overflow-y: auto; font-size: 11px; }
.marker-list li { display: flex; justify-content: space-between; align-items: center; gap: 4px; padding: 2px 0; border-bottom: 1px solid #444; }
.detail-grid { display: grid; grid-template-columns: 72px 1fr; gap: 6px 10px; font-size: 13px; margin: 0 0 12px; }
.detail-grid dt { color: #888; margin: 0; }
.detail-grid dd { margin: 0; color: #f0f0f0; }
.ds-summary { margin-left: 6px; font-size: 11px; color: #9cdcfe; }
.ds-state.on { color: #4ade80; }
.ds-state.off { color: #f87171; }

.health-panel {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  background: rgba(0, 0, 0, 0.8); border-radius: 5px; padding: 10px; min-width: 200px;
}
.hp-name { color: #fff; font-weight: bold; font-size: 13px; margin-bottom: 6px; }
.hp-bar { height: 18px; background: #333; border-radius: 3px; border: 1px solid #666; overflow: hidden; }
.hp-fill { height: 100%; background: linear-gradient(90deg, #22c55e, #84cc16); transition: width 0.3s; }
.hp-text { color: #ddd; font-size: 11px; text-align: center; margin-top: 4px; }

.map-footer {
  position: absolute; left: 10px; bottom: 36px; z-index: 4;
  background: rgba(0, 0, 0, 0.75); padding: 5px 10px; border-radius: 3px;
  font-size: 12px; color: #fff;
}
.map-attrib {
  position: absolute; left: 10px; bottom: 8px; z-index: 4;
  font-size: 10px; color: #aaa;
}

.side {
  width: 400px; display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--panel);
  min-height: 0;
}

.panel {
  display: flex; flex-direction: column; min-height: 0;
  border-bottom: 1px solid var(--border);
  flex: 1 1 33%;
}
.panel.flex { flex: 1 1 40%; }
.panel.stats-panel { flex: 0 0 auto; padding: 8px 10px 12px; }
.panel h2 {
  font-size: 14px; color: var(--text-bright); font-weight: bold;
  padding: 8px 10px 4px;
}

.table-scroll { flex: 1; overflow: auto; padding: 0 4px 6px; }

table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 5px 6px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #fff; color: #000; font-weight: bold; position: sticky; top: 0; z-index: 1; }
tbody tr { background: #fff; color: #000; cursor: pointer; }
tbody tr:hover { background: #f0f0f0; }
tr.selected td { background: #e0e0e0; }

.sub-tabs { display: flex; padding: 0 8px; gap: 4px; }
.sub-tabs button {
  flex: 1; padding: 5px; border: none; background: var(--panel2); color: var(--text);
  cursor: pointer; font-size: 12px;
}
.sub-tabs button.active { background: var(--accent); color: #fff; }

.stats-line { font-size: 12px; padding: 2px 0; color: var(--text); }
.stats-line.muted { color: #888; font-size: 11px; }

.statusbar {
  display: flex; justify-content: space-between; padding: 4px 12px;
  background: var(--accent); color: #fff; font-size: 12px;
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 18px; min-width: 320px; max-width: 90vw;
}
.modal-wide { min-width: 480px; max-width: 720px; }
.modal h3 { color: var(--text-bright); margin-bottom: 12px; font-size: 15px; }
.modal label { display: block; font-size: 12px; margin: 8px 0 4px; }
.modal select {
  width: 100%; padding: 8px; background: #fff; color: #000; border: 1px solid var(--border);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.config-pre {
  max-height: 360px; overflow: auto; background: #1e1e1e; color: #9cdcfe;
  padding: 10px; font-size: 11px; border-radius: 4px;
}
