/*
  Design tokens shared with gpx_weather (light mode only).
  Palette source: static/gpxlibrary.svg (orange grid #f39c12, slate frame #2c3e50,
  red saddle #c0392b, blue wheels #3498db). The accents are the same primary
  blue / soft orange combo as gpx_weather so both apps feel like one product.
*/
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --text: #2c3e50;
  --muted: #5d6d7e;
  --accent: #2980b9;
  --accent-2: #c0392b;
  --danger: #c0392b;
  --border: rgba(44, 62, 80, 0.14);
  --accent-soft-bg: rgba(243, 156, 18, 0.12);
  --accent-soft-border: rgba(243, 156, 18, 0.38);
  --hover-bg: rgba(44, 62, 80, 0.05);
  --select-bg: rgba(41, 128, 185, 0.1);
  --shadow-sm: 0 1px 4px rgba(44, 62, 80, 0.08);
  --shadow-md: 0 4px 16px rgba(44, 62, 80, 0.16);

  --pane-explorer: 280px;
  --pane-detail: 320px;
  --pane-elevation: 160px;
  --navbar-h: 72px;

  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Ubuntu,
    sans-serif;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

/* --- Layout primitives (login, settings) --- */
.container {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.container.narrow {
  max-width: 24rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

/* --- Header bar (used on every authenticated page + login uses brand only) --- */
.bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: var(--navbar-h);
}

.bar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.bar-right .btn-secondary {
  margin-left: 0;
}

a.bar-user-link {
  color: var(--muted);
  text-decoration: none;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.bar-user-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  font-size: 1.75rem;
  color: var(--text);
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand-logo {
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  display: block;
}

.brand-text {
  line-height: 1;
}

.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 2rem;
  margin: 0 0 0.5rem;
}

/* --- Buttons (vanilla, matches gpx_weather) --- */
button,
.btn {
  cursor: pointer;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.2;
  transition: filter 0.12s ease, background-color 0.12s ease, color 0.12s ease,
    border-color 0.12s ease;
}

button:hover,
.btn:hover {
  /* Reassert background so Bootstrap's `.btn:hover { background-color: var(--bs-btn-hover-bg); }`
     (unset on a bare `.btn`) doesn't wipe it to white. The brightness filter then gives the lift. */
  background: var(--accent);
  filter: brightness(1.08);
  color: #fff;
  text-decoration: none;
}

button:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled,
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
}

button.btn-secondary,
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.btn-secondary:hover,
.btn-secondary:hover {
  filter: none;
  background: var(--hover-bg);
  color: var(--text);
}

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

button.btn-outline-danger,
.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

button.btn-outline-danger:hover,
.btn-outline-danger:hover {
  filter: none;
  background: var(--danger);
  color: #fff;
}

button.btn-text,
.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0 0.25rem;
  font-size: 0.9rem;
  font-weight: 500;
}

button.btn-text:hover,
.btn-text:hover {
  filter: none;
  background: transparent;
  text-decoration: underline;
}

button.btn-text.danger,
.btn-text.danger {
  color: var(--danger);
}

/* Smaller variant used inside dense panes (tree toolbar, detail actions) */
.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  border-radius: 5px;
}

