/* Shared styles for the public (index.html) and private (my.html) pages.
   Both pages have the same shell — map + panel + Simple mode — so the layout
   lives here and each page only adds what's unique to it. */

:root {
  --bg: #0e1726;
  --panel: #16203a;
  --accent: #4f9dff;
  --text: #e6edf7;
  --muted: #93a1bd;
  --border: #243150;
  /* Height of the mobile bottom sheet. Set by ui.js as you drag / snap it;
     ignored entirely on desktop, where the panel is a fixed-width sidebar. */
  --sheet-h: 55dvh;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  height: 100vh;
  height: 100dvh; /* dvh tracks the shrinking URL bar; vh doesn't */
  overflow: hidden;
  overscroll-behavior: none; /* no page-level rubber-banding behind the sheet */
}

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

#panel {
  width: 360px;
  flex: 0 0 360px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  /* Without this, a flex item can't shrink below its content's min-content
     height, so the panel overflows the viewport and its bottom — including the
     end of the flight list — is clipped away with no way to reach it. */
  min-height: 0;
}

header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex: 0 0 auto;
}
header .header-text { min-width: 0; }
header h1 { font-size: 16px; margin: 0 0 4px; }
header p { margin: 0; font-size: 12px; color: var(--muted); }
#open-simple { flex: 0 0 auto; white-space: nowrap; }

.controls {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  flex: 0 0 auto;
}

button {
  font: inherit; font-size: 13px; cursor: pointer;
  background: var(--accent); color: #04122b; border: 0;
  border-radius: 8px; padding: 8px 12px; font-weight: 600;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Touch devices get finger-sized hit areas (Apple's 44px guideline) without
   inflating the same controls on a mouse-driven desktop. */
@media (pointer: coarse) {
  button, select, .radiusctl select { min-height: 44px; }
  .maplayers .ml-btn { min-height: 36px; }
}

.status {
  padding: 8px 16px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border); min-height: 34px; flex: 0 0 auto;
}

/* Scroll areas. min-height:0 lets them actually shrink inside the flex column;
   overscroll-behavior stops a scroll that hits the end from chaining out to the
   page (which is overflow:hidden, so chaining just rubber-bands the whole UI). */
#flights, #ships-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
}

