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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
}

header {
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
  padding: 1.25rem 2rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #f0f4ff;
}

main {
  padding: 2rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
}

.card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 1.5rem;
}

.card h2 {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892b0;
  margin-bottom: 0.75rem;
}

.card .stat {
  font-size: 2.25rem;
  font-weight: 700;
  color: #ccd6f6;
}

/* ── Wind Panel ───────────────────────────────────────────── */
.wind-panel {
  margin-top: 1.5rem;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 1.5rem;
}

.wind-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.wind-panel-title {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892b0;
}

.wf-link {
  font-size: 0.78rem;
  color: #4fc3f7;
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.wf-link:hover { opacity: 1; }

.wind-body {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

/* Compass */
.wind-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.compass {
  position: relative;
  width: 100px;
  height: 100px;
}

.compass-labels {
  position: absolute;
  inset: 0;
  border: 1.5px solid #2d3148;
  border-radius: 50%;
}

.compass-labels span {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 600;
  color: #8892b0;
  line-height: 1;
}
.cl-n { top: 4px;  left: 50%; transform: translateX(-50%); }
.cl-s { bottom: 4px; left: 50%; transform: translateX(-50%); }
.cl-e { right: 5px; top: 50%; transform: translateY(-50%); }
.cl-w { left: 5px;  top: 50%; transform: translateY(-50%); }

.compass-arrow-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: center;
  transition: transform 0.6s ease;
}

.wind-dir-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #ccd6f6;
  letter-spacing: 0.05em;
}

/* Wind stats */
.wind-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.wind-stat-row {
  display: flex;
  gap: 2rem;
}

.wind-stat {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.ws-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #ccd6f6;
  line-height: 1;
}

.ws-unit {
  font-size: 0.9rem;
  color: #8892b0;
  align-self: flex-end;
  padding-bottom: 0.25rem;
}

.ws-label {
  width: 100%;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8892b0;
}

/* Hourly chart */
.hourly-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 64px;
}

.hc-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
}

.hc-bar {
  width: 100%;
  background: #4fc3f7;
  border-radius: 3px 3px 0 0;
  opacity: 0.7;
  min-height: 2px;
  transition: height 0.4s ease;
}

.hc-bar-wrap:hover .hc-bar { opacity: 1; }

.hc-label {
  font-size: 0.6rem;
  color: #8892b0;
  white-space: nowrap;
}

.wind-updated {
  font-size: 0.7rem;
  color: #4a5568;
}

/* ── Map Panel ────────────────────────────────────────────── */
.map-panel {
  margin-top: 1.5rem;
  border: 1px solid #2d3148;
  border-radius: 10px;
  overflow: hidden;
}

#shipsMap {
  height: 360px;
  width: 100%;
  background: #0f1117;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  color: #111;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.leaflet-popup-content { font-size: 0.82rem; line-height: 1.6; }
