/* === Base Reset === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  overflow: hidden;
}

/* === Top Bar === */
#topBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  z-index: 10;
}

#topBar h1 {
  font-size: 16px;
  font-weight: 600;
  color: #00d4ff;
  letter-spacing: 0.5px;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#userName {
  font-size: 13px;
  color: #8b949e;
}

#logoutBtn {
  padding: 4px 12px;
  font-size: 12px;
  background: transparent;
  color: #f85149;
  border: 1px solid #f8514966;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

#logoutBtn:hover {
  background: #f8514922;
  border-color: #f85149;
}

/* === Layout === */
#appLayout {
  display: flex;
  height: calc(100vh - 48px);
}

/* === Side Panel === */
#sidePanel {
  width: 320px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  background: #161b22;
  border-right: 1px solid #30363d;
}

.filters {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid #30363d;
}

.filters input,
.filters select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

.filters input:focus,
.filters select:focus {
  border-color: #00d4ff;
}

.filters select option {
  background: #0d1117;
}

#counter {
  font-size: 12px;
  color: #8b949e;
  text-align: center;
  padding: 4px 0;
}

/* === Service List === */
#serviceList {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

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

#serviceList::-webkit-scrollbar-track {
  background: #0d1117;
}

#serviceList::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

#serviceList::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

/* === Service Card === */
.service-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin-bottom: 4px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  cursor: default;
  transition: all 0.15s;
}

.service-card:hover {
  border-color: #00d4ff44;
  background: #161b2288;
}

.service-card.active {
  border-color: #00d4ff88;
  background: #00d4ff0a;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 12px;
  font-weight: 500;
  color: #e6edf3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* === Badges === */
.badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 500;
  border-radius: 10px;
  white-space: nowrap;
}

/* Type badges */
.badge-SceneLayer {
  background: #1f6feb22;
  color: #58a6ff;
  border: 1px solid #1f6feb44;
}

.badge-BuildingSceneLayer {
  background: #d2992222;
  color: #e3b341;
  border: 1px solid #d2992244;
}

.badge-PointCloud {
  background: #23863622;
  color: #3fb950;
  border: 1px solid #23863644;
}

.badge-Point {
  background: #a371f722;
  color: #a371f7;
  border: 1px solid #a371f744;
}

.badge-IntegratedMesh {
  background: #f7814622;
  color: #f78146;
  border: 1px solid #f7814644;
}

/* Industry badges */
.badge-industry {
  background: #30363d;
  color: #8b949e;
  border: 1px solid #484f5844;
}

/* === Toggle Switch === */
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #30363d;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.25s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #8b949e;
  border-radius: 50%;
  transition: all 0.25s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #00d4ff;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: #fff;
}

/* === Local Viewer Button === */
.btn-local-viewer {
  background: none;
  border: 1px solid #3fb95044;
  color: #3fb950;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-local-viewer:hover {
  background: #3fb95022;
  border-color: #3fb950;
}

.btn-local-viewer.in-local {
  border-color: #f8514966;
  color: #f85149;
}

.btn-local-viewer.in-local:hover {
  background: #f8514922;
  border-color: #f85149;
}

/* === Local Viewer Modal === */
#localViewerModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70vw;
  height: 70vh;
  max-width: 1100px;
  max-height: 750px;
  min-width: 400px;
  min-height: 300px;
  z-index: 300;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#localViewerBackdrop {
  position: fixed;
  top: 48px;
  left: 320px;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 299;
  pointer-events: none;
}

.local-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  height: 40px;
  flex-shrink: 0;
  cursor: default;
}

.local-viewer-header span {
  font-size: 13px;
  font-weight: 600;
  color: #a371f7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.local-viewer-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

#localViewerMaximize,
#localViewerClose {
  background: none;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

#localViewerMaximize {
  border: 1px solid #8b949e44;
  color: #8b949e;
}

#localViewerMaximize:hover {
  background: #8b949e22;
  border-color: #8b949e;
}

#localViewerClose {
  border: 1px solid #f8514944;
  color: #f85149;
}

