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

:root {
  --bg:          #0d1821;
  --surface:     #162032;
  --surface2:    #1e2d42;
  --surface3:    #253650;
  --border:      #2d4060;
  --text:        #e2e8f0;
  --text-muted:  #7a98be;
  --accent:      #4a9eff;
  --good:        #22c55e;
  --fair:        #f59e0b;
  --poor:        #ef4444;
  --unknown:     #6b7280;
  --header-h:    62px;
  --sidebar-w:   340px;
  --radius:      10px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 1000;
  box-shadow: 0 2px 16px rgba(0,0,0,0.5);
}

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

.header-logo { font-size: 30px; line-height: 1; }

.header-title-block h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.4px;
  line-height: 1.1;
}

.header-title-block p {
  font-size: 11px;
  color: var(--text-muted);
}

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

.station-count-badge {
  font-size: 12px;
  color: var(--text-muted);
}

#locate-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}
#locate-btn:hover  { opacity: 0.88; }
#locate-btn:active { transform: scale(0.97); }

/* ===== Map ===== */
#map {
  position: fixed;
  top: var(--header-h);
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  bottom: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}

.sidebar.closed { transform: translateX(-100%); }

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.sidebar-toggle:hover { background: var(--surface3); }

.status-text {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.station-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.station-list::-webkit-scrollbar { width: 4px; }
.station-list::-webkit-scrollbar-track { background: transparent; }
.station-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.station-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.station-item:hover { background: var(--surface2); }
.station-item:last-child { border-bottom: none; }

.station-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.station-info { flex: 1; min-width: 0; }

.station-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.station-readings {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.station-dist {
  margin-left: auto;
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.station-cond {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.no-stations {
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  line-height: 1.4;
}

/* Sidebar open button */
.sidebar-open-btn {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 12px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  transition: background 0.15s;
}
.sidebar-open-btn:hover { background: var(--surface2); }

/* ===== Loading ===== */
#loading {
  position: fixed;
  top: var(--header-h);
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  background: rgba(13, 24, 33, 0.88);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

#loading p { color: var(--text-muted); font-size: 14px; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Detail Panel ===== */
.detail-panel {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w);
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  z-index: 300;
  max-height: 58vh;
  overflow-y: auto;
  padding: 20px 22px 28px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -6px 32px rgba(0,0,0,0.5);
}

.detail-panel::-webkit-scrollbar { width: 4px; }
.detail-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.detail-panel.open { transform: translateY(0); }

.detail-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.detail-close:hover { background: var(--surface3); color: var(--text); }

.detail-station-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  padding-right: 40px;
  line-height: 1.3;
  margin-bottom: 6px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.conditions-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 16px;
  border-width: 2px;
  border-style: solid;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}

.stat-icon  { font-size: 22px; margin-bottom: 5px; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-unit  { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.fishing-assessment {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.fishing-assessment h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

.fishing-assessment ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fishing-assessment li {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-usgs {
  flex: 1;
  min-width: 200px;
  display: block;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 11px 16px;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  transition: background 0.15s;
}
.btn-usgs:hover { background: var(--surface3); text-decoration: none; }

/* ===== Legend ===== */
.legend {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.legend-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-dot.good    { background: var(--good); box-shadow: 0 0 6px var(--good); }
.legend-dot.fair    { background: var(--fair); box-shadow: 0 0 6px var(--fair); }
.legend-dot.poor    { background: var(--poor); box-shadow: 0 0 6px var(--poor); }
.legend-dot.unknown { background: var(--unknown); }

/* ===== Leaflet overrides ===== */
.leaflet-tooltip {
  background: var(--surface2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
  font-size: 12px !important;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5) !important;
  padding: 6px 10px !important;
}
.leaflet-tooltip-left::before,
.leaflet-tooltip-right::before { border-color: transparent; }

.leaflet-popup-content-wrapper {
  background: var(--surface2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 10px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip { background: var(--surface2) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* User location pulse */
.user-pulse {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(74,158,255,0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,158,255,0.6); }
  70%  { box-shadow: 0 0 0 14px rgba(74,158,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,158,255,0); }
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  #map { left: 0; }
  #loading { left: 0; }

  .sidebar {
    width: 300px;
    transform: translateX(-100%);
    z-index: 600;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar:not(.closed) { transform: translateX(0); }

  .detail-panel { left: 0; }

  .sidebar-open-btn { display: flex !important; }

  .legend { bottom: 8px; right: 8px; }

  .detail-stats { grid-template-columns: repeat(2, 1fr); }

  .header-title-block p { display: none; }
}