.leaflet-popup-content strong { color: #000; }
.popup-code { margin-left: 0.4rem; font-size: 0.72rem; color: #555; }
.leaflet-control-attribution {
  background: rgba(15,17,23,0.8) !important;
  color: #4a5568 !important;
}
.leaflet-control-attribution a { color: #4a5568 !important; }

/* ── Conditions Row ───────────────────────────────────────── */
.conditions-row {
  display: flex;
  gap: 1.5rem;
  margin-top: 1.5rem;
  align-items: flex-start;
}

.conditions-row .wind-panel {
  margin-top: 0;
  flex: 1;
}

.weather-panel {
  flex: 1;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 1.5rem;
  min-width: 0;
}

.forecast-day-group {
  margin-top: 0.75rem;
}
.forecast-day-group + .forecast-day-group { margin-top: 1rem; }

.fdg-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8892b0;
  margin-bottom: 0.4rem;
}

.forecast-hours {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.forecast-hour {
  flex: 1;
  min-width: 52px;
  text-align: center;
  padding: 0.75rem 0.25rem;
  background: #0f1117;
  border-radius: 8px;
  border: 1px solid #2d3148;
}

.forecast-hour-now {
  border-color: #4fc3f7;
}

.forecast-hour-past {
  opacity: 0.35;
}

.fh-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8892b0;
  margin-bottom: 0.4rem;
  white-space: nowrap;
}

.forecast-hour-now .fh-label { color: #4fc3f7; }

.fh-icon { font-size: 1.4rem; margin-bottom: 0.3rem; }

.fh-temp {
  font-size: 1rem;
  font-weight: 700;
  color: #f6ad55;
  margin-bottom: 0.3rem;
}

.fh-precip {
  font-size: 0.65rem;
  color: #4fc3f7;
}

/* ── Currents Panel ───────────────────────────────────────── */
.currents-panel {
  margin-top: 1.5rem;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 1.5rem;
}

.currents-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}

.currents-panel-title {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892b0;
}

.currents-station-label {
  margin-top: 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #ccd6f6;
}

.currents-day-group {
  margin-top: 0.75rem;
}
.currents-day-group + .currents-day-group { margin-top: 1rem; }

.cdg-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8892b0;
  margin-bottom: 0.4rem;
}

.currents-events {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.currents-event {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 0.9rem;
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  min-width: 72px;
  text-align: center;
}

.curr-now { border-color: #4fc3f7; }
.curr-past { opacity: 0.35; }

.ce-time {
  font-size: 0.72rem;
  font-weight: 600;
  color: #ccd6f6;
  white-space: nowrap;
}

.ce-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.curr-flood { background: #0d3349; color: #4fc3f7; }
.curr-ebb   { background: #2d1f00; color: #f6ad55; }
.curr-slack { background: #1e2233; color: #8892b0; }

.ce-vel {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e2e8f0;
}

.ce-dir {
  font-size: 1rem;
  color: #8892b0;
}

.curr-arrow { display: inline-block; }

/* ── Ships Panel ──────────────────────────────────────────── */
.ships-panel {
  margin-top: 1.5rem;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 1.5rem;
}

.ships-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.ships-panel-title {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892b0;
}

.ships-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.ships-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8892b0;
  padding: 0 0.75rem 0.6rem;
  border-bottom: 1px solid #2d3148;
}

.ships-table th:first-child,
.ships-table td:first-child { padding-left: 0; }

.ships-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #1e2233;
  color: #ccd6f6;
  vertical-align: middle;
}

.ships-table tbody tr:last-child td { border-bottom: none; }

.ships-table tbody tr:hover td { background: #1e2233; }

.vessel-name {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.vessel-link {
  color: inherit;
  text-decoration: none;
}
.vessel-link:hover { color: #4fc3f7; }

.dir-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.eta-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: #7c2d12;
  color: #fed7aa;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.dir-in  { background: #0d3349; color: #4fc3f7; }
.dir-out { background: #2d1f00; color: #f6ad55; }
.dir-bm  { background: #0d2e1f; color: #34d399; }
.dir-ix  { background: #0d3349; color: #4fc3f7; outline: 1px dashed #4fc3f7; }
.dir-ox  { background: #2d1f00; color: #f6ad55; outline: 1px dashed #f6ad55; }
.dir-bx  { background: #0d2e1f; color: #34d399; outline: 1px dashed #34d399; }

.ships-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.ships-day-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.day-nav-btn {
  background: none;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #8892b0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.25rem 0.6rem;
  transition: border-color 0.15s, color 0.15s;
}
.day-nav-btn:hover:not(:disabled) { border-color: #4fc3f7; color: #4fc3f7; }
.day-nav-btn:disabled { opacity: 0.3; cursor: default; }

.day-nav-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #ccd6f6;
  min-width: 9rem;
  text-align: center;
}

.ships-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-wrap {
  position: relative;
}

.settings-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #4a5568;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.settings-btn:hover { color: #8892b0; }
.settings-btn svg { width: 16px; height: 16px; }

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
}
.settings-row + .settings-row { margin-top: 0.6rem; }

.settings-label {
  font-size: 0.82rem;
  color: #ccd6f6;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  display: block;
  width: 36px;
  height: 20px;
  background: #2d3148;
  border-radius: 999px;
  transition: background 0.2s;
  position: relative;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #8892b0;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track { background: #0d3349; }
.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
  background: #4fc3f7;
}

.th-with-filter {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.filter-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #4a5568;
  display: flex;
  align-items: center;
  transition: color 0.15s;
  flex-shrink: 0;
}
.filter-btn:hover { color: #8892b0; }
.filter-btn.filter-active { color: #4fc3f7; }

.filter-icon {
  width: 11px;
  height: 11px;
}

.th-filterable { position: relative; }

.filter-popover {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 10;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 6px;
  padding: 0.5rem;
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.filter-close {
  position: absolute;
  top: 0.2rem;
  right: 0.3rem;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.65rem;
  line-height: 1;
  padding: 0;
  opacity: 0.6;
}
.filter-close:hover { opacity: 1; }
.filter-hidden { display: none; }

.th-filter {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 4px;
  color: #ccd6f6;
  font-size: 0.7rem;
  padding: 0.2rem 0.35rem;
  width: 100%;
  cursor: pointer;
}
.th-filter:focus { outline: none; border-color: #4fc3f7; }

.ships-refresh {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ships-pulled-at {
  font-size: 0.7rem;
  color: #4a5568;
}

.refresh-btn {
  background: none;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #8892b0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  transition: border-color 0.15s, color 0.15s;
}
.refresh-btn:hover { border-color: #4fc3f7; color: #4fc3f7; }

@keyframes spin { to { transform: rotate(360deg); } }
.refresh-btn.spinning { animation: spin 0.7s linear infinite; }

.ships-loading {
  color: #8892b0;
  font-size: 0.88rem;
  padding: 0.5rem 0;
}

.ships-error {
  color: #fc8181;
  font-size: 0.82rem;
  padding: 0.5rem 0;
}

/* ── Ship Cards (mobile) ──────────────────────────────────────── */
.ship-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ship-card {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sc-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sc-eta-row {
  margin-top: 0.15rem;
  padding-top: 0.45rem;
  border-top: 1px solid #2d3148;
}

.sc-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #4a5568;
  width: 6.5rem;
  flex-shrink: 0;
}

.sc-value {
  font-size: 0.88rem;
  color: #ccd6f6;
}

.sc-time {
  font-size: 0.88rem;
  font-weight: 700;
  color: #ccd6f6;
  font-variant-numeric: tabular-nums;
}

.sc-vessel {
  font-size: 0.88rem;
  font-weight: 600;
}

.sc-approach {
  font-size: 0.72rem;
  color: #8892b0;
  margin-left: 0.25rem;
}

.mobile-only { display: none; }

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  main {
    padding: 0.75rem;
  }

  /* Ships panel header wraps on small screens */
  .ships-panel-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Smaller map */
  #shipsMap {
    height: 220px;
  }

  /* Stack wind + weather vertically; hide the Windfinder widget
     (it renders a fixed-width table that can't be reflowed) */
  .conditions-row {
    flex-direction: column;
  }

  .conditions-row .wind-panel {
    display: none;
  }

  .mobile-only { display: inline; }

  .weather-panel {
    flex: none;
    width: 100%;
    min-width: 0;
  }

  /* Currents: scroll horizontally per day row */
  .currents-events {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .forecast-hours {
    flex-wrap: nowrap;
  }
}


