/* OpenGridWorks Clone - Dark Theme */
:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #21262d; --bg4: #30363d;
  --fg: #e6edf3; --fg2: #8b949e; --fg3: #6e7681; --fg4: #484f58;
  --accent: #58a6ff; --green: #3fb950; --red: #f85149; --yellow: #d29922; --orange: #db6d28;
  --border: #30363d; --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: var(--font); font-size: 13px; color: var(--fg); background: #000; }

/* Loading */
#loading-overlay { position: fixed; inset: 0; z-index: 9999; background: #000; display: flex; align-items: center; justify-content: center; transition: opacity .5s; }
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-content { text-align: center; }
.loading-spinner { width: 32px; height: 32px; border: 3px solid var(--bg3); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 18px; font-weight: 700; letter-spacing: 4px; color: var(--fg2); }
.loading-error-icon { font-size: 34px; line-height: 1; margin-bottom: 14px; color: #f87171; }
.loading-error-msg { font-size: 13px; font-weight: 400; letter-spacing: 0; line-height: 1.7; color: var(--fg2); max-width: 340px; margin: 0 auto 18px; }
.loading-error-msg a { color: var(--accent); text-decoration: underline; }
.loading-retry { background: var(--accent); color: #000; border: 0; padding: 9px 22px; border-radius: 6px; font-size: 13px; font-weight: 700; letter-spacing: 1px; cursor: pointer; }
.loading-retry:hover { filter: brightness(1.1); }

/* Nav */
#navbar { position: fixed; top: 0; left: 0; right: 0; z-index: 100; height: 44px; background: var(--bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }
.nav-left { display: flex; align-items: center; gap: 8px; }
.nav-right { display: flex; align-items: center; gap: 8px; }
.nav-logo { font-weight: 700; font-size: 14px; color: var(--fg); text-decoration: none; margin-right: 8px; }
.nav-link { color: var(--fg2); text-decoration: none; font-size: 13px; padding: 4px 8px; border-radius: var(--radius); }
.nav-link:hover, .nav-link.active { color: var(--fg); background: var(--bg3); }
.nav-signin-btn { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.icon-btn { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border: none; background: none; color: var(--fg2); cursor: pointer; border-radius: var(--radius); }
.icon-btn:hover { background: var(--bg3); color: var(--fg); }

/* Legend Panel */
#legend-panel { position: fixed; top: 44px; left: 0; bottom: 40px; width: 280px; background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto; z-index: 50; padding: 8px 0; transition: transform .3s; }
#legend-panel.collapsed { transform: translateX(-280px); }
.legend-header { padding: 4px 12px 8px; font-weight: 600; font-size: 14px; color: var(--fg2); }

.legend-section { border-bottom: 1px solid var(--border); }
.legend-section-header { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 6px 12px; cursor: pointer; }
.legend-section-label { font-weight: 500; font-size: 12px; flex: 1; }
.legend-body { padding: 0 12px 8px; }
.legend-section:not(.open) .legend-body { display: none; }

/* Toggle switches */
.toggle-switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 11px; position: relative; }
.toggle-switch input { display: none; }
.toggle-track { width: 28px; height: 16px; background: var(--bg4); border-radius: 8px; position: relative; transition: background .2s; flex-shrink: 0; }
.toggle-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: var(--fg3); border-radius: 50%; transition: transform .2s, background .2s; }
.toggle-switch input:checked + .toggle-track { background: var(--green); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(12px); background: #fff; }

.toggle-track-sm { width: 22px; height: 13px; background: var(--bg4); border-radius: 7px; position: relative; transition: background .2s; flex-shrink: 0; }
.toggle-track-sm::after { content: ''; position: absolute; top: 2px; left: 2px; width: 9px; height: 9px; background: var(--fg3); border-radius: 50%; transition: transform .2s, background .2s; }
.toggle-switch input:checked + .toggle-track-sm,
.toggle-item input:checked + .toggle-track-sm { background: var(--green); }
.toggle-switch input:checked + .toggle-track-sm::after,
.toggle-item input:checked + .toggle-track-sm::after { transform: translateX(9px); background: #fff; }

.toggle-sub { margin-left: auto; }
.sub-label { color: var(--fg2); font-size: 10px; white-space: nowrap; }

.toggle-item { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 11px; padding: 2px 0; }
.toggle-item input { display: none; }
.toggle-item-label { color: var(--fg2); font-size: 11px; }

/* Type buttons */
.type-buttons { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.type-btn { padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 12px; background: transparent; color: var(--fg2); cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 4px; }
.type-btn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--tc); flex-shrink: 0; }
.type-btn.active { background: var(--bg3); color: var(--fg); border-color: var(--fg4); }
.type-btn:hover { border-color: var(--fg4); }

/* Plant size */
.plant-size-section { margin-top: 4px; }
.size-mw-btn { padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 12px; background: transparent; color: var(--fg2); cursor: pointer; margin-bottom: 4px; }
.size-mw-btn:hover { border-color: var(--fg4); }
.size-legend { display: flex; flex-direction: column; gap: 2px; }
.size-dots { display: flex; align-items: center; gap: 4px; }
.sdot { display: inline-block; border-radius: 50%; background: var(--fg3); }
.sdot.s1 { width: 6px; height: 6px; } .sdot.s2 { width: 10px; height: 10px; } .sdot.s3 { width: 16px; height: 16px; }
.size-info { display: flex; gap: 4px; font-size: 10px; color: var(--fg3); align-items: center; }
.size-info .sep { color: var(--fg4); }
.size-info b { color: var(--fg2); font-weight: 500; }

/* Sub items */
.sub-items { display: flex; flex-direction: column; gap: 1px; }

/* Attribution */
.legend-attribution { padding: 8px 12px; border-top: 1px solid var(--border); }
.attribution-text { font-size: 9px; color: var(--fg3); margin-top: 4px; line-height: 1.4; }
.attribution-text a { color: var(--accent); text-decoration: none; }

/* Map */
#map-container { position: fixed; top: 44px; left: 280px; right: 0; bottom: 40px; transition: left .3s; }
#map-container.expanded { left: 0; }
#map { width: 100%; height: 100%; background: #000; }

/* Map controls */
#map-controls { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; z-index: 40; }
.map-ctrl { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg2); cursor: pointer; font-size: 10px; font-weight: 600; }
.map-ctrl:hover { background: var(--bg3); color: var(--fg); }
.beta-btn { font-size: 8px; letter-spacing: .5px; }
.ctrl-divider { height: 1px; background: var(--border); margin: 2px 0; }

/* Popup */
#map-popup { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 45; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; min-width: 240px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
#map-popup.hidden { display: none; }
.popup-close { position: absolute; top: 4px; right: 8px; background: none; border: none; color: var(--fg3); cursor: pointer; font-size: 18px; }
#popup-content { font-size: 12px; }
#popup-content h3 { font-size: 14px; margin-bottom: 6px; }
#popup-content .detail { color: var(--fg2); margin: 2px 0; }

/* Side panels */
.side-panel { position: fixed; top: 44px; right: 0; width: 300px; bottom: 40px; background: var(--bg); border-left: 1px solid var(--border); z-index: 60; overflow-y: auto; transition: transform .3s; }
.side-panel.hidden { transform: translateX(300px); }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; }
.panel-close { background: none; border: none; color: var(--fg3); cursor: pointer; font-size: 18px; }
.panel-body { padding: 8px 12px; }
.panel-section { margin-bottom: 12px; }
.panel-section-title { font-size: 11px; font-weight: 600; color: var(--fg3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.on-badge, .off-badge { font-size: 9px; font-weight: 600; margin-left: 4px; }
.on-badge { color: var(--green); }
.off-badge { color: var(--fg3); }

/* Globe panel */
.country-items { display: flex; flex-direction: column; gap: 2px; }
.country-item { display: flex; align-items: center; gap: 4px; }
.country-item .toggle-item { flex: 1; }
.fly-btn { padding: 2px 8px; font-size: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg3); color: var(--accent); cursor: pointer; }
.fly-btn:hover { background: var(--bg4); }

/* Label presets */
.preset-buttons { display: flex; flex-direction: column; gap: 4px; }
.preset-btn { text-align: left; padding: 6px 10px; font-size: 11px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: var(--fg2); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.preset-btn:hover { background: var(--bg3); }
.preset-btn.active { border-color: var(--accent); color: var(--fg); }
.active-badge { font-size: 9px; font-weight: 600; color: var(--accent); background: rgba(88,166,255,.15); padding: 1px 6px; border-radius: 8px; }

/* Sliders */
.slider-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 11px; color: var(--fg2); }
.slider-row span:first-child { min-width: 90px; }
.slider-row input[type="range"] { flex: 1; height: 4px; accent-color: var(--accent); }
.slider-row span:last-child { min-width: 35px; text-align: right; font-family: var(--mono); font-size: 10px; }

/* Color */
.color-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--fg2); }
.color-row input[type="color"] { width: 24px; height: 24px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: none; }

