* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d1525;
  --bg-secondary: #131d2e;
  --bg-tertiary: #1a2740;
  --border: #2a3a52;
  --fg: #e6edf3;
  --fg-muted: #8b949e;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --accent: #58a6ff;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
  width: 100vw;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

header h1 span { color: var(--fg-muted); font-weight: 400; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-controls label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-controls select, .header-controls input {
  background: var(--bg-tertiary);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.header-controls input[type="range"] {
  width: 80px;
  padding: 0;
}

.btn {
  background: var(--bg-tertiary);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover { background: var(--border); }
.btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── Main content area ── */
#main {
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
}

#main.has-3d {
  grid-template-columns: 300px 1fr 1fr;
}

#main.has-chat {
  grid-template-columns: 300px 1fr 340px;
}

#main.has-3d.has-chat {
  grid-template-columns: 260px 1fr 1fr 320px;
}

/* ── Left panel: zone group tables ── */
#left-panel {
  overflow-y: auto;
  padding: 10px;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
}

#right-panel {
  overflow-y: auto;
  padding: 10px;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
}

.zone-group {
  margin-bottom: 12px;
}

.zone-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
  margin-bottom: 4px;
  padding: 4px 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  cursor: pointer;
}

.zone-group-title:hover { color: var(--fg); }
.zone-group-title.active { color: var(--accent); }

/* ── Heatmap mini-tables ── */
.heatmap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

.heatmap-table th {
  font-size: 9px;
  font-weight: 600;
  color: var(--fg-muted);
  text-align: right;
  padding: 2px 4px;
  border-bottom: 1px solid var(--border);
}

.heatmap-table th:first-child {
  text-align: left;
}

.heatmap-table td {
  padding: 2px 4px;
  text-align: right;
  border-bottom: 1px solid rgba(42,58,82,0.3);
  cursor: pointer;
}

.heatmap-table td:first-child {
  text-align: left;
  color: var(--fg-muted);
  font-weight: 500;
}

.heatmap-table tr:hover td {
  background: rgba(88,166,255,0.08);
}

.heatmap-table tr.selected td {
  background: rgba(88,166,255,0.15);
}

