:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #64717f;
  --line: #d9e0e7;
  --panel: #ffffff;
  --surface: #f3f6f8;
  --primary: #0d6b63;
  --primary-dark: #084f49;
  --accent: #c94f2f;
  --danger: #a83232;
  --shadow: 0 18px 48px rgba(20, 35, 48, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 2000;
  transform: translateY(-160%);
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 900;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.skip-link:focus {
  transform: translateY(0);
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  min-height: 76px;
  padding: 14px clamp(16px, 3vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: #102832;
  color: #fff;
}

.brand,
.account,
.field-row,
.form-actions,
.coords,
.inline-heading,
.report-card-header {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
  background: #c94f2f;
}

.eyebrow {
  margin: 0 0 3px;
  color: #82919e;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #b8c7d1;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.35rem, 3vw, 2rem);
}

h2 {
  font-size: 1.05rem;
}

.account {
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account-status {
  color: #d9e6ed;
  font-size: 0.9rem;
}

.shell {
  height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 430px);
  overflow: hidden;
}

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

#map {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #d9e5eb;
}

/* Local Leaflet layout fallback for offline/restricted preview environments. */
.leaflet-container {
  overflow: hidden;
  position: relative;
  z-index: 0;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  margin: 12px 0 0 12px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 24px rgba(20, 35, 48, 0.18);
}

.leaflet-control-zoom a {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  background: #fff;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-control-attribution {
  margin: 0 6px 4px 0;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.82);
  color: #46535e;
  font-size: 0.68rem;
}

.leaflet-control-layers {
  margin: 12px 12px 0 0;
  padding: 9px 10px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(20, 35, 48, 0.16);
  color: #24323c;
  font-size: 0.82rem;
  font-weight: 750;
}

.leaflet-control-layers label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.leaflet-control-layers input {
  width: auto;
  min-height: auto;
  margin: 0;
  padding: 0;
}

.leaflet-control-layers-separator,
.leaflet-control-layers-base {
  display: none;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 0;
  line-height: 1.35;
}

.leaflet-popup-tip-container {
  width: 40px;
  height: 20px;
  position: absolute;
  left: 50%;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 14px;
  height: 14px;
  margin: -7px auto 0;
  transform: rotate(45deg);
  background: #fff;
  box-shadow: var(--shadow);
}

.train-marker-shell {
  background: transparent;
  border: 0;
}

.train-marker {
  width: 54px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 8px 20px rgba(20, 35, 48, 0.3);
  opacity: var(--marker-opacity, 1);
}

.train-marker__text {
  color: #fff;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  max-width: 44px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.train-marker__text.compact {
  font-size: 0.68rem;
}

.train-marker--northbound {
  background: #1f7a4f;
}

.train-marker--southbound {
  background: #b5432c;
}

.train-marker--eastbound {
  background: #235f9f;
}

.train-marker--westbound {
  background: #7a4c9f;
}

.train-marker--unknown {
  border-color: #111;
  background: #fff;
}

.train-marker--unknown .train-marker__text {
  color: #111;
}

