* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  /* Dynamic viewport units avoid cut-off/scroll when mobile browser chrome
     (address bar, etc.) shows/hides. Fall back to 100vh for browsers that
     don't support dvh yet. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0b1220;
  color: #e6e9ef;
}

body {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
}

/* Header sits in normal flow (not overlaid) so it never obstructs the
   Leaflet zoom controls, and the map always gets the exact remaining
   viewport space below it. */
#header {
  flex: 0 0 auto;
  z-index: 1000;
  background: rgba(11, 18, 32, 0.92);
  color: #e6e9ef;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  font-size: 14px;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-main h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.header-details {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: #a9b2c3;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pill-live {
  background: #1c7c3f;
  color: #e9fff0;
}

.pill-disconnected {
  background: #7c1c1c;
  color: #ffecec;
}

.pill-nokey {
  background: #7c5c1c;
  color: #fff5e6;
}

/* Amber: connected but no position data yet, or a "Live" feed gone quiet
   (see the status.connected && !primaryCurrent / stale-lastMessageAt cases
   in app.js's setStatus()). Distinct from pill-nokey so the two states
   aren't visually confused. */
.pill-waiting {
  background: #8a6d1a;
  color: #fff3d6;
}

.pill-demo {
  background: #2a4a8c;
  color: #e6efff;
}

/* Teal-blue: current position is coming from the aprs.fi fallback source
   rather than the primary aisstream feed. Deliberately a different hue from
   pill-demo's indigo so the two "not primary live AIS" states aren't
   visually confused with each other. */
.pill-fallback {
  background: #0f6e8c;
  color: #e0fbff;
}

.pill-unknown {
  background: #444c5c;
  color: #e6e9ef;
}

.badge {
  background: #2a4a8c;
  color: #e6efff;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.follow-btn,
.hdr-btn {
  background: #1a2438;
  color: #e6e9ef;
  border: 1px solid #33415c;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  /* Comfortable tap target on touch devices while staying compact with a
     mouse (see the pointer: coarse rule below). */
  min-height: 32px;
}

.follow-btn[aria-pressed="true"] {
  background: #1c7c3f;
  border-color: #1c7c3f;
}

.hdr-btn:hover {
  background: #22304a;
}

.banner {
  flex: 0 0 auto;
  z-index: 999;
  background: #3a2e10;
  color: #ffe9b3;
  border: 1px solid #7c5c1c;
  border-radius: 8px;
  margin: 0 12px 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  max-width: 100%;
}

.banner span {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.banner a {
  color: #ffd77a;
}

.banner button {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: #ffe9b3;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
}

#map {
  flex: 1 1 auto;
  position: relative;
  width: 100%;
  min-height: 0;
}

/* Keep Leaflet's own popups readable and non-overflowing on narrow screens. */
.leaflet-popup-content-wrapper,
.leaflet-popup-content {
  max-width: min(280px, calc(100vw - 40px));
  overflow-wrap: break-word;
  word-break: break-word;
}

.history-dot {
  fill: #4aa3ff;
}

/* --- Multi-vessel icons -------------------------------------------------- */

.vessel-icon {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}

.vessel-icon--cruise {
  color: #ff5252;
}

.vessel-icon--ferry {
  color: #4ade80;
}

/* Focused vessel gets a glow ring in its own color so it's identifiable at
   a glance among the other markers. */
.vessel-icon.focused {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 5px currentColor);
}

/* --- Vessel panel --------------------------------------------------------- */

#vessel-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(280px, calc(100vw - 24px));
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  background: rgba(26, 36, 56, 0.94);
  border: 1px solid #33415c;
  border-radius: 8px;
  z-index: 1100;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  font-size: 13px;
}

.vessel-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

/* --- Add-vessel form -------------------------------------------------- */

.add-vessel-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #33415c;
}

.add-vessel-title {
  font-size: 12px;
  font-weight: 600;
  color: #a9b2c3;
}

.add-vessel-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.add-vessel-field label {
  font-size: 11px;
  color: #7f8ba3;
}

.add-vessel-field input {
  background: #0b1220;
  color: #e6e9ef;
  border: 1px solid #33415c;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  width: 100%;
}

