:root {
  --left-panel-width: 320px;
  --right-panel-width: 380px;
  --page-bg: #f6f4ef;
  --panel-bg: #ffffff;
  --text: #202124;
  --muted: #667085;
  --border: #d9ddd6;
  --accent: #176f75;
  --button-bg: #eef7f6;
  --button-border: #b9d9d7;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page-bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--left-panel-width) minmax(0, 1fr) var(--right-panel-width);
  min-height: 100vh;
}

.app-shell.right-panel-collapsed {
  grid-template-columns: var(--left-panel-width) minmax(0, 1fr);
}

.left-panel,
.right-panel {
  height: 100vh;
  overflow-y: auto;
  background: var(--panel-bg);
  padding: 20px;
}

.left-panel {
  border-right: 1px solid var(--border);
}

.right-panel {
  border-left: 1px solid var(--border);
}

.app-shell.right-panel-collapsed .right-panel {
  display: none;
}

.sidebar-header {
  margin-bottom: 22px;
}

.sidebar-header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  line-height: 1.1;
}

.sidebar-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.sidebar-controls {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-controls label {
  color: var(--muted);
  font-size: 13px;
}

.sidebar-controls input,
.sidebar-controls select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

.sidebar-controls input:focus,
.sidebar-controls select:focus {
  border-color: var(--accent);
  outline: none;
}

.map-actions {
  display: grid;
  gap: 8px;
}

.map-actions button {
  width: 100%;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--button-bg);
  color: #124f54;
  cursor: pointer;
}

.map-actions button:hover,
.map-actions button:focus {
  border-color: var(--accent);
  outline: none;
}

.runs-count,
.runs-total {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.runs-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--border);
}

.selection-panel {
  min-height: 100%;
}

.selection-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.selected-run-content {
  display: grid;
  gap: 12px;
}

.selected-run-content h2 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.selected-run-title {
  margin: 0;
  border-left: 6px solid var(--run-color, var(--accent));
  padding-left: 10px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.selected-run-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 14px;
}

.selected-run-meta dt {
  color: var(--muted);
}

.selected-run-meta dd {
  margin: 0;
  font-weight: 700;
}

.selection-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.selection-actions button {
  width: 100%;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--button-bg);
  color: #124f54;
  cursor: pointer;
}

.selection-actions button:hover,
.selection-actions button:focus {
  border-color: var(--accent);
  outline: none;
}

.selected-photo-gallery {
  display: grid;
  gap: 8px;
}

.selected-photo-gallery h3 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.photo-gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-thumb-button {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  background: #fafafa;
  cursor: pointer;
}

.photo-thumb-button:hover,
.photo-thumb-button:focus {
  border-color: var(--accent);
  outline: none;
}

.photo-thumb-button--no-gps {
  border-color: #c83f3f;
  box-shadow: inset 0 0 0 3px rgba(200, 63, 63, 0.75);
}

.photo-thumb-button.is-active {
  border-color: #b99b00;
  box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.35);
}

.photo-thumb-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-gallery-toggle {
  justify-self: start;
  border: 0;
  padding: 2px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.photo-gallery-toggle:hover,
.photo-gallery-toggle:focus {
  color: var(--accent);
  outline: none;
  text-decoration: underline;
}

.empty-list {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  color: var(--muted);
  font-size: 14px;
}

.run-list-item {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.run-list-item:hover,
.run-list-item:focus-visible {
  background: #f7fbfa;
  outline: none;
}

.run-list-item:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(23, 111, 117, 0.28);
}

.run-list-item.is-selected {
  background: #fff9d8;
  box-shadow: inset 3px 0 0 #b99b00;
}

.run-list-item__color {
  display: block;
  width: 4px;
  height: 100%;
  min-height: 32px;
  border-radius: 2px;
  background: var(--run-color, var(--accent));
}

.run-list-item__text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.run-list-item__title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-list-item__meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-panel {
  position: relative;
  min-width: 0;
  height: 100vh;
}

.right-panel-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 900;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel-bg);
  color: #124f54;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.right-panel-toggle:hover,
.right-panel-toggle:focus {
  border-color: var(--accent);
  outline: none;
}

#map {
  width: 100%;
  height: 100vh;
}

.track-popup h2,
.photo-popup h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.track-popup p,
.photo-popup p {
  margin: 4px 0;
}

.photo-popup {
  max-width: 280px;
}

.photo-popup img {
  display: block;
  object-fit: contain;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #f6f4ef;
}

.photo-popup--landscape img {
  width: 260px;
  max-width: 70vw;
  height: 170px;
}