.flight {
  background: #101a31; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.flight.selected { border-color: #ffd400; box-shadow: 0 0 0 1px #ffd400 inset; }
.flight .head { display: flex; align-items: center; gap: 8px; }
/* The logo only gets its white plate once it has actually decoded — a failed
   or pending load would otherwise show as an empty white slab. */
.flight .logo {
  height: 44px; width: 72px; object-fit: contain; flex: 0 0 auto;
  border-radius: 6px; padding: 2px; opacity: 0; transition: opacity 0.15s ease;
}
.flight .logo.loaded { opacity: 1; background: #fff; }
.flight .route { font-size: 15px; font-weight: 700; }
.flight .route.no-route { color: var(--muted); font-weight: 600; }
.flight .route-names { font-size: 12px; color: var(--muted); margin-top: 2px; }
.flight .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.flight .meta { font-size: 12px; margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }
.flight .meta span b { color: var(--text); font-weight: 600; }

.empty { color: var(--muted); font-size: 13px; padding: 16px; text-align: center; }
.hidden { display: none !important; }
.hint { background: #1d2b49; color: var(--text); }

/* First-run state: no area picked yet, so give people the two ways in rather
   than an empty list and a sentence telling them to tap something. */
.firstrun { padding: 22px 18px; text-align: center; }
.firstrun .fr-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.firstrun h2 { font-size: 16px; margin: 0 0 6px; }
.firstrun p { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.45; }
.firstrun .fr-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.firstrun .fr-actions button { width: 100%; }

.plane-icon { line-height: 0; will-change: transform; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.85)); }

/* Always-on labels next to each plane marker. */
.leaflet-tooltip.plane-label {
  background: rgba(14, 23, 38, 0.82); color: var(--text);
  border: none; box-shadow: none; border-radius: 6px;
  padding: 2px 6px; font-size: 11px; line-height: 1.25; white-space: nowrap;
}
.leaflet-tooltip.plane-label::before { display: none; } /* hide arrow */
.plane-label .lbl-num { font-weight: 700; color: #ffd400; }
.plane-label .lbl-route { color: var(--muted); }
.plane-label.small .lbl-num { color: #ff8a1f; } /* match the orange small-plane icon */

/* Mode tabs (private page: My Window / Vacation). */
.tabs { display: flex; gap: 6px; padding: 12px 16px 0; flex: 0 0 auto; }
.tab {
  flex: 1; background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-weight: 600;
}
.tab.active { background: var(--accent); color: #04122b; border-color: var(--accent); }

.radiusctl { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.radiusctl select {
  font: inherit; font-size: 13px; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}

/* Follow mode: type a flight number to track one aircraft anywhere, and the
   banner that replaces the area controls while it's running. */
.followsearch { display: flex; gap: 8px; padding: 12px 16px 0; flex: 0 0 auto; }
.followsearch input {
  flex: 1 1 auto; min-width: 0;
  font: inherit; font-size: 13px; background: #101a31; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.followsearch input::placeholder { color: var(--muted); }
.followsearch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Below 16px iOS Safari zooms the whole page when the field takes focus. This
   is the app's only text input, so the rule has had no earlier home — and it
   has to sit after the base rule above, which has the same specificity. */
@media (pointer: coarse) {
  .followsearch input { min-height: 44px; font-size: 16px; }
}

.followbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; flex: 0 0 auto;
  background: #12203c; border-bottom: 1px solid var(--border);
}
.followbar .fb-main { flex: 1 1 auto; min-width: 0; }
.followbar .fb-title { display: block; font-weight: 700; font-size: 14px; }
.followbar .fb-sub { display: block; font-size: 12px; color: var(--muted); }
.followbar .fb-btn { flex: 0 0 auto; padding: 8px 10px; }
/* No position for a while — the marker on screen is a memory, not a fix. */
.followbar.stale { background: #2a2033; }
.followbar.stale .fb-sub { color: #ffb37a; }
/* Loudest exactly when it matters: the plane is off screen and you panned away. */
.followbar .fb-btn.offscreen { border-color: var(--accent); color: var(--accent); }

/* Floating trail look-back control, shown over the map only while a plane is
   selected. Sits below Leaflet's top-left zoom buttons. */
.trailctl {
  position: absolute; top: 78px; left: 10px; z-index: 1000;
  display: flex; align-items: center; gap: 6px;
  background: rgba(22, 32, 58, 0.92); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
.trailctl.hidden { display: none !important; }
.trailctl select {
  font: inherit; font-size: 12px; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px;
}

/* Floating "show on map" control — hides/shows the flight markers, the ship
   markers and the "heard" coverage overlay without clearing their data.
   Separate from the sidebar list toggle (which chooses what details the panel
   shows). Kept a sibling of #map (not a child) so button clicks don't reach the
   map. Wraps because three pills plus the label do not fit one narrow row. */
.maplayers {
  position: absolute; top: 10px; left: 60px; z-index: 1000;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  background: rgba(22, 32, 58, 0.92); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
.maplayers .ml-label { color: var(--muted); }
.maplayers .ml-btn {
  background: transparent; color: var(--muted); cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
  font-size: 13px; line-height: 1;
}
.maplayers .ml-btn.active { background: var(--accent); color: #04122b; border-color: var(--accent); }

/* When ui.js docks the map controls into the panel on small screens they stop
   floating and sit in normal flow. */
.dock { display: none; flex: 0 0 auto; }
.dock .maplayers, .dock .trailctl {
  position: static; background: transparent; border: 0;
  box-shadow: none; padding: 0; z-index: auto;
}
.dock .trailctl.hidden { display: none !important; }
/* Docked, these sit right above the Flights/Ships list tabs and would otherwise
   read as a second set of them. Keep the on/off state legible but quieter, so
   the filled pill stays unambiguously "which list am I looking at". */
.dock .maplayers .ml-btn.active {
  background: transparent; color: var(--accent); border-color: var(--accent);
}

/* Grab handle for the mobile bottom sheet. Hidden unless the sheet is active. */
.sheet-grab {
  display: none;
  flex: 0 0 auto;
  width: 100%; padding: 10px 0 6px; margin: 0;
  background: transparent; border: 0; border-radius: 16px 16px 0 0;
  cursor: grab;
  touch-action: none; /* we interpret the drag ourselves */
}
.sheet-grab::before {
  content: ""; display: block; width: 40px; height: 4px; margin: 0 auto;
  border-radius: 999px; background: #3b4a6d;
}
.sheet-grab:active { cursor: grabbing; }

/* Flights/Ships list toggle + ships table (sidebar). */
.listtabs { display: flex; gap: 6px; padding: 10px 16px 0; flex: 0 0 auto; }
.listtabs .ltab {
  flex: 1; background: transparent; color: var(--muted); cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  font-weight: 600; font-size: 13px;
}
.listtabs .ltab.active { background: var(--accent); color: #04122b; border-color: var(--accent); }

/* Ship list ordering, directly above the ships table it reorders. */
.shipsort {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 8px 16px 0; font-size: 12px; color: var(--muted);
}
.shipsort.hidden { display: none !important; }
.shipsort select {
  font: inherit; font-size: 12px; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}

.ships-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ships-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 8px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel);
}
/* The column the list is ordered by. */
.ships-table th.sorted { color: var(--accent); }
.ships-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ships-table tr.cruise td { background: rgba(120, 80, 200, 0.1); }
/* The vessel picked from the list — centred and haloed on the map. The left
   marker ties the row to the glow out there; cruise ships get the purple their
   icon and badge already use, everything else the cyan of the plain boat. */
.ships-table tr[data-mmsi] { cursor: pointer; }
.ships-table tr.selected td { background: rgba(56, 189, 248, 0.14); }
.ships-table tr.selected td:first-child { box-shadow: inset 3px 0 0 #38bdf8; }
.ships-table tr.selected.cruise td { background: rgba(179, 136, 255, 0.16); }
.ships-table tr.selected.cruise td:first-child { box-shadow: inset 3px 0 0 #b388ff; }
.ships-table tr[data-mmsi]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}
.ship-name { font-weight: 600; color: var(--text); }
.ship-dest { color: var(--muted); font-size: 11px; margin-top: 2px; }
.ship-age { color: var(--muted); font-size: 11px; margin-top: 2px; opacity: 0.85; }
.ship-status {
  display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 600;
  color: #9fe0c0; background: #16342a; border: 1px solid #285043;
  border-radius: 5px; padding: 1px 5px; vertical-align: middle;
}
.ship-type { color: var(--muted); white-space: nowrap; }
.ship-speed { white-space: nowrap; }
.cruise-badge {
  display: inline-block; background: #2a1d49; color: #d9b3ff; border: 1px solid #4a3a7a;
  border-radius: 5px; font-size: 10px; padding: 1px 5px; margin-left: 6px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; vertical-align: middle;
}

/* Ship map markers (small boat icons) + name labels. */
.ship-icon { line-height: 0; will-change: transform; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.85)); }
.ship-icon.stale { opacity: 0.45; } /* remembered, not freshly heard */
/* The halo itself is drawn in the marker's SVG, in the vessel's own colour
   (stacking above neighbouring boats is Leaflet's zIndexOffset, not CSS). This
   just keeps a picked-but-remembered vessel readable rather than leaving it at
   the stale opacity, where the halo would be too faint to find. */
.ship-icon.stale.selected { opacity: 0.75; }
.ships-table tr.stale .ship-name { opacity: 0.6; }
.ships-table tr.stale .ship-type, .ships-table tr.stale .ship-speed { opacity: 0.6; }
.leaflet-tooltip.ship-label {
  background: rgba(4, 18, 31, 0.82); color: var(--text);
  border: none; box-shadow: none; border-radius: 6px;
  padding: 2px 6px; font-size: 11px; line-height: 1.25; white-space: nowrap;
}
.leaflet-tooltip.ship-label::before { display: none; } /* hide arrow */
.leaflet-tooltip.ship-label.cruise { color: #d9b3ff; }

/* ---- Simple mode: full-screen glance card of the top-ranked flight. */
.simple {
  position: fixed; inset: 0; z-index: 3000;
  background: #000; color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 28px; text-align: center;
}
.simple.hidden { display: none !important; }
.simple-actions { position: absolute; top: 16px; right: 16px; display: flex; gap: 12px; }
.simple .icon-btn {
  background: rgba(255, 255, 255, 0.12); color: #cfd6e4; border: 0;
  border-radius: 999px; width: 44px; height: 44px; padding: 0;
  font-size: 18px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.simple .icon-btn:hover { background: rgba(255, 255, 255, 0.22); }
.simple-content { max-width: 640px; width: 100%; }
.s-header {
  font-size: 14px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  color: var(--muted); margin: 0 0 22px;
}
.s-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.s-card.dimmed { opacity: 0.55; }
.s-logo {
  height: 56px; width: auto; max-width: 72%; object-fit: contain;
  border-radius: 10px; padding: 6px 10px; opacity: 0; transition: opacity 0.15s ease;
}
.s-logo.loaded { opacity: 1; background: #fff; }
.s-route {
  font-size: clamp(40px, 13vw, 68px); font-weight: 800; line-height: 1.05; margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif; overflow-wrap: break-word;
}
.s-route.no-route { font-size: clamp(30px, 9vw, 52px); }
.s-route-names { font-size: 20px; color: var(--muted); }
.s-sub { font-size: 20px; font-weight: 600; }
.s-stats { display: flex; gap: 40px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.s-stat-label { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.s-stat-value { font-size: 20px; font-weight: 600; }
.s-footer { font-size: 13px; color: var(--muted); margin-top: 26px; }
.s-empty-icon { font-size: 64px; margin-bottom: 8px; }

/* Long/short button labels: phones get the glyph, wider screens get the words. */
.btn-short { display: none; }

/* ------------------------------------------------------------------------
   Phones, portrait: the panel becomes a draggable bottom sheet over a
   full-bleed map. Snap heights come from --sheet-h (set by ui.js), so the
   list's scroll box is always exactly as tall as the visible sheet — nothing
   is ever laid out below the fold where it can't be reached.
   ------------------------------------------------------------------------ */
@media (max-width: 700px) and (min-height: 500px) {
  body { display: block; }

  #map { position: fixed; inset: 0; height: auto; width: auto; }

  #panel {
    position: fixed; left: 0; right: 0; bottom: 0;
    width: auto; flex: none;
    height: var(--sheet-h);
    max-height: 92dvh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
    z-index: 1200; /* above Leaflet's panes and controls */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: height 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  }
  #panel.dragging { transition: none; }

  .sheet-grab { display: block; }
  .dock:not(:empty) { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 0 14px 8px; }

  /* Give the list back the room the chrome was eating. The primary actions keep
     their 44px targets; the secondary toggles give a few pixels back, which is
     worth about another flight card at the half detent. */
  header { padding: 0 14px 6px; border-bottom: 0; }
  header h1 { font-size: 15px; margin: 0; }
  header p { display: none; } /* the first-run card explains it better */
  .controls { padding: 6px 12px; gap: 6px; flex-wrap: nowrap; border-bottom: 0; }
  .controls .radiusctl { flex: 0 0 auto; }
  .followsearch { padding: 4px 12px 0; gap: 6px; }
  .followbar { padding: 6px 12px; }
  .status { padding: 3px 14px; min-height: 0; font-size: 11px; }
  .tabs { padding: 4px 12px 0; }
  .listtabs { padding: 4px 12px 0; }
  .listtabs .ltab, .tabs .tab { min-height: 38px; padding: 6px 8px; }
  .dock .ml-btn { min-height: 32px; }
  #flights, #ships-list { padding: 6px 10px; }
  .shipsort { padding: 4px 12px 0; }

  .btn-short { display: inline; }
  .btn-long { display: none; }

  /* Denser cards: ~130px -> ~80px, so three or four fit instead of one. */
  .flight { padding: 8px 10px; margin-bottom: 6px; border-radius: 8px; }
  .flight .logo { height: 30px; width: 48px; }
  .flight .route { font-size: 14px; }
  .flight .route-names { display: none; } /* codes already say it */
  .flight .sub { margin-top: 3px; }
  .flight .meta { font-size: 11px; margin-top: 3px; gap: 6px; }
  .flight .meta b { display: none; } /* "Boeing 737-800 · 4,200 ft · 271° W" */
  .flight .meta span:not(:last-child)::after { content: " ·"; color: var(--muted); }

  .leaflet-tooltip.plane-label { font-size: 10px; padding: 1px 5px; }
  /* Keep Leaflet's own controls clear of the sheet. */
  .leaflet-bottom { bottom: 0; }
}

/* ------------------------------------------------------------------------
   Short viewports (phones in landscape): a bottom sheet would leave no room
   at all, so keep the side-by-side layout but slim it right down.
   ------------------------------------------------------------------------ */
@media (max-height: 499px) {
  body { flex-direction: row; }
  #map { position: static; flex: 1 1 auto; height: 100%; }
  #panel {
    position: static;
    width: min(46vw, 320px); flex: 0 0 min(46vw, 320px);
    height: 100%; min-height: 0;
    border-radius: 0; border-left: 1px solid var(--border); border-top: 0;
    box-shadow: none;
  }
  .sheet-grab { display: none; }
  /* There are only ~340px of height here, and a 44px minimum on every control
     would spend most of it on chrome. 36px is still a comfortable target and
     buys back roughly two more flight cards. */
  button, select, .radiusctl select { min-height: 36px; }
  header { padding: 6px 10px; border-bottom: 0; }
  header h1 { font-size: 13px; margin: 0; }
  header p { display: none; }
  .controls { padding: 4px 8px; gap: 5px; border-bottom: 0; flex-wrap: nowrap; }
  .followsearch { padding: 4px 8px 0; gap: 5px; }
  .followbar { padding: 5px 8px; }
  .status { padding: 3px 10px; min-height: 0; font-size: 11px; }
  .tabs, .listtabs { padding: 4px 8px 0; }
  .listtabs .ltab, .tabs .tab { padding: 5px 8px; }
  #flights, #ships-list { padding: 6px 8px; }
  .shipsort { padding: 4px 8px 0; }
  .flight { padding: 7px 9px; margin-bottom: 6px; }
  .flight .logo { height: 28px; width: 44px; }
  .flight .route { font-size: 13px; }
  .flight .route-names { display: none; }
  .flight .sub { margin-top: 2px; }
  .flight .meta { font-size: 11px; margin-top: 3px; gap: 6px; }
  .flight .meta b { display: none; }
  .flight .meta span:not(:last-child)::after { content: " ·"; color: var(--muted); }
  .btn-short { display: inline; }
  .btn-long { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #panel, .flight .logo, .s-logo { transition: none !important; }
}


/* Account gate covers both pages before they start any data request. */
#auth-gate { position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; background: #101827; color: white; }
#auth-gate p { max-width: 30em; }
.apple-sign-in { display: inline-block; padding: 14px 24px; border-radius: 8px; background: white; color: black; font: 600 17px system-ui; text-decoration: none; }
.web-account { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 6px 12px; }
.web-account a { color: var(--accent); font-size: 13px; }
/* Pushed to the left so the links and the sign-out button stay together at the
   trailing edge, where they are on every page. */
.web-who { margin-right: auto; color: var(--muted); font-size: 12px; }
