/* ============================================================
   Making the Underground Visible — Wilmersdorfer Strasse
   Dark theme (#0d1117) - Berlin urban planning visualization
   ============================================================ */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --border-light: #484f58;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-yellow: #d29922;
  --accent-orange: #f0883e;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --panel-width: 320px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

canvas {
  display: block;
}

/* ---- Header Bar ---- */
#header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 16px;
}

#header h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

#header .subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

#header .tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(209, 153, 34, 0.15);
  color: var(--accent-yellow);
  border: 1px solid rgba(209, 153, 34, 0.3);
  white-space: nowrap;
}

#header .spacer {
  flex: 1;
}

#header .help-btn {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}

#header .help-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* ---- Left Panel (Layers + Controls) ---- */
#left-panel {
  position: absolute;
  top: 56px;
  left: 8px;
  width: var(--panel-width);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.panel-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.panel-header .toggle-icon {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.panel-header.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.panel-body {
  padding: 8px 12px;
}

.panel-body.collapsed {
  display: none;
}

/* ---- Layer Toggle Items ---- */
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  cursor: pointer;
  transition: opacity 0.15s;
}

.layer-item:hover {
  opacity: 0.85;
}

.layer-item input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-light);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.layer-item input[type="checkbox"]:checked {
  border-color: var(--accent-blue);
  background: var(--accent-blue);
}

.layer-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 3px;
  width: 4px;
  height: 7px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.layer-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-label {
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
}

.layer-depth {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', Consolas, monospace;
}

/* ---- Slider Controls ---- */
.slider-group {
  padding: 8px 0;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.slider-group label span.value {
  font-family: 'SF Mono', Consolas, monospace;
  color: var(--accent-blue);
  font-size: 12px;
}

.slider-group input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(88, 166, 255, 0.4);
}

.slider-group input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 4px rgba(88, 166, 255, 0.4);
}

/* ---- Plant Here Button ---- */
.tool-btn {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  margin-top: 4px;
}

.tool-btn:hover {
  border-color: var(--accent-green);
  background: rgba(63, 185, 80, 0.1);
}

.tool-btn.active {
  border-color: var(--accent-green);
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent-green);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.2);
}

/* ---- Right Panel (Info / Coordination) ---- */
#right-panel {
  position: absolute;
  top: 56px;
  right: 8px;
  width: var(--panel-width);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- Info Panel ---- */
#info-panel {
  display: none;
}

#info-panel.visible {
  display: block;
}

#info-panel .info-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

#info-panel .info-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

#info-panel .info-row:last-child {
  border-bottom: none;
}

#info-panel .info-key {
  color: var(--text-secondary);
}

#info-panel .info-val {
  color: var(--text-primary);
  font-family: 'SF Mono', Consolas, monospace;
  text-align: right;
}

#info-panel .info-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(209, 153, 34, 0.15);
  color: var(--accent-yellow);
  margin-left: 4px;
}

.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-primary);
  background: var(--border);
}

/* ---- Coordination Timeline ---- */
.timeline-bar-container {
  padding: 4px 0;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 11px;
}

.timeline-label {
  width: 90px;
  text-align: right;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-size: 11px;
}

.timeline-track {
  flex: 1;
  height: 16px;
  position: relative;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.timeline-bar {
  position: absolute;
  top: 2px;
  height: 12px;
  border-radius: 2px;
  opacity: 0.85;
}

.timeline-bar.overdue {
  animation: pulse-bar 2s ease-in-out infinite;
}

@keyframes pulse-bar {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.5; }
}

.timeline-year-labels {
  display: flex;
  justify-content: space-between;
  padding: 2px 96px 0 96px;
  font-size: 10px;
  color: var(--text-muted);
}

.timeline-now-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent-red);
  z-index: 2;
}

/* ---- Clearance Result Overlay ---- */
#clearance-result {
  display: none;
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  z-index: 95;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  text-align: center;
  min-width: 280px;
}

#clearance-result.visible {
  display: block;
}

#clearance-result.green {
  background: rgba(63, 185, 80, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

#clearance-result.yellow {
  background: rgba(210, 153, 34, 0.15);
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

#clearance-result.red {
  background: rgba(248, 81, 73, 0.15);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

#clearance-result .result-detail {
  font-size: 12px;
  font-weight: 400;
  margin-top: 4px;
  opacity: 0.8;
}

/* ---- Bottom Status Bar ---- */
#status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11px;
  color: var(--text-muted);
  gap: 16px;
  z-index: 100;
}

#status-bar .status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

#status-bar .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}

/* ---- Tooltip ---- */
#tooltip {
  display: none;
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow);
  max-width: 240px;
}

#tooltip.visible {
  display: block;
}

#tooltip .tt-title {
  font-weight: 600;
  margin-bottom: 4px;
}

#tooltip .tt-row {
  color: var(--text-secondary);
  font-size: 11px;
}

/* ---- Help Modal ---- */
#help-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  justify-content: center;
  align-items: center;
}

#help-modal.visible {
  display: flex;
}

#help-modal .modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 520px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#help-modal h2 {
  font-size: 16px;
  margin-bottom: 16px;
  color: var(--text-primary);
}

#help-modal .help-section {
  margin-bottom: 14px;
}

#help-modal .help-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

#help-modal .help-section p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

#help-modal kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: 'SF Mono', Consolas, monospace;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  :root {
    --panel-width: 260px;
  }
}

@media (max-width: 720px) {
  :root {
    --panel-width: 220px;
  }

  #header h1 { font-size: 13px; }
  #header .subtitle { display: none; }

  #left-panel, #right-panel {
    width: var(--panel-width);
  }
}

@media (max-width: 540px) {
  #left-panel {
    left: 4px;
    width: calc(100vw - 8px);
    max-height: 40vh;
  }

  #right-panel {
    right: 4px;
    width: calc(100vw - 8px);
    top: auto;
    bottom: 36px;
    max-height: 35vh;
  }
}
