:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #627080;
  --line: #d7dde4;
  --accent: #0f6b5f;
  --accent-strong: #0a5249;
  --blue: #1565c0;
  --amber: #b7791f;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(23, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: linear-gradient(135deg, #0a3d2f 0%, #0f6b5f 60%, #1a8a6e 100%);
  border-bottom: 1px solid rgba(0,0,0,0.15);
  position: relative;
  z-index: 4;
  color: #fff;
}

.app-header .brand {
  margin-right: auto;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  color: #fff;
}

.brand-accent {
  font-weight: 400;
  opacity: 0.75;
  font-size: 13px;
  letter-spacing: 1.5px;
}

.app-header .scene-meta {
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}

.app-header .scene-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.app-header .scene-picker select {
  height: 32px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  padding: 0 10px;
  min-width: 340px;
  font-size: 13px;
}

.app-header .scene-picker select option,
.compact-select option {
  background: #fff;
  color: #000;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.app-header .segmented {
  border-color: rgba(255,255,255,0.3);
}

.app-header .segmented button {
  color: rgba(255,255,255,0.8);
  background: transparent;
  font-size: 12px;
  padding: 0 10px;
}

.app-header .segmented button.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.run-button {
  height: 32px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.12);
  color: #fff;
  padding: 0 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.run-button:hover {
  background: rgba(255,255,255,0.25);
}

.export-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.export-group .compact-select {
  height: 32px;
  font-size: 12px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-color: rgba(255,255,255,0.25);
  min-width: 70px;
}

.export-group .ghost-button {
  height: 32px;
  font-size: 12px;
  background: transparent;
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.export-group .ghost-button:hover {
  background: rgba(255,255,255,0.15);
}



.scene-meta,
.muted {
  color: var(--muted);
  font-size: 12px;
}



.scene-picker select,
.compact-select,
.select-row select,
.search-box input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  min-width: 0;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  height: 32px;
}

.segmented button {
  border: 0;
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.primary-button,
.ghost-button {
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
}

.ghost-button {
  background: #fff;
  color: var(--accent-strong);
  padding: 0 12px;
}

.workspace {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 380px;
  grid-template-rows: minmax(360px, 1fr) 250px;
  grid-template-areas:
    "sidebar map details"
    "sidebar table table";
}

.sidebar,
.details-panel,
.table-panel {
  background: var(--surface);
  border-color: var(--line);
}

.sidebar {
  grid-area: sidebar;
  overflow: auto;
  border-right: 1px solid var(--line);
}

.map-shell {
  grid-area: map;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.details-panel {
  grid-area: details;
  min-width: 0;
  overflow: hidden;
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
}

.table-panel {
  grid-area: table;
  min-height: 0;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  color: #334155;
  margin-bottom: 10px;
}

.search-box,
.select-row,
.toggle-row {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.toggle-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--ink);
}

.opacity-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.opacity-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.vv-info {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
  line-height: 1.35;
}

.vv-info .muted {
  font-size: 11px;
}

.range-block {
  margin: 8px 0 14px;
}

.range-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.range-block input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.check-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.check-title {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

.check-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.check-row span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 5px;
  background: #eef2f6;
  color: #334155;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
}

.badge.warn {
  color: #7c2d12;
  background: #ffedd5;
}

.badge.dark {
  color: #7f1d1d;
  background: #fee2e2;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  display: grid;
  gap: 6px;
  font-size: 12px;
  max-width: 260px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: center;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.details-content {
  overflow: auto;
  padding: 0 14px 14px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 12px 0;
  z-index: 2;
}

.tab-button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font-size: 12px;
}

.tab-button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

.kv {
  display: grid;
  grid-template-columns: minmax(120px, 0.85fr) minmax(0, 1.2fr);
  gap: 8px;
  border-bottom: 1px solid #edf1f5;
  padding: 8px 0;
  font-size: 12px;
}

.kv .key {
  color: var(--muted);
}

.kv .value {
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 11px;
}

.json-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #dbeafe;
  padding: 10px;
  border-radius: 6px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
}

.chip-panel {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  overflow: hidden;
}

.chip-panel-title {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.sar-chip-img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #020617;
  image-rendering: pixelated;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #edf1f5;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
  color: #334155;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eaf5f2;
}

.stats-panel {
  display: grid;
  gap: 10px;
  font-size: 12px;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(95px, 1fr) 48px;
  gap: 8px;
  align-items: center;
}

.bar-track {
  height: 7px;
  background: #e5eaf0;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.collapsed {
  display: none;
}

.details-panel.compact .details-content,
.table-panel.compact .table-wrap {
  display: none;
}

.table-panel.compact {
  grid-template-rows: auto;
}

@media (max-width: 1100px) {
  .app-header {
    grid-template-columns: 1fr 1fr;
    height: auto;
  }

  .workspace {
    height: calc(100vh - 124px);
    grid-template-columns: 260px 1fr;
    grid-template-rows: minmax(360px, 1fr) 260px;
    grid-template-areas:
      "sidebar map"
      "table table";
  }

  .details-panel {
    position: absolute;
    right: 0;
    top: 124px;
    bottom: 260px;
    width: min(380px, 96vw);
    z-index: 5;
    box-shadow: var(--shadow);
  }
}
