/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:   #0a0f1e;
  --bg-dark:   #0f172a;
  --bg-mid:    #1e293b;
  --bg-light:  #273549;
  --border:    rgba(255,255,255,0.08);
  --border-hi: rgba(255,255,255,0.15);
  --text-1:    #f1f5f9;
  --text-2:    #94a3b8;
  --text-3:    #64748b;
  --accent:    #f97316;
  --accent-hi: #fb923c;
  /* Windgram bottom panel height (overridable by drag-resize; stored in localStorage). */
  --windgram-h: min(52vh, 600px);
  --toolbar-h: 52px;
  --radius:    10px;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text-1);
}

button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }
a      { color: var(--accent); }

/* ===== MAP CONTAINER ===== */
#map-container {
  position: absolute;
  inset: 0;
}

/* ===== WIND OVERLAY ===== */
#wind-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* ===== TOP TOOLBAR ===== */
#toolbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: rgba(10, 15, 30, 0.82);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

#toolbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

#altitude-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

#altitude-selector label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

#model-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

#model-selector label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

#altitude-select {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  outline: none;
  min-width: 200px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
#altitude-select:focus  { border-color: var(--accent); }
#altitude-select option { background: var(--bg-mid); }

#model-select {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  appearance: auto;
}
#model-select:focus  { border-color: var(--accent); }

/* Basemap: topo (OpenTopoMap) vs satellite (Esri World Imagery) */
.basemap-toggle {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}
.basemap-toggle__btn {
  margin: 0;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--bg-mid);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.basemap-toggle__btn + .basemap-toggle__btn {
  border-left: 1px solid var(--border);
}
.basemap-toggle__btn:hover {
  color: var(--text-1);
  background: rgba(15, 23, 42, 0.95);
}
.basemap-toggle__btn.active {
  color: var(--accent);
  background: rgba(249, 115, 22, 0.12);
}

/* Map-pick windgram (toolbar) */
#pick-windgram-btn {
  flex-shrink: 0;
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
#pick-windgram-btn:hover {
  border-color: rgba(249, 115, 22, 0.45);
  color: var(--accent);
}
#pick-windgram-btn.active {
  border-color: var(--accent);
  background: rgba(249, 115, 22, 0.12);
  color: var(--accent);
}
#model-select option { background: var(--bg-mid); }

#spatial-wind-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

#spatial-wind-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

#spatial-wind-label input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

#spatial-time-select {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  outline: none;
  min-width: 148px;
  max-width: 200px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
#spatial-time-select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#spatial-time-select:focus:not(:disabled) { border-color: var(--accent); }
#spatial-time-select option { background: var(--bg-mid); }

#toolbar-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#time-display {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.loading { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.status-dot.ready   { background: #22c55e; }
.status-dot.error   { background: #ef4444; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

#settings-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#settings-btn:hover { color: var(--text-1); border-color: var(--border-hi); }

/* ===== WINDGRAM PANEL ===== */
#windgram-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--windgram-h);
  display: flex;
  flex-direction: column;
  background: rgba(10, 15, 30, 0.96);
  backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--border);
  z-index: 25;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#windgram-panel.panel-hidden {
  transform: translateY(var(--windgram-h));
}

#windgram-resize-handle {
  flex-shrink: 0;
  height: 8px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
#windgram-resize-handle:hover {
  background: rgba(255, 255, 255, 0.06);
}
#windgram-resize-handle::after {
  content: '';
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: var(--text-3);
  opacity: 0.35;
  pointer-events: none;
}
#windgram-resize-handle:hover::after {
  opacity: 0.65;
}

#windgram-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  position: relative;
  z-index: 30;
}

#windgram-title-area { min-width: 0; }

#windgram-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#windgram-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
  display: block;
}

/* Windgram tab strip */
#windgram-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.wg-thermals-with-help {
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
}

.wg-tab-info-btn {
  flex-shrink: 0;
  width: 26px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 13px/1 'Inter', sans-serif;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-mid);
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.wg-tab-info-btn:hover,
.wg-tab-info-btn.active {
  color: var(--text-1);
  border-color: var(--border-hi);
  background: var(--bg-light);
}

.windgram-header-popup {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(290px, calc(100vw - 32px));
  background: rgba(15, 23, 42, 0.97);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  z-index: 50;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.45;
}
.windgram-header-popup.hidden { display: none; }

.wg-tab {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.wg-tab:hover {
  color: var(--text-2);
  border-color: var(--border-hi);
}
.wg-tab.active {
  background: rgba(249, 115, 22, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

#windgram-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#windgram-time-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

#windgram-time-nav button {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 28px; height: 28px;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
#windgram-time-nav button:hover  { background: var(--bg-light); color: var(--text-1); }
#windgram-time-nav button:disabled { opacity: 0.3; pointer-events: none; }

#wg-time-range {
  font-size: 11px;
  color: var(--text-3);
  min-width: 120px;
  text-align: center;
}

#close-windgram {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  width: 28px; height: 28px;
  border-radius: 6px;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
#close-windgram:hover { color: var(--text-1); border-color: var(--border-hi); }

/* Landing zone marker: panel is notes-only (no forecast tabs / time stepper). */
#windgram-panel.windgram-panel--landing-zone #windgram-tabs {
  display: none;
}
#windgram-panel.windgram-panel--landing-zone #windgram-time-nav {
  display: none;
}

