/* Reset & base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 1. Root height chain */
html,
body {
    height: 100%;
    margin: 0;
}

/* 2. Page structure */
body {
    display: flex;
    flex-direction: column;
}

body {
  font-family: system-ui, sans-serif;
  background-color: #f9f9f9;
  color: #333;
  line-height: 1.6;
  padding: 1rem;
}


/* Header and navigation */
header,
footer {
    flex: 0 0 auto; /* fixed height */
}


header {
  background-color: #005f73;
  padding: 1rem 0.5rem;
  margin-bottom: 1rem;
  border-radius: 6px;
}

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}

nav a {
  color: #fff;
  text-decoration: none;
  font-weight: bold;
  transition: opacity 0.2s ease-in-out;
}

nav a:hover {
  opacity: 0.8;
}

nav a.active {
  border-bottom: 2px solid #fff;
  padding-bottom: 2px;
}

/* Put items in the centre */
.centre {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: auto;
}

.centered-form {
  padding-top: 1rem;
  text-align: center;
}

/* Main content */
/* 3. Main must define available vertical space */
main {
    flex: 1 1 auto;
    min-height: 0; /* CRITICAL */
    display: flex;
    flex-direction: column;
}

main {
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  min-height: 0; /* for flexbox layouts */
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropbtn {
  background-color: transparent;
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.dropbtn:hover {
  text-decoration: underline;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #444;
  min-width: 160px;
  right: 0;
  z-index: 9999;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.dropdown-content a {
  color: white;
  padding: 10px 12px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #555;
}

/* Show when toggled */
.dropdown.open .dropdown-content {
  display: block;
}

/* Journey header */
/* 4. Journey header sits above editor */
.journey-header {
    flex: 0 0 auto;
}

.journey-header {
  padding: 10px 16px;
  border-bottom: 1px solid #ccc;
  background: #fafafa;
}

.journey-scroll {
  flex: 1;
  overflow-y: auto;
}

.journey-title {
  margin: 0 0 6px;
}

.journey-description {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.3rem;
  max-height: 3.9rem; /* roughly 3 lines */
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.journey-description.expanded {
  max-height: 500px; /* enough space to animate fully */
}

.read-more-btn {
  margin-top: 4px;
  padding: 2px 4px;
  border: none;
  background: none;
  color: #0066cc;
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
  display: none; /* shown only if needed */
}

/* Modal dialog */
/* Title row */
.journey-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Add button */
.add-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.add-btn:hover {
  background: #0066d3;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}

.modal-overlay.active {
  display: flex;
}

/* Modal window */
.modal-box {
  background: white;
  width: 420px;
  padding: 20px;
  border-radius: 10px;
  animation: fadeIn 0.3s;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.cancel-btn {
  background: #ccc;
  border: none;
  padding: 6px 10px;
}
.save-btn {
  background: #28a745;
  border: none;
  padding: 6px 10px;
  color: white;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* Modal dialog to create new journey */
.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-content {
  position: relative;
  background: #fff;
  max-width: 500px;

  /* NEW */
  max-height: calc(100vh - 40px);
  overflow-y: auto;

  margin: 20px auto;
  padding: 24px;
  border-radius: 8px;
}


.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.modal[hidden] {
  display: none;
}

/* Journey edit page layout */

/* 5. Two-column editor fills remaining space */
.edit-container {
    flex: 1 1 auto;
    min-height: 0;          /* CRITICAL */
    display: flex;
    overflow-y: auto;       /* scrollbar if viewport too small */
}

/* 6. Left column */
.forms {
    flex: 0 0 auto;         /* or fixed width if you already use one */
    min-width: 140px;      /* CRITICAL: allow shrinking */
    padding-right: 16px;
}

.forms h3 {
  margin-top: 1rem;
}

.grant-access-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;       /* allow wrapping on smaller screens */
}

.grant-access-form label {
  white-space: nowrap;   /* keep "Find user:" together */
}

.grant-access-form input {
  flex: 1;               /* input expands on wide screens */
  min-width: 200px;      /* prevents collapsing too much */
}

.grant-access-form select {
  flex: 1;               /* input expands on wide screens */
  min-width: 100px;      /* prevents collapsing too much */
}

.grant-access-form button {
  flex: 1;               /* input expands on wide screens */
  min-width: 100px;      /* prevents collapsing too much */
}

.autocomplete-suggestions {
  position: absolute;
  background: #fff;
  border: none;
  border-radius: 4px;
  margin-top: 2px;
  max-height: 200px;
  overflow-y: auto;
  width: 250px;
  z-index: 1000;
}

.autocomplete-suggestions div {
  padding: 8px 10px;
  cursor: pointer;
}

.autocomplete-suggestions div:hover {
  background-color: #f0f0f0;
}

.access-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.access-item {
  display: flex;
  align-items: center;
  gap: 10px;       /* space between elements */
  margin-bottom: 8px;
}

.access-username {
  flex: 1;         /* takes remaining space so forms align right */
  font-weight: bold;
}

.access-usertag {
  flex: 1;         /* takes remaining space so forms align right */
  font-size: smaller;
  color: darkgreen;
}

.access-form {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
}

select[name="role"] {
  min-width: 14ch; /* "Contributor" = 11 chars; add padding */
}

/* List of GPX tracks */
.track-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.track-item {
  display: flex;
  align-items: center;
  justify-content: space-between; /* pushes name left, checkbox right */
  padding: 6px 0;
  border-bottom: 1px solid #ddd;
}

.track-item:hover {
  color: #8b0000; /* dark red on hover */
}

.track-name {
  flex: 1;
}


/* 7. Right column: map + media */
.map-and-media {
    flex: 1 1 auto;
    min-height: 0;          /* CRITICAL */
    min-width: 0;
    display: flex;
    flex-direction: column;
}


/* 8. Map grows, thumbnails keep intrinsic height */
#map-container {
    flex: 1 1 auto;
    min-height: 300px;
}

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

/* Loading overlay */
.map-loading {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35); /* darken map */
    z-index: 500; /* above Leaflet tiles, below modals */
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* allow map to exist underneath */
    transition: opacity 0.2s ease;
}

.map-loading.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* Spinner */
.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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


/* Thumbnail strip container */
.thumb-strip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  min-width: 0;
}

/* Prev/Next buttons */
.thumb-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 20px;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
  z-index: 10;
  transition: background 0.2s ease;
}
.thumb-btn:hover { background: rgba(0, 0, 0, 0.8); }
.thumb-btn:disabled { opacity: 0.4; cursor: default; }

/* Thumbnails scroller */
.media-thumbnails {
  display: flex;
  flex-direction: row;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 10px;
  flex: 1 1 auto;   /* fill remaining space between buttons */
  min-width: 0;     /* CRITICAL: enable horizontal overflow */
  cursor: grab;
}
.media-thumbnails.dragging { cursor: grabbing; }

/* Individual thumbnails */
.media-thumbnails .thumbnail-image {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  scroll-snap-align: start;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.media-thumbnails .thumbnail-image:hover {
  transform: scale(1.05);
  box-shadow: 0 0 10px rgba(0,0,0,0.4);
}
/* small hover effect on thumbnail */
.thumbnail-image:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

/* Hide scrollbar */
.media-thumbnails::-webkit-scrollbar { height: 8px; }
.media-thumbnails::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
}

/* ---------- Fullscreen overlay ---------- */
.image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);

  display: flex;
  flex-direction: row;

  opacity: 0;
  pointer-events: none;
  z-index: 9997;
  transition: opacity .2s ease-in-out;
}

