/* WindApp — Maritime Instrument Panel Theme */

:root {
  /* Deep ocean base */
  --bg-deep: #0a1628;
  --bg-surface: #0f2035;
  --bg-elevated: #162942;

  /* Accent colors */
  --accent-wind: #60a5fa;
  --accent-water: #22d3ee;
  --accent-gust: #f472b6;
  --accent-warm: #fbbf24;
  --accent-calm: #34d399;

  /* Text hierarchy */
  --text-primary: #f0f6ff;
  --text-secondary: #8aa8d4;
  --text-muted: #4a6589;

  /* Nautical brass accent */
  --accent-brass: #d4a574;

  /* Borders */
  --border-subtle: rgba(96, 165, 250, 0.12);
  --border-accent: rgba(96, 165, 250, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  background:
    radial-gradient(ellipse at 20% 90%, rgba(34, 211, 238, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 10%, rgba(96, 165, 250, 0.05) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 50%, rgba(22, 41, 66, 0.5) 0%, transparent 70%),
    var(--bg-deep);
}

body {
  display: flex;
  flex-direction: column;
}

/* Subtle noise texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.018;
  pointer-events: none;
  z-index: 9999;
}

/* Header */
header {
  padding: 12px 20px;
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-deep) 100%);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.02),
    0 4px 20px rgba(0,0,0,0.2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 100;
}

header h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--text-primary) 20%, var(--accent-brass) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-left: auto;
  flex-wrap: wrap;
}

.controls label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.controls select {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-accent);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.controls select:hover {
  border-color: var(--accent-wind);
}

.controls select:focus {
  outline: none;
  border-color: var(--accent-wind);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.status {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-calm);
  box-shadow: 0 0 8px var(--accent-calm);
  animation: pulse 2s ease-in-out infinite;
}

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

/* Main layout */
main {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1;
  background: var(--bg-deep);
}

/* Panel */
.panel {
  width: 420px;
  max-width: 50vw;
  background: linear-gradient(160deg, var(--bg-surface) 0%, var(--bg-elevated) 100%);
  color: var(--text-primary);
  border-left: 1px solid var(--border-subtle);
  padding: 20px;
  overflow-y: auto;
  position: relative;
  box-shadow: -20px 0 60px rgba(0,0,0,0.4);
  transform: translateX(0);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

.panel.hidden {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  letter-spacing: 0.02em;
}

.panel .meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel .meta b {
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.panel .meta span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
}

#panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

#panel-close:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

/* Leaflet tooltip override */
.leaflet-tooltip {
  background: rgba(10, 22, 40, 0.95) !important;
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-accent) !important;
  border-radius: 6px !important;
  color: var(--text-primary) !important;
  font-family: 'Outfit', sans-serif !important;
  font-size: 0.85rem !important;
  padding: 10px 14px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4) !important;
}

.leaflet-tooltip b {
  color: var(--accent-brass);
  font-weight: 600;
}

.leaflet-tooltip small {
  color: var(--text-muted);
}

.leaflet-tooltip-top:before {
  border-top-color: rgba(10, 22, 40, 0.95) !important;
}

/* Mobile */
@media (max-width: 720px) {
  header {
    padding: 10px 14px;
  }

  header h1 {
    font-size: 0.85rem;
  }

  .controls {
    gap: 10px;
  }

  main {
    flex-direction: column;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    max-height: 55%;
    border-left: 0;
    border-top: 1px solid var(--border-subtle);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
  }

  .panel.hidden {
    transform: translateY(100%);
  }

  .panel:not(.hidden) {
    transform: translateY(0);
  }
}

/* --- SAV additions --------------------------------------------------- */
.controls { flex-wrap: wrap; gap: 0.75rem 1.25rem; }
.mode label { margin-right: 0.75rem; cursor: pointer; }
.layers { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.layers label { cursor: pointer; white-space: nowrap; }
.layers label.opacity input { vertical-align: middle; width: 90px; margin-left: 0.4rem; }
.layers label.disabled { opacity: 0.4; cursor: not-allowed; }

@media (min-width: 721px) {
  .panel { display: block; width: 340px; overflow-y: auto; }
}
.panel .hint { padding: 0.75rem 1rem; color: var(--accent-water); font-family: "JetBrains Mono", monospace; font-size: 0.85rem; }
.panel h2 { font-size: 1rem; margin: 1rem 1rem 0.5rem; }
.panel table { width: calc(100% - 2rem); margin: 0 1rem 1rem; border-collapse: collapse; font-family: "JetBrains Mono", monospace; font-size: 0.8rem; }
.panel th, .panel td { padding: 0.25rem 0.4rem; text-align: right; border-bottom: 1px solid rgba(255,255,255,0.08); }
.panel th:first-child, .panel td:first-child { text-align: left; }
.panel td.pos { color: #74c476; }
.panel td.neg { color: #fb6a4a; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 0.4rem; vertical-align: -2px; border: 1px solid rgba(255,255,255,0.3); }

/* legend control */
.legend { background: rgba(8, 14, 22, 0.88); color: #dfe7ee; padding: 0.6rem 0.8rem; border-radius: 6px;
          font: 0.78rem "JetBrains Mono", monospace; line-height: 1.5; max-width: 220px; }
.legend h3 { margin: 0 0 0.3rem; font: 600 0.8rem "Outfit", sans-serif; letter-spacing: 0.04em; }
.legend .row { display: flex; align-items: center; gap: 0.4rem; }
.legend .hatch { background-image: repeating-linear-gradient(45deg, transparent 0 3px, currentColor 3px 5px); }

/* diff vector styles (fill via CSS so SVG patterns can override Leaflet's fill attribute) */
path.sav-hatch-denser-1 { fill: url(#hatch-denser-1); }
path.sav-hatch-denser-2 { fill: url(#hatch-denser-2); }
path.sav-hatch-denser-3 { fill: url(#hatch-denser-3); }
path.sav-hatch-sparser-1 { fill: url(#hatch-sparser-1); }
path.sav-hatch-sparser-2 { fill: url(#hatch-sparser-2); }
path.sav-hatch-sparser-3 { fill: url(#hatch-sparser-3); }

.quad-loading { stroke-dasharray: 6 6; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -12; } }

.leaflet-popup-content { font: 0.85rem "Outfit", sans-serif; }
.leaflet-popup-content .mono { font-family: "JetBrains Mono", monospace; }