/* --- Forms --- */
label {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.field-control {
  display: flex;
  width: 100%;
  min-width: 0;
  gap: 0.5rem;
  align-items: center;
}

.field-control > input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.field-control > button {
  flex: 0 0 auto;
  white-space: nowrap;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input[type="file"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* --- Feedback --- */
.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.warn {
  background: var(--accent-soft-bg);
  border: 1px solid var(--accent-soft-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Native dialog used by the password-change feedback flow. */
.feedback-dialog {
  margin: auto;
  padding: 1.25rem;
  max-width: min(92vw, 22rem);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.feedback-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.feedback-dialog__heading {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.feedback-dialog__msg {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.45;
}

.feedback-dialog--success .feedback-dialog__heading {
  color: #4ade80;
}

.feedback-dialog--error .feedback-dialog__heading {
  color: var(--danger);
}

.feedback-dialog .btn-secondary {
  margin-left: 0;
  width: 100%;
}

/* --- 3-pane app shell (only applies on the library page) --- */
body.app-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

body.app-page > .bar {
  flex: 0 0 auto;
}

.app-shell {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--pane-explorer) 6px 1fr 6px var(--pane-detail);
  min-height: 0;
  min-width: 960px;
}

.app-shell.map-maximized {
  grid-template-columns: var(--pane-explorer) 6px 1fr 0 0;
}

.app-shell.map-maximized #detail-resizer,
.app-shell.map-maximized .pane-detail,
.app-shell.map-maximized #elevation-resizer,
.app-shell.map-maximized #elevation-panel {
  display: none;
}

.pane-resizer {
  background: var(--border);
  cursor: col-resize;
  user-select: none;
  transition: background-color 0.15s;
}

.pane-resizer-horizontal {
  cursor: row-resize;
  height: 6px;
  width: 100%;
  flex: 0 0 6px;
}

.pane-resizer:hover,
.pane-resizer.dragging {
  background: var(--muted);
}

body.resizing {
  user-select: none;
}

body.resizing.resizing-x {
  cursor: col-resize;
}

body.resizing.resizing-y {
  cursor: row-resize;
}

body.resizing iframe,
body.resizing .leaflet-container {
  pointer-events: none;
}

.pane {
  overflow: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.75rem;
}

.pane-map {
  padding: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-detail {
  border-right: none;
}

.pane-toolbar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.pane-toolbar .btn {
  flex: 1 1 auto;
}

/* --- Map --- */
.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.map-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-hint {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  z-index: 500;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
}

.map-legend {
  position: absolute;
  top: 3rem;
  right: 0.75rem;
  z-index: 800;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  max-width: 220px;
  max-height: calc(40vh - 2.25rem);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

.map-legend-title {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.map-fullscreen-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 900;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  box-shadow: var(--shadow-sm);
}

.map-fullscreen-btn:hover,
.map-fullscreen-btn:focus-visible {
  background: #fff;
  color: var(--accent);
  outline: none;
  border-color: var(--accent);
  filter: none;
}

.map-fullscreen-btn[aria-pressed="true"] {
  background: var(--select-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.map-fit-btn {
  right: 3.25rem;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.map-legend-item:last-child {
  margin-bottom: 0;
}

.map-legend-swatch {
  width: 14px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* --- Elevation panel --- */
.elevation-panel {
  flex: 0 0 var(--pane-elevation, 160px);
  height: var(--pane-elevation, 160px);
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.4rem 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.elevation-meta {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.85rem;
}

.elevation-meta-sep {
  color: var(--border);
}

.elevation-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.elevation-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* --- Explorer tree --- */
.tree-root {
  font-size: 0.9rem;
}

.tree-folder {
  margin-bottom: 0.15rem;
}

.tree-folder-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.35rem;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
}

.tree-folder-header:hover,
.tree-file:hover {
  background: var(--hover-bg);
}

.tree-folder-header.selected,
.tree-file.selected {
  background: var(--select-bg);
  color: var(--accent);
}

.tree-folder-check {
  margin: 0;
  flex: 0 0 auto;
  cursor: pointer;
  width: 1rem;
  height: 1rem;
}

.tree-folder-check:disabled {
  opacity: 0.35;
  cursor: default;
}

.tree-toggle {
  width: 1rem;
  text-align: center;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.7rem;
}

.tree-folder-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  margin-left: 1rem;
}

.tree-file {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.35rem 0.2rem 1.35rem;
  border-radius: 5px;
  cursor: pointer;
}

.tree-file-check {
  margin: 0;
  flex: 0 0 auto;
  cursor: pointer;
  width: 1rem;
  height: 1rem;
}

.tree-file-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.1rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent-soft-bg);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--accent-soft-border);
}

/* --- Detail pane --- */
.detail-stats {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.detail-stats dt {
  float: left;
  clear: left;
  width: 6rem;
  color: var(--muted);
  font-weight: 500;
}

.detail-stats dd {
  margin: 0 0 0.25rem 6.5rem;
  word-break: break-word;
}

.detail-stats::after {
  content: "";
  display: block;
  clear: both;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.detail-row label {
  margin: 0;
}

.detail-row select {
  flex: 1 1 auto;
}

.detail-row .btn-sm {
  flex: 0 0 auto;
}

.detail-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.detail-heading-row h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.detail-meta-form button {
  margin-top: 0.5rem;
}

.detail-save-status {
  font-size: 0.85rem;
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.detail-save-status.is-error {
  color: var(--danger);
}

/* Tables (rides) */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 500;
}

tr:last-child td {
  border-bottom: none;
}

/* --- Login page --- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
}

body.login-page main {
  width: 100%;
}

body.login-page .login-brand .brand-logo {
  width: 2.5rem;
  height: 2.5rem;
}

/* --- Bootstrap modal restyle (we keep .modal markup so bootstrap.bundle.js still drives them) --- */
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.1rem;
  display: flex;
  align-items: center;
}

.modal-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0;
}

.modal-body {
  padding: 1rem 1.1rem;
}

.modal-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-body label {
  margin-bottom: 0.5rem;
}

.modal-body .form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.btn-close {
  background: transparent;
  border: none;
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  margin-left: auto;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  opacity: 0.7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.btn-close::before {
  content: "✕";
}

.btn-close:hover {
  opacity: 1;
  background: var(--hover-bg);
  filter: none;
  color: var(--text);
}

/* --- Mobile tab bar (only on the app page, hidden on desktop) --- */
.mobile-tabbar {
  display: none;
}

/* Breakpoint matches `.app-shell { min-width: 960px }` so there is no dead
   zone where the desktop grid is wider than the (overflow-hidden) viewport and
   the right pane gets clipped with no way to scroll to it. */
@media (max-width: 960px) {
  :root {
    --tabbar-h: 52px;
    --navbar-h: 56px;
  }

  body.app-page {
    height: 100dvh;
  }

  .app-shell {
    display: block;
    grid-template-columns: none;
    min-width: 0;
    padding-bottom: var(--tabbar-h);
  }

  .pane-explorer,
  .pane-map,
  .pane-detail {
    display: none;
    height: 100%;
  }

  .app-shell[data-mobile-view="explorer"] .pane-explorer {
    display: block;
  }
  .app-shell[data-mobile-view="map"] .pane-map {
    display: flex;
  }
  .app-shell[data-mobile-view="detail"] .pane-detail {
    display: block;
  }

  .pane {
    border-right: none;
  }

  .pane-resizer,
  #elevation-resizer,
  .map-fullscreen-btn {
    display: none;
  }

  .elevation-panel {
    flex: 0 0 120px;
    height: 120px;
  }

  .map-legend {
    max-width: 60vw;
    max-height: 35vh;
  }

  .mobile-tabbar {
    display: flex;
    position: fixed;
    inset: auto 0 0 0;
    height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1000;
  }

  .mobile-tab {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 0;
    padding: 0.5rem;
  }

  .mobile-tab:hover {
    background: var(--hover-bg);
    color: var(--text);
    filter: none;
  }

  .mobile-tab[aria-selected="true"] {
    color: var(--accent);
    box-shadow: inset 0 2px 0 0 var(--accent);
    background: transparent;
  }
}

@media (max-width: 640px) {
  .bar {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0.5rem;
  }

  .bar .brand {
    font-size: 1.125rem;
    gap: 0.35rem;
  }

  .bar .brand-logo {
    width: 1.75rem;
    height: 1.75rem;
  }

  a.bar-user-link {
    max-width: min(10rem, 28vw);
  }

  .login-brand {
    font-size: 1.5rem;
    gap: 0.5rem;
  }

  .login-brand .brand-logo {
    width: 2rem;
    height: 2rem;
  }
}
