:root {
  --bg-main: #0d1117;
  --bg-panel: #161b22;
  --bg-card: #21262d;
  --border-color: #30363d;
  --border-focus: #58a6ff;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-blue: #388bfd;
  --accent-blue-hover: #1f6feb;
  --accent-red: #d92525;
  --accent-gold: #d29922;
  --accent-green: #238636;
  --chart-border: #111111;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* App Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Top Header */
.top-header {
  height: 60px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.om-logo {
  height: 32px;
  width: 32px;
  border-radius: 6px;
  background: white;
  padding: 2px;
}

.title-group {
  display: flex;
  flex-direction: column;
}

.main-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-sans);
  user-select: none;
}

.btn-primary {
  background: var(--accent-green);
  color: #ffffff;
  border-color: rgba(240, 246, 252, 0.1);
}

.btn-primary:hover {
  background: #2ea043;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover, .btn-secondary.active {
  background: #30363d;
  border-color: #8b949e;
  color: #58a6ff;
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-outline:hover {
  background: var(--bg-card);
  border-color: #58a6ff;
  color: #58a6ff;
}

.btn-icon {
  padding: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-icon:hover {
  background: #30363d;
  color: var(--accent-blue);
}

.full-width {
  width: 100%;
  justify-content: center;
}

.small-btn {
  padding: 6px 10px;
  font-size: 0.78rem;
}

/* Workspace Body */
.workspace-body {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 340px;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex-shrink: 0;
  z-index: 500;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

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

.panel-section {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section-heading {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.section-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: 1.25rem;
  font-weight: 700;
  color: #58a6ff;
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-top: 2px;
}

/* Basemap Style Selector */
.basemap-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.style-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}

.style-chip:hover {
  border-color: #58a6ff;
}

.style-chip.active {
  border-color: #58a6ff;
  background: rgba(56, 139, 253, 0.15);
  color: #58a6ff;
}

.chip-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.default-preview { background: #5da4df; }
.hd-preview { background: #3d88ca; }
.grey-preview { background: #9da5b0; }
.night-preview { background: #1a233a; }
.original-preview { background: #e0d8b5; }

/* Toggles */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.toggle-item input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  width: 32px;
  height: 18px;
  background-color: #30363d;
  border-radius: 12px;
  position: relative;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

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

.toggle-item input:checked + .toggle-slider::after {
  transform: translateX(14px);
}


/* Timeline */
.timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.timeline-slider {
  flex: 1;
  accent-color: var(--accent-blue);
  cursor: pointer;
}

.point-info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
}

.point-time {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #ffffff;
}

.point-coords-line {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.point-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px solid var(--border-color);
}

.point-note-box {
  background: rgba(210, 153, 34, 0.15);
  border-left: 3px solid var(--accent-gold);
  padding: 6px;
  border-radius: 4px;
  color: #e3b341;
  font-size: 0.72rem;
  line-height: 1.35;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
}

.badge-info {
  background: rgba(56, 139, 253, 0.15);
  color: #58a6ff;
  border: 1px solid rgba(56, 139, 253, 0.4);
}

.badge-official {
  background: rgba(210, 153, 34, 0.2);
  color: #e3b341;
  border: 1px solid #d29922;
}

.badge-neutral {
  background: #21262d;
  color: var(--text-secondary);
}

/* Map Viewport Area */
.map-viewport-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: #0b0e14;
  overflow: hidden;
  padding: 14px;
  align-items: stretch;
  justify-content: stretch;
}

/* Coordinate Chart Frame (Simulates chart.png layout with borders and rulers) */
.coordinate-chart-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 2px solid var(--chart-border);
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  width: 100%;
  height: 100%;
}

/* Fullscreen or Map Focus vs Chart Mode */
.coordinate-chart-frame.chart-mode {
  width: 90%;
  height: 92%;
  max-width: 1100px;
  max-height: 850px;
  margin: auto;
  border: 2px solid #111111;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
  flex: none;
}

.chart-title-banner {
  text-align: center;
  padding: 10px 0 8px 0;
  background: #ffffff;
  color: #111111;
  border-bottom: 1px solid #111111;
  display: none;
}

.chart-mode .chart-title-banner {
  display: block;
}

.chart-title-banner h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-family: var(--font-sans);
}

/* Rulers */
.ruler {
  background-color: #ffffff;
  user-select: none;
  position: relative;
  z-index: 400;
  transition: opacity 0.2s;
}

.ruler-top {
  height: 18px;
  border-bottom: 1px solid #111111;
  margin-left: 74px; /* Offset for left ruler */
  margin-right: 20px;
}

.chart-middle-row {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.ruler-left {
  width: 74px;
  border-right: 1px solid #111111;
  position: relative;
  display: flex;
  flex-shrink: 0;
}

.ruler-label-y {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: center center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #111111;
  letter-spacing: 0.02em;
}

.ruler-right {
  width: 20px;
  border-left: 1px solid #111111;
  flex-shrink: 0;
}

.ruler-bottom {
  height: 44px;
  border-top: 1px solid #111111;
  margin-left: 74px;
  margin-right: 20px;
  position: relative;
}

.ruler-label-x {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  font-weight: 600;
  color: #111111;
  letter-spacing: 0.02em;
}

/* Rulers hidden when toggled off */
.rulers-hidden .ruler-top,
.rulers-hidden .ruler-bottom,
.rulers-hidden .ruler-left,
.rulers-hidden .ruler-right {
  display: none !important;
}

.rulers-hidden .coordinate-chart-frame {
  border: none;
  background: transparent;
}

/* Map inner canvas */
.map-inner-container {
  flex: 1;
  position: relative;
  background-color: #e5e3df;
  overflow: hidden;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #e5e3df;
}

/* Tick markings */
.ruler-ticks {
  position: relative;
  width: 100%;
  height: 100%;
}

.tick-mark-x {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}

.tick-notch-x {
  width: 1px;
  height: 6px;
  background-color: #111111;
}

.tick-label-x {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: #111111;
  margin-top: 2px;
}

.tick-mark-y {
  position: absolute;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transform: translateY(-50%);
}

.tick-label-y {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: #111111;
  margin-right: 5px;
}

.tick-notch-y {
  width: 6px;
  height: 1px;
  background-color: #111111;
}

/* Overlay Legend (Matches chart.png) */
.chart-legend {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #999999;
  border-radius: 4px;
  padding: 8px 12px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(4px);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-symbol {
  display: inline-block;
  flex-shrink: 0;
}

.dot-symbol {
  width: 8px;
  height: 8px;
  background-color: #4a80c0;
  border-radius: 50%;
  border: 1px solid #2d5a8c;
}

.star-symbol {
  color: #d92525;
  font-size: 1.1rem;
  line-height: 1;
  text-shadow: 0 0 1px #000, 0 0 1px #000;
}

.ring-symbol {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #d29922;
  background: rgba(210, 153, 34, 0.3);
}

.legend-text {
  font-size: 0.72rem;
  font-weight: 600;
  color: #222222;
}

/* Live Coordinate Bar */
.live-coord-bar {
  position: absolute;
  bottom: 24px;
  left: 12px;
  background: rgba(22, 27, 34, 0.9);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  z-index: 900;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #c9d1d9;
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.coord-tag {
  color: var(--text-muted);
  font-weight: 600;
}

.zoom-tag, .crs-tag {
  color: #58a6ff;
  border-left: 1px solid var(--border-color);
  padding-left: 8px;
}

/* Floating Action Buttons */
.quick-action-floater {
  position: absolute;
  top: 14px;
  left: 60px; /* offset from Leaflet zoom control */
  display: flex;
  gap: 6px;
  z-index: 900;
}

.fab-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
  color: #111111;
  border: 1px solid #b0b0b0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  font-weight: 700;
  transition: all 0.15s;
}

.fab-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  color: var(--accent-blue);
}

/* Custom Marker Styles */
.bb-star-marker {
  display: flex;
  align-items: center;
  pointer-events: auto;
  white-space: nowrap;
}

.bb-star-svg {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.bb-star-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #111111;
  background: rgba(255, 255, 255, 0.85);
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  text-shadow: 0 0 2px #fff;
}

.official-marker-pulse {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #d29922;
  background: rgba(210, 153, 34, 0.25);
  transform: translate(-50%, -50%);
  animation: pulse-ring 2s infinite ease-out;
}

@keyframes pulse-ring {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0;
  }
}

/* Leaflet Popup Styling */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 12px 14px !important;
  font-family: var(--font-sans) !important;
  font-size: 0.75rem !important;
  line-height: 1.4 !important;
}

.popup-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #58a6ff;
  margin-bottom: 4px;
}

.popup-row {
  margin: 3px 0;
  color: var(--text-secondary);
}

.popup-row strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.leaflet-popup-tip {
  background: var(--bg-panel) !important;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Drag and Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(13, 17, 23, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}

.drop-overlay-box {
  background: var(--bg-panel);
  border: 2px dashed var(--accent-blue);
  border-radius: var(--radius-lg);
  padding: 40px 60px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  max-width: 500px;
}

.drop-overlay-box svg {
  color: var(--accent-blue);
  animation: bounceUp 1.2s infinite ease-in-out;
}

.drop-overlay-box h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.drop-overlay-box p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

@keyframes bounceUp {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

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

/* Header Dataset Pill */
.dataset-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(33, 38, 45, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  max-width: 280px;
}

.dataset-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 6px #3fb950;
  flex-shrink: 0;
}

.dataset-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  font-weight: 500;
}

.btn-pill-reset {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-pill-reset:hover {
  background: rgba(248, 81, 73, 0.2);
  color: #f85149;
}

/* Section Heading Row */
.section-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-heading-row .section-heading {
  margin-bottom: 0;
}

.badge-accent {
  background: rgba(56, 139, 253, 0.15);
  color: #58a6ff;
  border: 1px solid rgba(56, 139, 253, 0.3);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.toggle-count-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(110, 118, 129, 0.2);
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  animation: slideInRight 0.25s ease-out;
  transition: all 0.25s ease;
  min-width: 280px;
  max-width: 420px;
}

.toast-success {
  border-left: 4px solid #3fb950;
}

.toast-error {
  border-left: 4px solid #f85149;
}

.toast-info {
  border-left: 4px solid #58a6ff;
}

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

