html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, sans-serif;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f4f6f8;
}

.login-card {
  width: 320px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 24px;
}

.login-card h1 {
  margin-top: 0;
  font-size: 24px;
}

.login-card form {
  display: grid;
  gap: 10px;
}

.login-card input {
  padding: 10px;
  font-size: 14px;
}

.login-card button,
.topbar button,
.mobile-more-inner button {
  padding: 10px 12px;
  cursor: pointer;
}

.error {
  background: #ffe4e4;
  color: #8a1f1f;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 12px;
}

.muted {
  color: #666;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.map-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  gap: 12px;
  flex: 0 0 56px;
  position: relative;
  z-index: 1200;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

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

.desktop-actions {
  display: flex;
}

.mobile-actions {
  display: none;
}

.desktop-only {
  display: inline;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: row-reverse;
  position: relative;
}

.sidebar {
  width: 320px;
  flex: 0 0 320px;
  box-sizing: border-box;
  border-left: 1px solid #ddd;
  background: #fff;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  transition:
    width 0.2s ease,
    flex-basis 0.2s ease,
    padding 0.2s ease,
    border-left-color 0.2s ease,
    transform 0.2s ease;
  z-index: 1100;
}

.sidebar h2 {
  margin-top: 0;
}

.sidebar input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  margin-bottom: 12px;
}

.layout.sidebar-hidden .sidebar {
  width: 0;
  flex-basis: 0;
  padding: 0;
  border-left-color: transparent;
  overflow: hidden;
}

.layout.sidebar-hidden .sidebar > * {
  display: none;
}

.map-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mobile-sidebar-backdrop {
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 1050;
}

.mobile-more-menu {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: white;
  border-bottom: 1px solid #ddd;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 1250;
}

.mobile-more-inner {
  display: grid;
  gap: 10px;
  padding: 12px 16px 16px;
}

.mobile-more-inner form {
  margin: 0;
}

.mobile-user {
  margin-bottom: 2px;
}

.boat-label {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 140px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: #111827;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  pointer-events: auto;
}

.boat-label.pos-default,
.boat-label.pos-n {
  translate: -50% -100%;
}

.boat-label.pos-ne,
.boat-label.pos-e,
.boat-label.pos-se {
  translate: 0 -50%;
}

.boat-label.pos-s {
  translate: -50% 0;
}

.boat-label.pos-sw,
.boat-label.pos-w,
.boat-label.pos-nw {
  translate: -100% -50%;
}

.boat-card {
  width: 100%;
  text-align: left;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fafafa;
  cursor: pointer;
}

.boat-card.selected {
  border-color: #1d4ed8;
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
  background: #f8fbff;
}

.boat-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.boat-name {
  font-size: 16px;
  font-weight: 700;
}

.boat-river {
  margin-top: 4px;
  font-size: 14px;
}

.boat-meta {
  margin-top: 8px;
  font-size: 13px;
  color: #555;
}

.last-update {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.35;
}

.last-update-abs {
  color: #666;
  font-size: 12px;
}