.image-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-image-container {
  position: relative;

  flex: 1 1 auto;           /* take remaining space */
  min-width: 0;             /* IMPORTANT for flex shrink */
  min-height: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  overflow: hidden;         /* prevent overflow artifacts */
}

.overlay-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;

  transition: opacity .2s ease-in-out;
}

.overlay-close {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  padding: 0;
  overflow: hidden;
}

.mini-map {
  position: relative;
  width: 220px;
  height: 220px;
  border-radius: 10px;
  overflow: hidden;
}

.hidden { display: none !important; }

.overlay-meta {
  min-width: 220px;
  flex-shrink: 0;
  padding: 20px;
  overflow-y: auto;
  color: #fff;
}


/* Footer */
footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.9rem;
  color: #777;
}

/* Buttons */
button,
input[type="submit"] {
  background-color: #0a9396;
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

button:hover,
input[type="submit"]:hover {
  background-color: #007f86;
}

/* Forms */
input, textarea, select {
  width: 100%;
  padding: 0.6rem;
  margin: 0.5rem 0 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

label {
  display: block;
  margin-top: 1rem;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 600px) {
  nav {
    flex-direction: column;
    align-items: center;
  }

  main {
    padding: 0.8rem;
  }
}

/* Flash messages */
.flash {
  padding: 0.8rem;
  margin: 1rem 0;
  border-radius: 4px;
  text-align: center;
  font-weight: bold;
}

.flash-success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash-error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.journey-search,
.journey-create {
  margin: 1rem 0;
}

.journey-search input,
.journey-create input {
  padding: 0.5rem;
  margin-right: 0.5rem;
}

/* Media */
.media-thumbnails img,
.media-thumbnails video {
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.media-thumbnails img:hover,
.media-thumbnails video:hover {
  transform: scale(1.05);
}

/* Journey explore page */
.page-title {
  margin: 20px 0;
  font-size: 2.2rem;
  text-align: center;
}

.journey-grid {
  display: grid;
  grid-template-columns: 1fr; /* full width rows */
  gap: 18px;
  padding: 20px;
}

.journey-card a {
  display: flex;
  gap: 16px;
  color: inherit;
  text-decoration: none;
  padding: 12px;
  align-items: flex-start;
}

.journey-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.cover {
  flex: 0 0 240px;
  height: 160px;
  overflow: hidden;
  background: #eee;
  border-radius: 8px;
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.journey-text {
  flex: 1;
  min-width: 0; /* prevents overflow */
}

.title {
  margin: 0 0 6px 0;
  font-size: 1.3rem;
}

.desc {
  margin: 0;
  color: #444;
  font-size: .95rem;
}

.meta {
  margin-top: 8px;
  color: #777;
  font-size: .8rem;
}

/* For the feed page */
.feed {
  margin-left: 20px;
}

/* For the map popup on the journey edit page */
.map-popup-image {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border-radius: 4px;
}

/* User account page */
.avatar {
  background-color: #005f73;
  padding: 1rem;
  border-radius: 4px;
  color: white;
}

.account-form {
  max-width: 400px;
  overflow-x: auto;
  overflow-y: auto;
}

/* Form field wrapper */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}

/* Inputs inside form fields */
.form-field input {
  font: inherit;
  padding: 0.55rem 0.6rem;
  border: 1px solid #c9c9c9;
  border-radius: 4px;
  background: #fff;
}

.form-field input:focus {
  outline: none;
  border-color: #005fcc;
  box-shadow: 0 0 0 2px rgba(0, 95, 204, 0.15);
}

/* Error message */
.form-error {
  margin: 0 0 1rem 0;
  padding: 0.6rem 0.75rem;
  border-left: 4px solid #c62828;
  background: #fdecea;
  color: #8a1f1f;
  font-size: 0.95rem;
}

/* Primary action button */
button.primary {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.6rem 1.25rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background-color: #005fcc;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button.primary:hover {
  background-color: #0047a3;
}

button.primary:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 95, 204, 0.3);
}

button.primary:disabled {
  background-color: #9bb7e0;
  cursor: not-allowed;
}

.form-hint {
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #666;
  background-color: #f5f7f9;
}

.form-note {
  margin-top: 1rem;
  padding-top: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #555;
  border-top: 1px solid #e0e0e0;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

.account-form-buttons {
  display: flex;
  margin-top: 1rem;
  align-items: center;
}

/* Help */
.note {
  background: #f5f7f9;
  border-left: 4px solid #4a90e2;
  padding: 1rem;
  margin: 1.5rem 0;
}
.help-body {
  overflow-x: auto;
  overflow-y:auto;
  max-width: 800px;
}

.help-body h1, h2, h3 {
  line-height: 1.3;
}

.help-body h2 {
  margin-top: 3rem;
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.25rem;
}

.help-body h3 {
  margin-top: 1.75rem;
}
.help-body ul, ol {
  margin-left: 1.5rem;
}
.help-body li {
  margin: 0.5rem 0;
}