.map-overlay {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.map-overlay span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.side-panel {
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.panel-section {
  margin: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-section + .panel-section {
  margin-top: 10px;
}

.app-nav {
  display: none;
}

.section-heading {
  margin-bottom: 14px;
}

.inline-heading {
  justify-content: space-between;
  gap: 12px;
}

.helper {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.account-summary {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: #33414b;
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1.4;
}

.form-grid {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: #35424d;
  font-size: 0.86rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd5de;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(13, 107, 99, 0.18);
  border-color: var(--primary);
}

.coords {
  gap: 10px;
}

.coords label {
  flex: 1 1 0;
}

.location-grid,
.search-grid {
  display: grid;
  gap: 10px;
}

.location-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-hint {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.35;
}

.field-row {
  gap: 8px;
  align-items: end;
}

.field-row label {
  flex: 1 1 auto;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f1ef;
  color: #164f49;
  font-size: 0.82rem;
  font-weight: 800;
}

.chip button {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: rgba(13, 107, 99, 0.13);
  cursor: pointer;
}

.button,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.button {
  min-height: 40px;
  padding: 9px 13px;
  white-space: nowrap;
}

.button-primary {
  background: var(--primary);
  color: #fff;
}

.button-primary:hover {
  background: var(--primary-dark);
}

.button-secondary {
  background: #fff;
  color: var(--primary-dark);
}

.button-ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: #24323c;
}

.button-danger {
  background: var(--danger);
  color: #fff;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  background: #102832;
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
}

.form-actions {
  gap: 10px;
  justify-content: space-between;
}

.locked {
  opacity: 0.55;
}

.locked form {
  pointer-events: none;
}

.report-list {
  display: grid;
  gap: 10px;
}

.admin-list,
.page-stack,
.user-list {
  display: grid;
  gap: 10px;
}

.search-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.search-grid .button {
  grid-column: 1 / -1;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: -4px 0 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.tab-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 850;
}

.tab-button.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(20, 35, 48, 0.1);
}

.report-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff;
}

.admin-card,
.user-card,
.info-page,
.moderation-tools {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-card p,
.user-card p,
.info-page p,
.moderation-tools p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.admin-subsection {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.admin-subsection h3 {
  margin: 0;
  font-size: 0.95rem;
}

.user-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  align-items: center;
  gap: 12px;
}

.user-role {
  min-height: 38px;
}

.info-page h3 {
  margin: 0;
  font-size: 0.98rem;
}

.admin-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f1ef;
  color: var(--primary-dark);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.admin-edit-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.admin-title {
  font-size: 0.96rem;
}

.admin-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.report-card-header {
  justify-content: space-between;
  gap: 10px;
}

.report-title {
  font-size: 0.98rem;
}

.report-direction {
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 850;
}

.report-card p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.35;
}

.report-card .report-locos {
  color: #33414b;
  font-weight: 650;
}

.empty-state {
  padding: 18px;
  border: 1px dashed #b9c5ce;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
  text-align: center;
}

.leaflet-popup-content {
  min-width: 190px;
}

.popup-title {
  margin: 0 0 6px;
  font-weight: 850;
}

.popup-meta {
  margin: 0;
  color: #52616d;
}

@media (max-width: 900px) {
  body {
    padding-bottom: 72px;
  }

  .shell {
    height: calc(100vh - 76px);
    min-height: 0;
    grid-template-columns: 1fr;
    overflow: hidden;
  }

  .map-panel {
    height: 100%;
    min-height: 0;
  }

  .side-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 78px;
    z-index: 900;
    max-height: min(68vh, 620px);
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(243, 246, 248, 0.98);
    box-shadow: var(--shadow);
  }

  .app-panel {
    display: none;
  }

  .app-panel.active-panel {
    display: block;
  }

  .panel-section {
    margin: 0;
    border: 0;
    border-radius: 12px;
  }

  .app-nav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 950;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 12px 34px rgba(20, 35, 48, 0.2);
  }

  .nav-button {
    min-height: 46px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 900;
  }

  .nav-button.active {
    background: #e8f1ef;
    color: var(--primary-dark);
  }

  .auth-panel[hidden] {
    display: none;
  }

  .locked {
    opacity: 1;
  }

  .locked::before {
    content: "Sign in from Account to post reports.";
    display: block;
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 8px;
    background: #fff5df;
    color: #7b4e00;
    font-size: 0.86rem;
    font-weight: 800;
  }

  .locked form {
    opacity: 0.5;
  }

  .side-panel {
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .account {
    width: 100%;
    justify-content: space-between;
  }

  .map-overlay,
  .coords,
  .location-grid,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .location-grid,
  .search-grid {
    grid-template-columns: 1fr;
  }

  .map-overlay {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .button {
    width: 100%;
  }

  .admin-actions {
    display: grid;
  }
}