#localViewerClose:hover {
  background: #f8514922;
  border-color: #f85149;
}

/* Maximized state */
#localViewerModal.maximized {
  top: 0;
  left: 0;
  transform: none;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  border: none;
}

#localSceneView {
  flex: 1;
  width: 100%;
}

/* === Panel Footer === */
.panel-footer {
  padding: 8px 12px;
  border-top: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-footer button {
  width: 100%;
  padding: 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

#loadMoreBtn {
  background: #1f6feb22;
  color: #58a6ff;
  border: 1px solid #1f6feb44;
}

#loadMoreBtn:hover {
  background: #1f6feb44;
}

#removeAllBtn {
  background: #f8514911;
  color: #f85149;
  border: 1px solid #f8514933;
}

#removeAllBtn:hover {
  background: #f8514922;
  border-color: #f85149;
}

/* === 3D Scene View === */
#sceneView {
  flex: 1;
  position: relative;
}

/* === Active Layers Floating Panel === */
#activeLayersPanel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 280px;
  max-height: 300px;
  background: #161b22dd;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #30363d;
  border-radius: 10px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.active-header {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid #30363d;
  color: #8b949e;
}

.active-header strong {
  color: #00d4ff;
}

#activeLayersList {
  list-style: none;
  overflow-y: auto;
  max-height: 240px;
  padding: 4px 0;
}

#activeLayersList::-webkit-scrollbar {
  width: 4px;
}

#activeLayersList::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 2px;
}

#activeLayersList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  font-size: 12px;
  color: #c9d1d9;
}

#activeLayersList li span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 8px;
}

#activeLayersList li button {
  background: none;
  border: none;
  color: #f85149;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
}

#activeLayersList li button:hover {
  background: #f8514922;
}

.empty-active {
  padding: 12px 14px;
  font-size: 12px;
  color: #484f58;
  text-align: center;
}

/* === Toast Notifications === */
#toastContainer {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  font-size: 13px;
  border-radius: 8px;
  background: #161b22ee;
  backdrop-filter: blur(8px);
  border: 1px solid #30363d;
  color: #c9d1d9;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 3.7s forwards;
  max-width: 360px;
}

.toast.error {
  border-color: #f8514966;
  color: #f85149;
}

.toast.success {
  border-color: #3fb95066;
  color: #3fb950;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* === Loading Overlay === */
#loadingOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0d111788;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 500;
  color: #c9d1d9;
  font-size: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #30363d;
  border-top-color: #00d4ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Auth Overlay === */
#authOverlay {
  position: fixed;
  inset: 0;
  background: #0d1117;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.auth-box {
  width: 380px;
  padding: 40px 32px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  text-align: center;
}

.auth-box h2 {
  font-size: 22px;
  color: #00d4ff;
  margin-bottom: 28px;
}

.auth-subtitle {
  font-size: 13px;
  color: #8b949e;
  margin-bottom: 28px;
}

.auth-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-btn {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-btn-primary {
  background: #00d4ff;
  color: #0d1117;
  border: none;
}

.auth-btn-primary:hover {
  background: #33dfff;
}

.auth-btn-secondary {
  background: #1f6feb22;
  color: #58a6ff;
  border: 1px solid #1f6feb44;
}

.auth-btn-secondary:hover {
  background: #1f6feb44;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0;
  color: #484f58;
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #30363d;
}

.auth-token-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-token-hint {
  font-size: 12px;
  color: #8b949e;
  line-height: 1.5;
}

.auth-token-hint a {
  color: #58a6ff;
  text-decoration: none;
}

.auth-token-hint a:hover {
  text-decoration: underline;
}

#manualTokenInput {
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  font-family: monospace;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

#manualTokenInput:focus {
  border-color: #00d4ff;
}

/* === Responsive (small screens) === */
@media (max-width: 768px) {
  #sidePanel {
    width: 100%;
    min-width: 100%;
    max-height: 50vh;
  }

  #appLayout {
    flex-direction: column;
  }

  #activeLayersPanel {
    width: calc(100% - 32px);
  }
}