.stale-good { color: #1b7f2a; }
.stale-warn { color: #b07a00; }
.stale-bad  { color: #b42318; }

.boat-marker svg polygon {
  fill: #2563eb;
  stroke: #0f172a;
  stroke-width: 1.2;
}

.boat-marker-shell {
  position: relative;
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: auto;
}

.boat-marker.selected svg polygon {
  fill: #f59e0b;
  stroke: #7c2d12;
  stroke-width: 1.4;
}

.boat-marker-ais-derived svg polygon {
  fill: #64748b;
  stroke: #1e293b;
  stroke-width: 1.2;
}

.boat-marker.selected.boat-marker-ais-derived svg polygon {
  fill: #f59e0b;
  stroke: #7c2d12;
  stroke-width: 1.4;
}

.boat-triangle {
  position: absolute;
  pointer-events:auto;
  left: 0;
  top: 0;
  transform-origin: center center;
  translate: -50% -50%;
}

.ais-marker svg polygon {
  fill: #6b7280;
  stroke: #111827;
  stroke-width: 1.1;
}


.ais-marker-shell {
  position: relative;
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: auto;
}

.ais-triangle {
  position: absolute;
  pointer-events: auto;
  left: 0;
  top: 0;
  transform-origin: center center;
  translate: -50% -50%;
}

.ais-label {
  position: absolute;
  pointer-events: auto;
  left: 0;
  top: 0;
  translate: -50% calc(-100% - 8px);
}

.ais-square {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
}

.ais-square svg {
  fill: #2d7dff;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.ais-marker.selected .ais-square svg {
  fill: #ffcc00;
}

.named-marker-icon {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}

.marker-wrap {
  position: relative;
  width: 120px;
  height: 80px;
  display: block;
  pointer-events: none;
  overflow: visible;
}

.marker-connector {
  position: absolute;
  pointer-events: none;
  left: 0;
  top: 0;
  width: 160px;
  height: 160px;
  overflow: visible;
  translate: -50% -50%;
}

.marker-connector line {
  stroke: rgba(17, 24, 39, 0.55);
  stroke-width: 1.2;
}

.marker-label {
  display: inline-block;
  max-width: 140px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: #111827;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.marker-label.ais {
  font-size: 11px;
  font-weight: 500;
  color: #374151;
}

.marker-label.selected {
  background: #ffedd5;
  border-color: #ea580c;
}

.item-badge {
  font-size: 11px;
  font-weight: 700;
  color: #374151;
  background: #e5e7eb;
  border-radius: 999px;
  padding: 3px 8px;
}

.popup-boat {
  min-width: 140px;
}

@media (max-width: 767px) {
  .topbar {
    justify-content: flex-end;
  }

  .topbar-left {
    display: none;
  }

  .topbar-left strong {
    font-size: 15px;
    white-space: nowrap;
  }

  .desktop-actions {
    display: none;
  }

  .mobile-actions {
    display: flex;
    gap: 8px;
  }

  .desktop-only {
    display: none;
  }

  .mobile-actions button {
    padding: 8px 10px;
    font-size: 13px;
  }

  .layout {
    display: block;
    height: 100%;
  }

  .map-wrap {
    position: relative;
    height: calc(100vh - 56px);
    min-height: calc(100vh - 56px);
  }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    max-width: 320px;
    border-left: none;
    border-right: 1px solid #ddd;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .layout.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .layout.sidebar-hidden .sidebar {
    width: min(84vw, 320px);
    flex-basis: auto;
    padding: 12px;
    border-left-color: transparent;
    overflow-y: auto;
  }

  .layout.sidebar-hidden .sidebar>* {
    display: block;
  }
}

.sidebar-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.sidebar-controls button {
  flex: 1 1 auto;
  padding: 10px;
  border: 1px solid #cfcfcf;
  border-radius: 8px;
  background: #f8f8f8;
  cursor: pointer;
}

.sidebar-section {
  margin-top: 14px;
}

.sidebar-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #555;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.fleet-health-list {
  max-width: 900px;
  padding: 12px 0 24px;
}

.fleet-health-card {
  background: #ffffff;
  border: 1px solid #d9d9d9;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

.fleet-health-name {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.fleet-health-status {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.fleet-health-status.is-fresh {
  background: #dcfce7;
  color: #166534;
}

.fleet-health-status.is-aging {
  background: #fef3c7;
  color: #92400e;
}

.fleet-health-status.is-stale {
  background: #fee2e2;
  color: #991b1b;
}

.fleet-health-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  line-height: 1.4;
}

.fleet-health-row:last-of-type .fleet-health-value {
  color: #666;
  font-size: 13px;
}

.fleet-health-label {
  width: 95px;
  flex: 0 0 95px;
  font-weight: 700;
  color: #444;
}

.fleet-health-value {
  color: #222;
  word-break: break-word;
}

@media (max-width: 767px) {
  .fleet-health-card {
    padding: 12px;
  }

  .fleet-health-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .fleet-health-name {
    font-size: 20px;
  }

  .fleet-health-row {
    flex-direction: column;
    gap: 2px;
  }

  .fleet-health-label {
    width: auto;
    flex: 0 0 auto;
  }
}

.fleet-age-text {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
}

.fleet-age-text.is-fresh {
  color: #166534;
}

.fleet-age-text.is-aging {
  color: #92400e;
}

.fleet-age-text.is-stale {
  color: #991b1b;
}

/* --- Admin pages --- */
.page-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.page-wrap h1,
.page-wrap h2 {
  margin-top: 0;
  margin-bottom: 16px;
}

.admin-card {
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-field label {
  font-size: 14px;
  font-weight: 700;
  color: #333;
}

.admin-field input,
.admin-field select {
  padding: 10px 12px;
  border: 1px solid #cfcfcf;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
  width: 100%;
}

.admin-actions-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.admin-note {
  margin-top: 8px;
  color: #666;
  font-size: 14px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e5e5;
  vertical-align: middle;
}

.admin-table th {
  font-size: 14px;
  font-weight: 700;
  color: #333;
  background: #f8f8f8;
}

.admin-table td {
  font-size: 14px;
}

.admin-inline-form {
  display: inline;
  margin: 0;
}

.admin-link-btn,
.admin-table button,
.admin-card button {
  padding: 8px 12px;
  border: 1px solid #cfcfcf;
  background: #f8f8f8;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.admin-link-btn:hover,
.admin-table button:hover,
.admin-card button:hover {
  background: #efefef;
}

.status-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.active {
  background: #dcfce7;
  color: #166534;
}

.status-pill.inactive {
  background: #fee2e2;
  color: #991b1b;
}

@media (max-width: 767px) {
  .admin-form-grid {
    grid-template-columns: 1fr;
  }

  .page-wrap {
    padding: 16px 12px 24px;
  }

  .admin-table th,
  .admin-table td {
    padding: 9px 10px;
    font-size: 13px;
  }
}

.mono-cell {
  font-family: Consolas, "Courier New", monospace;
}

details summary {
  cursor: pointer;
  font-weight: 600;
}

@media (max-width: 767px) {
  body:not(.map-page) .topbar {
    height: auto;
    min-height: 56px;
    padding: 10px 12px;
    align-items: flex-start;
    flex-direction: column;
  }

  body:not(.map-page) .topbar-left {
    display: none;
  }

  body:not(.map-page) .topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
}

@media (max-width: 767px) {

  .boat-label,
  .ais-label,
  .marker-connector {
    pointer-events: none;
  }
}

.marker-hitbox {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  translate: -50% -50%;
  background: transparent;
  pointer-events: auto;
}

.boat-source {
  font-size: 0.75em;
  color: #888;
}

.river-mile-label {
  background: rgba(255, 255, 255, 0.85);
  border: none;
  box-shadow: none;
  font-size: 11px;
  font-weight: 600;
  color: #333;
  padding: 1px 3px;
}

#zoom-display {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  z-index: 1000;
}