/* Mobile-first: base styles target a phone screen. The >=800px query below
   switches the bridge list from cards to a dense table and loosens up spacing
   for desktop/dispatcher use. */

* { box-sizing: border-box; }

:root {
  --bg: #0b1220;
  --bg-raised: #0f1830;
  --border: #1d2740;
  --text: #e8eef5;
  --text-dim: #9fb1d6;
  --text-dimmer: #b8c7e6;
  --ok-bg: #113a22;   --ok-fg: #7be594;
  --marg-bg: #3a310f; --marg-fg: #f3dc7b;
  --block-bg: #3a1311; --block-fg: #f59b9b;
  --unk-bg: #26304f;  --unk-fg: #b8c7e6;
  --mov-bg: #142a45;  --mov-fg: #7db8f5;
  --need-bg: #2a1f45; --need-fg: #c8a8f5;
  --touch: 44px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Banners ---------- */

.alert-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--block-bg);
  color: var(--block-fg);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}

.offline-banner {
  background: var(--marg-bg);
  color: var(--marg-fg);
  padding: 8px 16px;
  font-size: 13px;
  text-align: center;
}

.loading-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-raised);
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 13px;
  text-align: center;
}

.loading-banner[hidden] { display: none; }

.spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: #4f7cf0;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---------- Header ---------- */

header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 { margin: 0; font-size: 19px; }
h2 { margin: 0 0 8px; font-size: 15px; color: var(--text-dimmer); }

p.disclaimer {
  margin: 8px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.account-trigger {
  flex-shrink: 0;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  padding: 8px 14px;
}

.account-trigger.logged-in {
  border-color: #4f7cf0;
  background: #16223f;
}

/* ---------- Account modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(4, 8, 18, 0.72);
  display: flex;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  width: 100%;
  max-width: 380px;
  height: fit-content;
  margin-top: 8vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  padding: 0 6px;
  min-height: auto;
}

/* ---------- Controls ---------- */

.controls {
  border-bottom: 1px solid var(--border);
}

.controls-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  min-height: var(--touch);
  background: var(--bg-raised);
  color: var(--text);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.controls-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 16px 16px;
}

/* An explicit `display` on an author rule beats the UA stylesheet's
   `[hidden] { display: none }` regardless of specificity, so the hidden
   attribute needs its own explicit override here or it's silently ignored. */
.controls-body[hidden] { display: none; }

.control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

label { color: var(--text-dimmer); font-size: 14px; }

input, select, button {
  padding: 10px 12px;
  min-height: var(--touch);
  border-radius: 10px;
  border: 1px solid #243258;
  background: #101a33;
  color: var(--text);
  font-size: 15px;
}

button { cursor: pointer; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: default; transform: none; }

.last-updated { color: var(--text-dim); font-size: 12px; }

/* ---------- Vessels ---------- */

.vessel-panel {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.vessel-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.vessel-row {
  display: flex;
  gap: 6px;
}

.vessel-select {
  flex: 1;
  text-align: left;
}

.vessel-row.active .vessel-select {
  border-color: #4f7cf0;
  background: #16223f;
}

.vessel-delete {
  min-width: var(--touch);
  color: var(--block-fg);
}

.vessel-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.vessel-form label { margin-top: 4px; }

.form-error {
  color: var(--block-fg);
  font-size: 13px;
  margin: 4px 0 0;
}

.sync-note {
  margin: 0 0 10px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

.account-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.account-tab {
  flex: 1;
  background: transparent;
}

.account-tab.active {
  border-color: #4f7cf0;
  background: #16223f;
  color: var(--text);
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Same lesson as .controls-body above: an author `display` rule beats the
   UA stylesheet's `[hidden] { display: none }`, so each hidden form needs
   its own explicit override or all four (login/signup/forgot/reset) render
   stacked at once regardless of which tab is active. */
.account-form[hidden] { display: none; }

.account-form label { margin-top: 4px; }

.link-button {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--text-dimmer);
  text-decoration: underline;
  min-height: auto;
  padding: 6px 0;
}

.account-loggedin-line {
  margin: 0 0 4px;
  font-size: 14px;
}

.admin-badge {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--need-bg);
  color: var(--need-fg);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  vertical-align: middle;
}

.sync-status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--ok-fg);
}

.sync-status-error { color: var(--block-fg); }

/* ---------- Bridge list: cards (mobile default) ---------- */

.list-wrap { padding: 12px 16px; }

.bridge-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bridge-card {
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg-raised);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.card-top strong { font-size: 15px; }

.card-mile { color: var(--text-dim); font-size: 13px; }

.card-margin-label {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px;
}

.card-clearance {
  font-size: 30px;
  font-weight: 700;
  margin: 2px 0 6px;
}

.card-detail { color: var(--text-dimmer); font-size: 13px; }