/* Preset views panel */
.preset-view-btn { display: block; width: 100%; text-align: left; padding: 8px 10px; font-size: 11px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: var(--fg2); cursor: pointer; margin-bottom: 6px; line-height: 1.4; }
.preset-view-btn:hover { background: var(--bg3); color: var(--fg); }

/* Saved views */
.saved-empty { text-align: center; padding: 20px; color: var(--fg3); }
.sign-in-link { color: var(--accent); text-decoration: none; font-weight: 500; }

/* Search */
.search-input { width: 100%; padding: 8px 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg); font-size: 12px; outline: none; }
.search-input:focus { border-color: var(--accent); }
.search-results { margin-top: 8px; }
.search-result-item { padding: 6px 8px; border-radius: var(--radius); cursor: pointer; font-size: 12px; color: var(--fg2); }
.search-result-item:hover { background: var(--bg3); color: var(--fg); }

/* Bottom bar */
#bottom-bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; height: 40px; background: var(--bg); border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; padding: 0 12px; overflow-x: auto; }
.bottom-btn { padding: 4px 10px; font-size: 11px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: var(--fg2); cursor: pointer; white-space: nowrap; }
.bottom-btn:hover { background: var(--bg3); color: var(--fg); }
.live-count { font-size: 11px; color: var(--fg3); white-space: nowrap; display: flex; gap: 4px; }
.live-count span:first-child { color: var(--green); font-weight: 600; font-family: var(--mono); }
.bottom-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.bottom-action-btn { padding: 4px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: var(--fg2); cursor: pointer; white-space: nowrap; }
.bottom-action-btn:hover { background: var(--bg3); color: var(--fg); }
.bottom-toggle { display: inline-flex; white-space: nowrap; }
.sign-in-btn { color: var(--accent); }

/* Terms */
#terms-notice { position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%); z-index: 90; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px; font-size: 11px; color: var(--fg2); max-width: 600px; display: flex; align-items: center; gap: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
#terms-notice.hidden { display: none; }
#terms-notice a { color: var(--accent); text-decoration: none; }
#terms-dismiss { background: none; border: none; color: var(--fg3); cursor: pointer; font-size: 16px; }

/* Maplibre overrides */
.maplibregl-ctrl-attrib { font-size: 9px !important; background: rgba(0,0,0,.5) !important; color: var(--fg3) !important; }
.maplibregl-ctrl-attrib a { color: var(--accent) !important; }
.maplibregl-popup-content { background: var(--bg2) !important; color: var(--fg) !important; border: 1px solid var(--border) !important; border-radius: var(--radius) !important; padding: 8px 12px !important; box-shadow: 0 4px 12px rgba(0,0,0,.4) !important; }
.maplibregl-popup-tip { border-top-color: var(--bg2) !important; }
.maplibregl-popup-close-button { color: var(--fg3) !important; }

/* Responsive */
@media (max-width: 768px) {
  #legend-panel { width: 240px; }
  #map-container { left: 0; }
  .side-panel { width: 100%; }
}