.tip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tip-header span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: 0.03em;
}
.tip-header button {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  transition: color 0.12s;
}
.tip-header button:hover { color: var(--text-1); }

.tip-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.tip-body {
  font-size: 10.5px;
  color: var(--text-3);
  margin-bottom: 8px;
  line-height: 1.5;
}

.tip-swatches { display: flex; flex-direction: column; gap: 5px; }

.tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-2);
}

.tip-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.10);
}

.tip-line {
  width: 24px;
  height: 2px;
  flex-shrink: 0;
  border-radius: 1px;
}
.tip-line--blh { background: rgba(251,191,36,0.85); border-top: 2px dashed rgba(251,191,36,0.85); background: none; }
.tip-line--fzl { border-top: 2px dashed rgba(125,211,252,0.85); background: none; }

#windgram-body {
  flex: 1;
  min-height: 0;
  overflow: visible;
  position: relative;
  display: flex;
  flex-direction: column;
}

.windgram-body--notes #windgram-canvas {
  display: none;
}

.windgram-notes-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  box-sizing: border-box;
}

.windgram-notes-panel[hidden] {
  display: none !important;
}

.windgram-body--notes .windgram-notes-panel {
  display: flex !important;
}

.windgram-notes-hint {
  margin: 0;
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.35;
}

.windgram-notes-display {
  flex: 1;
  min-height: 120px;
  margin: 0;
  padding: 10px 12px;
  box-sizing: border-box;
  font: 13px/1.45 Inter, system-ui, sans-serif;
  color: var(--text-1);
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-y: auto;
}

.windgram-notes-display--empty {
  color: var(--text-3);
  font-style: italic;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Canvas would otherwise sit above margin controls in the GPU stack and steal clicks. */
#windgram-canvas {
  display: block;
  position: relative;
  z-index: 0;
  pointer-events: none;
}

/* ===== WIND LEGEND ===== */
#wind-legend {
  position: absolute;
  top: calc(var(--toolbar-h) + 12px);
  right: 12px;
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  z-index: 15;
}

.legend-sub {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  line-height: 1.3;
  margin-top: 2px;
  max-width: 200px;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 7px;
}

.legend-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-2);
}

.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-unit {
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  margin-top: 6px;
}

/* ===== LOADING OVERLAY ===== */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 30, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.3s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

#loading-text {
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
  max-width: 420px;
  line-height: 1.45;
}

#loading-error-actions {
  display: none;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

#loading-error-actions.visible {
  display: flex;
}

#loading-retry-no-token {
  flex: none;
  width: auto;
  padding: 10px 16px;
}


/* ===== SHARED BUTTONS ===== */
.btn-primary {
  flex: 1;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hi); }

.btn-secondary {
  background: var(--bg-dark);
  border: 1px solid var(--border-hi);
  color: var(--text-2);
  font-size: 13px;
  padding: 11px 16px;
  border-radius: 8px;
  transition: all 0.15s;
}
.btn-secondary:hover { background: var(--bg-light); color: var(--text-1); }

/* ===== SETTINGS PANEL ===== */
#settings-panel {
  position: absolute;
  top: var(--toolbar-h);
  right: 0;
  width: 300px;
  bottom: 0;
  background: rgba(10, 15, 30, 0.96);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#settings-panel.panel-hidden-right { transform: translateX(300px); }

#settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

#close-settings {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 16px;
  transition: color 0.15s;
}
#close-settings:hover { color: var(--text-1); }

#settings-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

#settings-body h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

#settings-body code {
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  background: var(--bg-dark);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--accent-hi);
}

/* ===== LIVE WIND MODAL (Spit iframe / Gondola) ===== */
.live-wind-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}
.live-wind-modal.hidden { display: none; }

.live-wind-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 20, 0.72);
  pointer-events: auto;
}

.live-wind-modal__card {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100vw - 32px));
  max-height: min(88vh, 780px);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  overflow: hidden;
}

.live-wind-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.live-wind-modal__head h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}
.live-wind-modal__close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.live-wind-modal__close:hover { color: var(--text-1); background: var(--bg-mid); }

.live-wind-modal__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 10px 14px 14px;
  gap: 10px;
}

.live-wind-spit-canvas {
  display: block;
  width: 100%;
  height: 220px;
  border-radius: 8px;
  background: #0d1b2a;
  margin-bottom: 6px;
}
.live-wind-spit-canvas.hidden { display: none; }

.live-wind-gondola.hidden { display: none; }
.live-wind-gondola__text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-2);
  margin: 8px 0;
}

.live-wind-spit-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(34,211,238,0.10);
  border: 1px solid rgba(34,211,238,0.25);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #67e8f9;
}
.live-wind-spit-bar.hidden { display: none; }

.live-wind-modal__link {
  font-size: 12px;
  font-weight: 500;
  align-self: flex-start;
}
.live-wind-modal__link.hidden {
  display: none;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }
