/**
 * ExoAtlas Cislunar Visualizer — application styles
 * Mirrors /tools/orbit-visualizer/app/orbit-visualizer-app.css palette so that
 * the Cislunar app shares the dark theme used by the Orbit Visualizer and
 * Live View. Selectors use the cl-* prefix; visual treatment follows the
 * established system (#111 background, #181818 sidebar, #1a1a1a panels,
 * #333 borders, #eee text, #0b84ff accent).
 *
 * Copyright (c) 2026 ExoAtlas. All rights reserved.
 */

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #111;
  color: #eee;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body { display: flex; flex-direction: column; }

.cl-app {
  position: fixed; inset: 0;
  display: flex;
  width: 100%;
  height: 100%;
}

/* ------------------ Sidebar ------------------ */
#cl-sidebar {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  box-sizing: border-box;
  background: #181818;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 12px;
  gap: 0;
}

#cl-sidebar h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #fff;
  letter-spacing: -0.5px;
  text-align: center;
}

.cl-section {
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  margin-top: 12px;
}

.cl-section > [data-toggle] {
  width: 100%;
  margin: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #333;
  border-radius: 4px 4px 0 0;
  color: #eee;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.2s;
}
.cl-section > [data-toggle]:hover { background: #252525; }
.cl-section > [data-toggle]::after {
  content: '▼';
  font-size: 10px;
  color: #888;
}
.cl-section > [data-toggle][aria-expanded="false"]::after { content: '▶'; }
.cl-section > [data-toggle][aria-expanded="false"] {
  border-bottom: none;
  border-radius: 4px;
}

.cl-panel {
  padding: 8px 12px 12px;
  background: #1a1a1a;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cl-panel.collapsed { display: none; }

#cl-sidebar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #ccc;
  font-weight: 500;
  margin: 0;
}
#cl-sidebar label input[type="checkbox"],
#cl-sidebar label input[type="radio"] {
  width: auto;
  margin: 0 4px 0 0;
  cursor: pointer;
  accent-color: #0b84ff;
}
#cl-sidebar label:hover { color: #fff; }

#cl-sidebar input[type="text"],
#cl-sidebar input[type="number"],
#cl-sidebar select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: #0d0d0d;
  border: 1px solid #444;
  color: #eee;
  font-size: 12px;
  border-radius: 4px;
  transition: border-color 0.2s, background 0.2s;
}
#cl-sidebar input:focus,
#cl-sidebar select:focus {
  outline: none;
  border-color: #0b84ff;
  background: #1a1a1a;
}
#cl-sidebar input:hover:not(:focus),
#cl-sidebar select:hover { border-color: #555; }

#cl-sidebar button {
  margin: 0;
  width: 100%;
  padding: 8px 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #eee;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
#cl-sidebar button:hover { background: #333; border-color: #666; }
#cl-sidebar button:active { transform: translateY(1px); }

.cl-row { display: flex; gap: 6px; }
.cl-row > button { flex: 1; }

#cl-object-list {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  background: #0d0d0d;
}
#cl-object-list:empty { display: none; }
#cl-object-list li {
  padding: 6px 10px;
  border-bottom: 1px solid #1a1a1a;
  cursor: pointer;
  font-size: 12px;
  color: #ccc;
}
#cl-object-list li:last-child { border-bottom: none; }
#cl-object-list li.selected { background: #0b84ff; color: #fff; }
#cl-object-list li:hover:not(.selected) { background: #1f1f1f; color: #fff; }

.cl-prop {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: #ccc;
  border-bottom: 1px dashed #2a2a2a;
}
.cl-prop b { color: #fff; font-weight: 600; }

.cl-muted {
  color: #888;
  font-size: 11px;
  line-height: 1.4;
}
.cl-muted code {
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 0 4px;
  color: #aaa;
  font-size: 10.5px;
}

.cl-version {
  font-size: 11px;
  color: #888;
  margin-top: auto;
  padding: 12px 4px 4px;
  text-align: center;
}

/* Custom scrollbar (matches orbit-visualizer) */
#cl-sidebar::-webkit-scrollbar,
#cl-object-list::-webkit-scrollbar { width: 8px; }
#cl-sidebar::-webkit-scrollbar-track,
#cl-object-list::-webkit-scrollbar-track { background: #1a1a1a; }
#cl-sidebar::-webkit-scrollbar-thumb,
#cl-object-list::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
#cl-sidebar::-webkit-scrollbar-thumb:hover,
#cl-object-list::-webkit-scrollbar-thumb:hover { background: #444; }

/* ------------------ Viewport ------------------ */
#cl-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
  display: flex;
}