.photo-popup--portrait {
  max-width: 220px;
}

.photo-popup--portrait img {
  width: 210px;
  max-width: 65vw;
  height: 310px;
}

.photo-popup__lightbox-button {
  width: 100%;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  padding: 7px 9px;
  background: var(--button-bg);
  color: #124f54;
  cursor: pointer;
  font: inherit;
}

.photo-popup__lightbox-button:hover,
.photo-popup__lightbox-button:focus {
  border-color: var(--accent);
  outline: none;
}

.photo-lightbox {
  --photo-lightbox-edge-gap: 4vh;
  --photo-lightbox-footer-gap: 14px;
  --photo-lightbox-footer-height: 52px;
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3000;
}

.photo-lightbox.is-open {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: var(--photo-lightbox-edge-gap) 4vw calc(var(--photo-lightbox-edge-gap) + var(--photo-lightbox-footer-height) + var(--photo-lightbox-footer-gap));
}

.photo-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 27, 0.72);
}

.photo-lightbox__content {
  box-sizing: border-box;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, auto) auto;
  gap: 10px;
  justify-items: center;
  max-width: 92vw;
  max-height: calc(100vh - var(--photo-lightbox-edge-gap) - var(--photo-lightbox-edge-gap) - var(--photo-lightbox-footer-height) - var(--photo-lightbox-footer-gap));
  padding: 18px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

.photo-lightbox__image {
  display: block;
  max-width: 88vw;
  max-height: calc(100vh - var(--photo-lightbox-edge-gap) - var(--photo-lightbox-edge-gap) - var(--photo-lightbox-footer-height) - var(--photo-lightbox-footer-gap) - 36px);
  object-fit: contain;
  background: #f6f4ef;
}

.photo-lightbox__caption {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.photo-lightbox__footer {
  position: fixed;
  left: 50%;
  bottom: 4vh;
  z-index: 2;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  width: min(640px, 88vw);
  min-height: var(--photo-lightbox-footer-height);
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  transform: translateX(-50%);
}

.photo-lightbox__button {
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  background: rgba(18, 79, 84, 0.88);
  color: #ffffff;
  cursor: pointer;
}

.photo-lightbox__button:hover,
.photo-lightbox__button:focus {
  background: #176f75;
  outline: none;
}

.photo-lightbox__button:disabled {
  cursor: default;
  opacity: 0.35;
}

.photo-lightbox__button--prev,
.photo-lightbox__button--next {
  width: 36px;
  height: 36px;
  font-size: 30px;
  line-height: 1;
}

.photo-lightbox__button--close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  font-size: 24px;
  line-height: 1;
}

.photo-marker {
  width: 22px;
  height: 22px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: #176f75;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.run-start-marker-icon,
.run-direction-arrow-icon {
  background: transparent;
  border: 0;
}

.leaflet-run-direction-markers-pane {
  pointer-events: none;
}

.run-direction-arrow-icon {
  pointer-events: none;
}

.run-start-marker {
  display: block;
  position: relative;
  width: 22px;
  height: 22px;
  border: 3px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  background: var(--run-color, #176f75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
  transform: rotate(-45deg);
}

.run-start-marker--selected {
  width: 30px;
  height: 30px;
  border-width: 4px;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.8),
    0 3px 12px rgba(0, 0, 0, 0.42);
}

.run-start-marker::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
}

.run-start-marker--selected::after {
  top: 7px;
  left: 7px;
  width: 8px;
  height: 8px;
}

.run-direction-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--run-color, #176f75);
  font-size: 18px;
  line-height: 1;
  text-shadow:
    0 1px 0 #513f00,
    1px 0 0 #513f00,
    0 -1px 0 #513f00,
    -1px 0 0 #513f00,
    0 2px 5px rgba(0, 0, 0, 0.34);
  transform-origin: center;
}

.run-endpoint-icon {
  background: transparent;
  border: 0;
}

.run-endpoint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.32);
}

.run-endpoint--start {
  background: #12823b;
}

.run-endpoint--end {
  background: #c62828;
}

.app-error {
  padding: 16px;
  border: 1px solid #f0b8b8;
  border-radius: 8px;
  background: #fff2f2;
  color: #8a1f1f;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 58vh) auto;
  }

  .app-shell.right-panel-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 58vh);
  }

  .left-panel,
  .right-panel {
    height: auto;
    max-height: none;
  }

  .left-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .map-panel {
    height: 58vh;
    min-height: 360px;
  }

  #map {
    height: 100%;
  }

  .right-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}