.card-note {
  margin-top: 6px;
  color: var(--marg-fg);
  font-size: 12px;
}

/* Status border tint per card, echoed on the big margin number itself so a
   blocked bridge reads red at a glance without having to read the pill. */
.bridge-card.status-ok { border-left-color: var(--ok-fg); }
.bridge-card.status-ok .card-clearance { color: var(--ok-fg); }
.bridge-card.status-marginal { border-left-color: var(--marg-fg); }
.bridge-card.status-marginal .card-clearance { color: var(--marg-fg); }
.bridge-card.status-blocked { border-left-color: var(--block-fg); }
.bridge-card.status-blocked .card-clearance { color: var(--block-fg); }
.bridge-card.status-unknown { border-left-color: var(--unk-fg); }
.bridge-card.status-movable { border-left-color: var(--mov-fg); }
.bridge-card.status-needsdata { border-left-color: var(--need-fg); }

/* ---------- Bridge list: table (desktop, hidden on mobile) ---------- */

.table-wrap { display: none; }

table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 10px;
  color: var(--text-dimmer);
  text-align: left;
}
tbody td { padding: 10px; border-bottom: 1px solid #1c2744; }
tr:hover { background: var(--bg-raised); }

/* ---------- Status pill (shared by cards + table) ---------- */

.status {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
  white-space: nowrap;
}
.status.ok { background: var(--ok-bg); color: var(--ok-fg); }
.status.marginal { background: var(--marg-bg); color: var(--marg-fg); }
.status.blocked { background: var(--block-bg); color: var(--block-fg); }
.status.unknown { background: var(--unk-bg); color: var(--unk-fg); }
.status.movable { background: var(--mov-bg); color: var(--mov-fg); }
.status.needsdata { background: var(--need-bg); color: var(--need-fg); }

/* ---------- NOAA gauges ---------- */

.gauges-section { border-top: 1px solid var(--border); }

.gauges-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  min-height: var(--touch);
  background: var(--bg-raised);
  color: var(--text);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* No explicit `display` here on purpose — same lesson as the controls-body
   bug: an author `display` value beats the UA stylesheet's `[hidden] {
   display: none }` regardless of specificity, which would silently defeat
   the hidden attribute this section is toggled with. */
.gauges-body { padding: 4px 16px 16px; }

.gauges-note {
  margin: 0 0 10px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

.gauge-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gauge-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  font-size: 13px;
}

.gauge-name { flex: 1; color: var(--text); }
.gauge-id { color: var(--text-dim); font-variant: small-caps; }
.gauge-stage { color: var(--text-dimmer); font-weight: 600; white-space: nowrap; }

/* ---------- Admin ---------- */

.admin-section { border-top: 1px solid var(--border); }

.admin-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  min-height: var(--touch);
  background: var(--need-bg);
  color: var(--need-fg);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* No explicit `display` here on purpose -- same [hidden]-override lesson as
   .gauges-body/.controls-body above. */
.admin-body { padding: 4px 16px 16px; }

.admin-editor { margin-top: 14px; }

.admin-editor h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text-dimmer);
}

.admin-textarea {
  display: block;
  width: 100%;
  height: 260px;
  margin: 8px 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #243258;
  background: #0a1224;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

/* ---------- Map ---------- */

.map-section { border-top: 1px solid var(--border); }

.map-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  min-height: var(--touch);
  background: var(--bg-raised);
  color: var(--text);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#map { height: 50vh; border-top: 1px solid var(--border); }

/* ---------- Footer ---------- */

footer {
  padding: 14px 16px 24px;
  color: var(--text-dim);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.report-issue-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 14px;
  min-height: var(--touch);
  line-height: calc(var(--touch) - 20px);
  border-radius: 10px;
  border: 1px solid #243258;
  background: #101a33;
  color: var(--text-dimmer);
  font-size: 13px;
  text-decoration: none;
}
.report-issue-btn:hover,
.report-issue-btn:focus-visible {
  color: var(--text);
  border-color: #3a4d80;
}

/* ---------- Desktop / wide screens ---------- */

@media (min-width: 800px) {
  header, .controls-body, .list-wrap, footer { padding-left: 20px; padding-right: 20px; }

  /* Controls and map are always visible on desktop; their mobile collapse
     toggles are hidden, and a [hidden] override forces both open regardless
     of whatever collapsed state was set while the viewport was narrow. */
  .controls-toggle, .map-toggle { display: none; }
  #controlsBody[hidden] { display: flex; }
  #map[hidden] { display: block; }

  .vessel-form {
    grid-template-columns: repeat(4, 1fr) auto;
    align-items: end;
  }

  .bridge-cards { display: none; }
  .table-wrap { display: block; overflow: auto; }

  .card-clearance { font-size: 20px; }
}