#cl-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#cl-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.cl-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-9999px, -9999px);
  background: rgba(17, 17, 17, 0.85);
  color: #eee;
  border: 1px solid #333;
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}
.cl-label-lagrange { color: #ffd700; border-color: #5a4500; }
.cl-label-site     { color: #87cefa; border-color: #244a66; }

/* ------------------ HUD ------------------ */
.cl-hud-top {
  position: absolute;
  top: 12px;
  /* Offset right by ~80px so the parent page's fullscreen toggle button
     (positioned at top:30 right:30, 44x44) does not overlap the HUD. */
  right: 90px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(17, 17, 17, 0.85);
  border: 1px solid #333;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  color: #ccc;
  z-index: 4;
  font-variant-numeric: tabular-nums;
}
#cl-frame-tag {
  font-weight: 600;
  letter-spacing: 0.5px;
  background: #0b84ff;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}
#cl-time-utc { color: #fff; }
#cl-fps { color: #888; }

#cl-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #888;
}
#cl-live-badge .cl-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #555;
}
#cl-live-badge.active {
  color: #38d97f;
}
#cl-live-badge.active .cl-dot {
  background: #38d97f;
  animation: cislunar-live-pulse 1.4s infinite ease-in-out;
}
@keyframes cislunar-live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(56, 217, 127, 0.6); }
  50%      { box-shadow: 0 0 0 6px rgba(56, 217, 127, 0); }
}

/* ------------------ Modal ------------------ */
.cl-modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
}
.cl-modal.open { display: flex; }
.cl-modal .cl-card {
  background: #181818;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 18px 20px;
  width: 380px;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #eee;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
}
.cl-modal h2 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid #333;
  padding-bottom: 8px;
  margin-bottom: 4px;
}
.cl-modal label {
  display: block;
  font-size: 12px;
  color: #ccc;
  font-weight: 500;
}
.cl-modal input[type="text"],
.cl-modal select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  margin-top: 4px;
  background: #0d0d0d;
  border: 1px solid #444;
  color: #eee;
  font-size: 12px;
  border-radius: 4px;
}
.cl-modal input:focus,
.cl-modal select:focus {
  outline: none;
  border-color: #0b84ff;
}
.cl-modal button {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #eee;
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.cl-modal button:hover { background: #333; border-color: #666; }
.cl-modal button[data-modal-action="add"] {
  background: #0b84ff;
  border-color: #0b84ff;
  color: #fff;
}
.cl-modal button[data-modal-action="add"]:hover {
  background: #0a7ae6;
  border-color: #0a7ae6;
}
.cl-modal .cl-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.cl-modal .cl-row > button { flex: 0 0 auto; width: auto; }

/* ------------------ Mobile ------------------ */
@media (max-width: 850px) {
  .cl-app { flex-direction: column; }
  #cl-sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid #333;
  }
  .cl-hud-top { font-size: 11px; padding: 4px 8px; right: 70px; }
}

/* ------------------ Loading screen ------------------ */
#cl-loading-screen {
  position: absolute;
  inset: 0;
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease-out;
  text-align: center;
  padding: 20px;
}
#cl-loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.cl-loader {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid #333;
  border-top-color: #0b84ff;
  animation: cl-spin 1s linear infinite;
  margin-bottom: 20px;
}
@keyframes cl-spin {
  to { transform: rotate(360deg); }
}
#cl-loading-text {
  color: #eee;
  font-size: 18px;
  font-weight: 500;
  margin-top: 8px;
  opacity: 0.9;
  letter-spacing: -0.2px;
}
#cl-loading-subtext {
  color: #888;
  font-size: 13px;
  margin-top: 6px;
}