/* Heatmap cell colors */
.cell-green { color: #2ea043; background: rgba(46,160,67,0.12); }
.cell-yellow { color: #d29922; background: rgba(210,153,34,0.12); }
.cell-orange { color: #db6d28; background: rgba(219,109,40,0.15); }
.cell-red { color: #f85149; background: rgba(248,81,73,0.15); }
.cell-darkred { color: #ff4040; background: rgba(255,64,64,0.20); font-weight: 700; }

/* ── Viewport ── */
#viewport {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#viewport canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  display: none;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  max-width: 260px;
}

#tooltip.visible { display: block; }
#tooltip .tt-name { font-weight: 600; margin-bottom: 2px; }
#tooltip .tt-stat { color: var(--fg-muted); font-size: 10px; }

/* ── Area detail view (replaces right panel content) ── */
.detail-section {
  margin-bottom: 14px;
}

.detail-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

.detail-table th {
  font-size: 9px;
  font-weight: 600;
  color: var(--fg-muted);
  text-align: right;
  padding: 3px 4px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
}

.detail-table th:first-child { text-align: left; }

.detail-table td {
  padding: 3px 4px;
  text-align: right;
  border-bottom: 1px solid rgba(42,58,82,0.3);
}

.detail-table td:first-child {
  text-align: left;
  color: var(--fg-muted);
}

/* ── Chart area ── */
#chart-container {
  background: var(--bg-tertiary);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
}

#chart-container canvas {
  width: 100% !important;
  height: 180px !important;
}

.chart-title {
  font-size: 11px;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

.chart-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.chart-legend span {
  font-size: 9px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.chart-legend .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

/* ── View modes ── */
.view-tabs {
  display: flex;
  gap: 2px;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Chat panel ── */
#chat-messages {
  display: flex !important;
}

.chat-msg {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 95%;
  word-wrap: break-word;
}

.chat-msg.user {
  background: #1a2740;
  color: #e6edf3;
  align-self: flex-end;
  border: 1px solid #2a3a52;
}

.chat-msg.assistant {
  background: #131d2e;
  color: #e6edf3;
  align-self: flex-start;
  border: 1px solid #2a3a52;
}

.chat-msg.assistant h2, .chat-msg.assistant h3, .chat-msg.assistant h4 {
  margin: 4px 0 2px 0;
  color: #58a6ff;
}

.chat-msg.assistant code {
  background: #1a2740;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.chat-msg.assistant pre {
  background: #1a2740;
  padding: 6px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 4px 0;
}

.chat-msg.assistant strong { color: #58a6ff; }
.chat-msg.assistant ul { padding-left: 16px; margin: 2px 0; }
.chat-msg.assistant li { margin: 1px 0; }

.chat-msg.system {
  background: transparent;
  color: #8b949e;
  font-size: 11px;
  align-self: center;
  text-align: center;
}

.chat-msg.system code {
  background: #1a2740;
  padding: 1px 4px;
  border-radius: 3px;
  color: #58a6ff;
}

.chat-msg.thinking {
  background: #131d2e;
  color: #8b949e;
  font-size: 11px;
  font-style: italic;
  align-self: flex-start;
  border: 1px solid #2a3a52;
  max-height: 120px;
  overflow-y: auto;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.thinking-toggle {
  background: none;
  border: none;
  color: #8b949e;
  font-size: 10px;
  cursor: pointer;
  padding: 2px 8px;
  font-family: inherit;
}

.thinking-toggle:hover { color: #58a6ff; }
.thinking-toggle .brain { font-size: 12px; }

.thinking-saved {
  display: none;
  background: #131d2e;
  border: 1px solid #2a3a52;
  border-radius: 4px;
  padding: 6px;
  font-size: 10px;
  color: #8b949e;
  max-height: 150px;
  overflow-y: auto;
  margin: 2px 0;
}

.thinking-saved.open { display: block; }

.msg-thinking-btn {
  background: none;
  border: 1px solid #2a3a52;
  color: #8b949e;
  font-size: 10px;
  font-family: inherit;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
  margin-bottom: 4px;
}

.msg-thinking-btn:hover {
  color: #d29922;
  border-color: #d29922;
}

.msg-thinking-btn.active {
  color: #d29922;
  border-color: #d29922;
  animation: pulse 1.5s ease-in-out infinite;
}

.msg-thinking-panel {
  display: none;
  margin-top: 6px;
  padding: 8px;
  background: #0d1525;
  border: 1px solid #2a3a52;
  border-left: 2px solid #d29922;
  border-radius: 4px;
  font-size: 10px;
  color: #8b949e;
  max-height: 200px;
  overflow-y: auto;
  font-style: italic;
}

.msg-thinking-panel.open { display: block; }

.msg-thinking-panel code { background: #1a2740; padding: 1px 4px; border-radius: 3px; font-style: normal; }
.msg-thinking-panel hr { border: none; border-top: 1px solid #2a3a52; margin: 6px 0; }

.memory-section {
  margin-bottom: 12px;
  padding: 8px;
  background: #1a2740;
  border-radius: 4px;
  border-left: 2px solid #58a6ff;
}

.memory-section h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #58a6ff;
  margin: 0 0 6px 0;
}

.memory-section code {
  background: #131d2e;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}

.memory-section pre {
  background: #131d2e;
  padding: 6px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 4px 0;
  font-size: 10px;
}

.memory-section strong { color: #58a6ff; }
.memory-section ul { padding-left: 14px; margin: 2px 0; }
.memory-section li { margin: 1px 0; }

/* ── Measurement line elevation indicators on viewport ── */
.elevation-label {
  position: absolute;
  font-size: 10px;
  color: var(--green);
  font-family: monospace;
  pointer-events: none;
  white-space: nowrap;
}
