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

:root {
  --bg-dark: #0b0f19;
  --panel-bg: rgba(15, 23, 42, 0.82);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-hover: rgba(255, 255, 255, 0.06);
  --z-sidebar: 25;
  --z-sidebar-toggle: 20;
  --z-modal: 100;
  --z-globe: 1;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-cyan: #38bdf8;
  --accent-red: #ef4444;
  --accent-amber: #fbbf24;
  --accent-emerald: #10b981;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-panel: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Fullscreen Globe Canvas */
#globus {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-globe);
}

/* Floating Sidebar Toggle Button (Floating when sidebar is collapsed) */
.sidebar-toggle-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: var(--z-sidebar-toggle);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: var(--shadow-panel);
  transition: var(--transition);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.sidebar-toggle-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.sidebar-toggle-btn:hover {
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
}

/* OpenGlobus Popup Custom Dark Styling */
.og-popup-content-wrapper {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  color: var(--text-primary);
  padding: 4px;
}

.og-popup-tip {
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
}

.og-popup-btn {
  color: var(--text-secondary);
  transition: var(--transition);
}

.og-popup-btn:hover {
  color: #ef4444;
}

/* Collapsible Floating Glass Sidebar */
.sidebar {
  position: absolute;
  top: 20px;
  left: 20px;
  bottom: 20px;
  width: 360px;
  max-width: calc(100vw - 40px);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  transform: translateX(-110%);
  opacity: 0;
  pointer-events: none;
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.02);
}

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

.brand-badge {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  box-shadow: 0 0 12px var(--accent-cyan);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

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

/* Sections */
.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}

.section-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

/* Control Rows */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.control-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.segment-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.segment-btn.active {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Layer Dropdown */
.layer-dropdown {
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  max-width: 180px;
}

.layer-dropdown:focus {
  border-color: var(--accent-cyan);
}

.layer-dropdown option {
  background: var(--bg-dark);
  color: var(--text-primary);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

input:checked+.slider {
  background-color: var(--accent-blue);
}

input:checked+.slider:before {
  transform: translateX(16px);
}

/* Primary Action Button */
.btn-primary-action {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #bfdbfe;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary-action:hover {
  background: rgba(59, 130, 246, 0.35);
  border-color: rgba(59, 130, 246, 0.7);
  color: #fff;
}

/* Assets Tree Scrollable Area */
.assets-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: none;
}

.asset-tree {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.asset-tree::-webkit-scrollbar,
.photo-grid::-webkit-scrollbar {
  width: 5px;
}

.asset-tree::-webkit-scrollbar-thumb,
.photo-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

/* Category Card */
.category-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition);
}

.category-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  background: rgba(255, 255, 255, 0.02);
}

.category-header:hover {
  background: var(--panel-hover);
}

.category-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-pip {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  box-shadow: 0 0 8px currentColor;
}

.category-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.badge-count {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

.category-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-checkbox {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: var(--transition);
}

.custom-checkbox:checked {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

.custom-checkbox:checked::before {
  content: "";
  width: 8px;
  height: 8px;
  background-color: white;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.chevron-icon {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.category-card.open .chevron-icon {
  transform: rotate(90deg);
}

/* Category Body */
.category-body {
  display: none;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.15);
}

.category-card.open .category-body {
  display: block;
}

/* Opacity Slider Container */
.opacity-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}

.opacity-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Layers List */
.layers-sublist {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  color: var(--text-secondary);
  transition: var(--transition);
}

.layer-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary);
}

.layer-item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Photo Thumbnail Grid in Sidebar */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
  max-height: 150px;
  overflow-y: auto;
  padding: 2px;
}

.photo-thumb-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #000;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: var(--transition);
}

.photo-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb-btn:hover {
  transform: scale(1.05);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
  z-index: 2;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.2);
}

.footer-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 6px var(--accent-emerald);
}

/* Loading Spinners */
.loading-spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Photo Lightbox Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: var(--z-modal);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.open .modal-content {
  transform: scale(1);
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.modal-close-btn:hover {
  background: rgba(239, 68, 68, 0.8);
  border-color: transparent;
}

.modal-image-container {
  flex: 1;
  min-height: 300px;
  max-height: 70vh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.modal-image-container img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.modal-meta-bar {
  padding: 16px 20px;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.modal-subtags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.tag-group {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-secondary-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-secondary-action:hover {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .sidebar {
    width: 100%;
    left: 10px;
    right: 10px;
    top: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
  }
}