/* Windrose Global Freight - Cargo Tracker (demo)
   Palette: chart-navy ink + parchment surfaces + brass "live data" accent + sea-teal routes.
   Nautical-chart / instrument-panel aesthetic. */

:root {
  --bg: #f2efe6;
  --surface: #ffffff;
  --surface-2: #e8e3d3;
  --ink: #142534;
  --ink-soft: #576674;
  --line: #dad4c1;
  --line-strong: #b9b096;
  --accent: #146b6b;
  --accent-soft: #dcece9;
  --accent-ink: #0d4f4f;
  --brass: #a8791f;
  --brass-soft: #f3e6c8;
  --brass-ink: #7a5714;
  --warn: #a8452f;
  --warn-soft: #f6e4dd;
  --empty-ink: #8a8877;
  --shadow: 0 12px 32px rgba(20, 37, 52, 0.16);
  --radius: 10px;
  --font-ui: "Space Grotesk", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1922;
    --surface: #15232f;
    --surface-2: #1c2e3c;
    --ink: #e7ecef;
    --ink-soft: #93a7b3;
    --line: #253947;
    --line-strong: #35505f;
    --accent: #4fd1c8;
    --accent-soft: #123b3a;
    --accent-ink: #8fe6df;
    --brass: #e0b34a;
    --brass-soft: #362c12;
    --brass-ink: #f3cd76;
    --warn: #e08469;
    --warn-soft: #3a2016;
    --empty-ink: #647585;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-ui); }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--brass);
  border-radius: 9px;
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--ink-soft);
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }

/* ---------- buttons ---------- */

.btn {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; }

.btn-solid {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-solid:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-lang { font-family: var(--font-mono); min-width: 64px; }

/* ---------- live toggle ---------- */

.live-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}
.live-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.live-toggle-track {
  width: 38px;
  height: 21px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  position: relative;
  flex: none;
  transition: background 0.15s, border-color 0.15s;
}
.live-toggle-thumb {
  position: absolute;
  top: 1px; left: 1px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}
.live-toggle input:checked + .live-toggle-track {
  background: var(--brass);
  border-color: var(--brass);
}
.live-toggle input:checked + .live-toggle-track .live-toggle-thumb {
  transform: translateX(17px);
}
.live-toggle input:focus-visible + .live-toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.live-toggle-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

/* ---------- stat bar ---------- */

.statbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 40px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.stat { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
.stat[hidden] { display: none; }

.stat-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}

.stat-value {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.live-note-stat { min-width: 0; }
.live-note {
  font-size: 12.5px;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 6px;
  padding: 5px 10px;
  display: inline-block;
}

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  align-items: stretch;
  min-height: 0;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- map ---------- */

.map-panel {
  position: relative;
  min-height: 480px;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}

@media (max-width: 900px) {
  .map-panel { min-height: 60vh; }
  .legend {
    left: 8px;
    bottom: 8px;
    padding: 6px 9px;
    font-size: 10.5px;
    gap: 3px;
    max-width: 46vw;
  }
  .legend-dot { width: 8px; height: 8px; }
}

/* Leaflet's default attribution control sits bottom-right and, on a narrow
   phone screen, its long text ("OpenStreetMap contributors, CARTO") wraps
   to two lines -- tall enough to collide with our own bottom-left legend
   box. Keep it single-line and compact so the two never overlap. */
.leaflet-control-attribution {
  font-size: 10px;
  max-width: 48vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-container { font-family: var(--font-ui); }

.ship-popup { font-size: 13px; }
.ship-popup .p-name { font-weight: 700; margin: 0 0 4px; }
.ship-popup .p-row { color: var(--ink-soft); font-size: 12.5px; }
.ship-popup a { color: var(--accent-ink); }

/* legend */

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend-row[hidden] { display: none; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend-dot-ship { background: var(--accent); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--accent); }
.legend-dot-live { background: var(--brass); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--brass); }

/* ---------- detail panel ---------- */

.detail-panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  position: relative;
}
.detail-panel[hidden] { display: none; }

@media (max-width: 900px) {
  .detail-panel {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 900;
    max-height: 72vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow);
  }
}

.detail-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.detail-close:hover { background: var(--surface-2); }

.detail-body { padding-right: 4px; }

.d-vessel-name {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 2px;
  padding-right: 30px;
}
.d-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 0 16px;
}

.d-route {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}
.d-route .port { flex: 1; }
.d-route .port.dest { text-align: right; }
.d-route .arrow { color: var(--ink-soft); font-family: var(--font-mono); }

.d-progress-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 4px;
}
.d-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.6s ease;
}
.d-progress-pct {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}

.d-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-bottom: 18px;
}
.d-field { display: flex; flex-direction: column; gap: 2px; }
.d-field-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.d-field-value { font-size: 13.5px; font-weight: 600; }

.d-leg {
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.d-leg-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-ink);
  margin-bottom: 2px;
}
.d-leg-value { font-size: 13.5px; font-weight: 600; color: var(--accent-ink); }

.d-eta {
  font-size: 12.5px;
  color: var(--ink-soft);
}
.d-eta strong { color: var(--ink); font-family: var(--font-mono); }

/* live vessel detail variant */
.d-live-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brass-ink);
  background: var(--brass-soft);
  border-radius: 5px;
  padding: 3px 8px;
  margin-bottom: 10px;
}
.d-live-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-ink);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.d-live-link:hover { color: var(--accent); }

/* ---------- shipment list bar (bottom strip, always visible) ---------- */

.shiplist-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.ship-chip {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 168px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s;
}
.ship-chip:hover { border-color: var(--accent); }
.ship-chip.active { border-color: var(--accent); background: var(--accent-soft); }

.ship-chip-name {
  font-size: 12.5px;
  font-weight: 700;
}
.ship-chip-route {
  font-size: 11px;
  color: var(--ink-soft);
}
.ship-chip-bar {
  height: 3px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 2px;
}
.ship-chip-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}

/* ---------- demo note ---------- */

.demo-note {
  margin: 0;
  padding: 8px 24px 14px;
  font-size: 11.5px;
  color: var(--empty-ink);
  background: var(--surface);
  text-align: center;
}

/* ---------- access gate ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate[hidden] { display: none; }

.gate-lang-corner {
  position: absolute;
  top: 16px;
  right: 20px;
  font-family: var(--font-mono);
  min-width: 64px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 30px 30px;
  text-align: center;
}

.gate-card .brand-mark { margin: 0 auto 14px; }

.gate-card h1 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.gate-note {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--ink-soft);
}

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

.gate-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 0.1em;
  text-align: center;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
}
.gate-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.gate-error {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--warn);
}
.gate-error[hidden] { display: none; }

/* ---------- custom leaflet markers ---------- */

.wr-ship-icon {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0,0,0,0.3);
}
.wr-ship-icon.selected {
  background: var(--accent-ink);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 2px 8px rgba(0,0,0,0.4);
}
.wr-live-icon {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--brass);
  border: 1.5px solid var(--surface);
  box-shadow: 0 0 0 1px var(--brass), 0 1px 4px rgba(0,0,0,0.3);
}
.wr-port-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.0);
  white-space: nowrap;
  text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 5px var(--surface);
}