.add-vessel-submit {
  align-self: flex-start;
}

.add-vessel-error {
  margin: 0;
  color: #ffecec;
  background: #7c1c1c;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
}

.vessel-group {
  margin-bottom: 10px;
}

.vessel-group:last-child {
  margin-bottom: 0;
}

.vessel-group-header {
  font-size: 12px;
  font-weight: 600;
  color: #a9b2c3;
  margin-bottom: 4px;
}

.vessel-group-header label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.vessel-rows {
  display: flex;
  flex-direction: column;
}

.vessel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.vessel-row:hover {
  background: rgba(255, 255, 255, 0.06);
}

.vessel-row.focused {
  border-left-color: #2f6fd6;
  background: rgba(47, 111, 214, 0.12);
}

.vessel-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.vessel-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vessel-stats {
  flex: 0 0 auto;
  color: #7f8ba3;
  font-size: 11px;
  white-space: nowrap;
}

.vessel-remove-btn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: #7f8ba3;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
}

.vessel-remove-btn:hover {
  background: rgba(255, 82, 82, 0.15);
  color: #ff5252;
}

.vessel-empty-hint {
  margin: 4px 0 0;
  color: #7f8ba3;
  font-size: 12px;
  font-style: italic;
}

#auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(11, 18, 32, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-dialog {
  background: #1a2438;
  border: 1px solid #33415c;
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.auth-dialog label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  color: #e6e9ef;
}

.auth-dialog form {
  display: flex;
  gap: 8px;
}

.auth-dialog input {
  flex: 1 1 auto;
  min-width: 0;
  background: #0b1220;
  color: #e6e9ef;
  border: 1px solid #33415c;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

.auth-dialog button {
  flex: 0 0 auto;
  background: #2f6fd6;
  color: #e6efff;
  border: 1px solid #2f6fd6;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}

.auth-dialog button:hover {
  background: #4aa3ff;
  border-color: #4aa3ff;
}

#auth-error {
  margin: 12px 0 0;
  color: #ffecec;
  background: #7c1c1c;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
}

/* --- Responsive breakpoints ------------------------------------------- */

/* Tablets / small laptops: tighten spacing and font sizes a bit so the
   header stays a compact one-or-two-line bar instead of crowding the map. */
@media (max-width: 768px) {
  #header {
    padding: 8px 10px;
    font-size: 13px;
    gap: 4px;
  }

  .header-main h1 {
    font-size: 16px;
  }

  .header-details {
    gap: 10px;
  }

  .banner {
    margin: 0 10px 8px;
    font-size: 12px;
  }
}

/* Phones: stack the header into clear rows, shrink text further, and hide
   the least-critical detail (IMO) to keep everything on screen without
   overflowing or squeezing the map. */
@media (max-width: 480px) {
  #header {
    padding: 6px 8px;
    font-size: 12px;
    gap: 4px;
  }

  .header-main {
    gap: 8px;
  }

  .header-main h1 {
    font-size: 15px;
  }

  .header-details {
    gap: 6px 10px;
  }

  /* Least-critical identifier — drop it on very small widths. */
  .imo-part {
    display: none;
  }

  .pill,
  .badge {
    font-size: 11px;
    padding: 2px 8px;
  }

  .follow-btn,
  .hdr-btn {
    font-size: 11px;
    padding: 4px 8px;
  }

  .banner {
    margin: 0 8px 8px;
    padding: 8px 10px;
    font-size: 11px;
    flex-wrap: wrap;
  }

  /* Give the panel more room on phones instead of the fixed 280px width,
     which would crowd the edges. */
  #vessel-panel {
    left: 8px;
    right: 8px;
    width: auto;
  }
}

/* Touch devices: guarantee ~44px tap targets on interactive controls,
   regardless of viewport width. */
@media (pointer: coarse) {
  .follow-btn,
  .hdr-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
  }

  .vessel-row {
    min-height: 44px;
  }

  .vessel-checkbox {
    width: 20px;
    height: 20px;
  }

  .vessel-remove-btn {
    min-width: 32px;
    min-height: 32px;
  }

  .banner button {
    min-height: 44px;
    min-width: 44px;
    font-size: 22px;
  }
}
