/* ---------------------------------------------------------------------
   Telemetry Tunnel — chart-room design system.

   Direction: this reads like a page torn from a chart table, not a SaaS
   dashboard. Parchment paper, chart ink, a hazard-mark red used sparingly,
   a brass instrument accent for rules and borders. Numeric telemetry is
   set in a monospace face with tabular figures so live-updating values
   don't jitter the layout as digits change width.
   --------------------------------------------------------------------- */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --paper: #E8E4D3;
  --sea: #C9DDD6;
  --ink: #16232E;
  --ink-soft: #4A5D68;
  --hazard: #B8391F;
  --brass: #8B6F3E;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(var(--paper), var(--paper)),
    repeating-linear-gradient(0deg, rgba(139,111,62,0.05) 0px, rgba(139,111,62,0.05) 1px, transparent 1px, transparent 32px);
  min-height: 100vh;
}

a { color: inherit; }

::selection { background: var(--hazard); color: var(--paper); }

:focus-visible {
  outline: 2px solid var(--hazard);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- shared chrome ---------- */

.rule {
  border: none;
  border-top: 1px dashed var(--brass);
  opacity: 0.6;
  margin: 0;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.compass {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
}

.compass-spin {
  animation: spin 3.6s linear infinite;
  transform-origin: 50% 50%;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- view: entry form ---------- */

#view-form {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  border: 1px solid var(--brass);
  box-shadow: 0 1px 0 rgba(22,35,46,0.06), 0 8px 24px rgba(22,35,46,0.08);
  padding: 36px 32px 32px;
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(139,111,62,0.35);
  pointer-events: none;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.card-header svg { width: 28px; height: 28px; flex: none; }

.card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: 0.01em;
}

.card p.lede {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 10px 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--brass);
  color: var(--ink);
}

.field input:focus {
  border-color: var(--hazard);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 5px;
}

button.primary {
  width: 100%;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  padding: 12px 16px;
  margin-top: 6px;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}

button.primary:hover { background: #223243; }
button.primary:active { transform: translateY(1px); }
button.primary:disabled { opacity: 0.55; cursor: default; }

.form-error {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--hazard);
  margin-top: 14px;
  line-height: 1.5;
  display: none;
}

.form-error.visible { display: block; }

/* ---------- view: tracking ---------- */

#view-track {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}

#view-track.active { display: flex; }
#view-form.hidden { display: none; }

.trackbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--brass);
  background: var(--paper);
}

.trackbar-vessel {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.trackbar-vessel h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trackbar-tunnel {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex: none;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.status[data-state="live"] .status-dot {
  background: var(--hazard);
  box-shadow: 0 0 0 rgba(184,57,31,0.5);
  animation: pulse 1.8s ease-in-out infinite;
}

.status[data-state="connecting"] .status-dot,
.status[data-state="reconnecting"] .status-dot {
  background: var(--brass);
}

.status[data-state="offline"] .status-dot,
.status[data-state="closed"] .status-dot {
  background: var(--ink-soft);
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(184,57,31,0.45); }
  70%  { box-shadow: 0 0 0 7px rgba(184,57,31,0); }
  100% { box-shadow: 0 0 0 0 rgba(184,57,31,0); }
}

.trackmain {
  flex: 1;
  display: flex;
  min-height: 0;
}

@media (max-width: 860px) {
  .trackmain { flex-direction: column; }
}

.chartpane {
  flex: 1 1 62%;
  position: relative;
  min-height: 320px;
  background: var(--sea);
  border-right: 1px solid var(--brass);
}

@media (max-width: 860px) {
  .chartpane { border-right: none; border-bottom: 1px solid var(--brass); }
}

#map { position: absolute; inset: 0; }

.chart-watermark {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 400;
  opacity: 0.55;
  pointer-events: none;
}

.chart-watermark svg { width: 40px; height: 40px; }

.readpane {
  flex: 1 1 38%;
  max-width: 380px;
  padding: 18px 20px 24px;
  overflow-y: auto;
  background: var(--paper);
}

@media (max-width: 860px) {
  .readpane { max-width: none; }
}

.readgroup {
  margin-bottom: 22px;
}

.readgroup-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.readgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.readout {
  border-left: 2px solid var(--brass);
  padding-left: 10px;
}

.readout.span-2 { grid-column: 1 / -1; }

.readout-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 3px;
}

.readout-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

.readout-value .unit {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-left: 3px;
  font-weight: 400;
}

.readout-value.stale { color: var(--ink-soft); }

.readgroup-note {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-style: italic;
  color: var(--ink-soft);
  margin: -4px 0 10px;
  line-height: 1.35;
}

/* Calculated (derived on this page) vs. measured (from the tunnel): a
   dashed brass border and slightly muted value color, rather than the
   solid border every directly-measured readout uses, so a viewer never
   mistakes a client-side estimate for an instrument reading. */
.readout.calculated {
  border-left: 2px dashed var(--brass);
}
.readout.calculated .readout-value {
  color: var(--ink-soft);
}
.readout.calculated .readout-label::after {
  content: ' ✦';
  color: var(--brass);
}

.banner {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 12px 14px;
  border: 1px solid var(--hazard);
  color: var(--hazard);
  background: rgba(184,57,31,0.06);
  margin-bottom: 18px;
  line-height: 1.5;
  display: none;
}

.banner.visible { display: block; }

.vessel-icon {
  filter: drop-shadow(0 1px 2px rgba(22,35,46,0.35));
}

/* ---------- chart tile-provider picker ---------- */

.chart-picker {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  background: var(--paper);
  border: 1px solid var(--brass);
  padding: 10px 12px;
  max-width: 240px;
  box-shadow: 0 1px 0 rgba(22,35,46,0.06), 0 4px 12px rgba(22,35,46,0.12);
}

.chart-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-picker-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  flex: none;
}

.chart-picker select {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 5px 6px;
  background: #fff;
  border: 1px solid var(--brass);
  color: var(--ink);
}

.chart-picker select:focus {
  border-color: var(--hazard);
}

.chart-picker-overlay {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 8px;
  cursor: pointer;
}

.chart-picker-note {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.4;
  margin-top: 8px;
}

/* MapLibre's own controls (zoom, attribution) get the same chart-room
   treatment rather than their default white-on-white look. */
.maplibregl-ctrl-group {
  background: var(--paper);
  border: 1px solid var(--brass);
  box-shadow: none;
  border-radius: 0;
}

.maplibregl-ctrl-attrib {
  background: rgba(232,228,211,0.85);
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.maplibregl-ctrl-attrib a {
  color: var(--ink-soft);
}
