:root {
  --ink: #17211c;
  --muted: #69746d;
  --paper: #f4f5f1;
  --panel: #fbfcf8;
  --line: #dfe3dc;
  --accent: #ef5b36;
  --green: #1f7a59;
  --amber: #d79b28;
  --red: #d34b39;
  --sidebar: 252px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button { font: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  width: 100vw;
  height: 100dvh;
  background: var(--paper);
}

.sidebar {
  position: relative;
  z-index: 1200;
  display: flex;
  min-height: 0;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.brand strong { display: block; margin-top: 3px; font-size: 19px; letter-spacing: -.02em; }
.eyebrow, .route-heading span, .profile-label, .drawer-head span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.route-list { flex: 1; min-height: 0; overflow: auto; padding: 8px; }
.route-button {
  display: grid;
  grid-template-columns: 35px minmax(0, 1fr) auto;
  width: 100%;
  min-height: 62px;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease;
}
.route-button:hover { background: #f0f2ed; }
.route-button.active { background: #fff; border-color: #d6dbd2; box-shadow: 0 3px 12px rgba(24, 35, 28, .06); }
.route-day {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  background: #ecefe9;
  border-radius: 50%;
}
.route-button.active .route-day { color: white; background: var(--accent); }
.route-name { min-width: 0; }
.route-name strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.route-name span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.route-distance { font-size: 11px; font-weight: 700; color: var(--muted); }
.backup-pill { display: inline-block; margin-left: 4px; padding: 1px 4px; color: #755411; font-size: 9px; background: #f4e8c9; border-radius: 4px; }

.sidebar-foot {
  display: flex;
  height: 39px;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  color: var(--muted);
  font-size: 10px;
  border-top: 1px solid var(--line);
}
.legend-line { width: 18px; height: 3px; background: var(--accent); border-radius: 3px; }

.workspace { display: grid; min-width: 0; min-height: 0; grid-template-rows: 58px minmax(0, 1fr) 156px; }
.topbar {
  position: relative;
  z-index: 1100;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 18px;
  padding: 8px 14px 8px 18px;
  background: rgba(251, 252, 248, .96);
  border-bottom: 1px solid var(--line);
}
.route-heading { min-width: 230px; margin-right: auto; }
.route-heading h1 { overflow: hidden; margin: 2px 0 0; font-size: 17px; letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }
.metrics { display: flex; align-items: center; gap: 16px; }
.metric { min-width: 58px; }
.metric b { display: block; font-size: 14px; letter-spacing: -.02em; }
.metric span { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.top-actions { display: flex; gap: 7px; }
.compact-button, .icon-button {
  height: 34px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  background: #fff;
  border: 1px solid #d8ddd5;
  border-radius: 8px;
  cursor: pointer;
}
.compact-button { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; }
.compact-button:hover, .icon-button:hover { background: #f3f5f0; }
.compact-button b { display: grid; min-width: 19px; height: 19px; place-items: center; color: white; font-size: 9px; background: var(--ink); border-radius: 9px; }
.compact-button:disabled { opacity: .45; cursor: default; }
.icon-button { display: grid; width: 34px; place-items: center; font-size: 20px; line-height: 1; }
.mobile-only { display: none; }

.map-stage { position: relative; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: #dfe5dc; }
.leaflet-container { font: inherit; }
.leaflet-control-zoom { border: 0 !important; box-shadow: 0 4px 16px rgba(18, 31, 23, .15) !important; }
.leaflet-control-zoom a { color: var(--ink) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { padding: 2px 5px !important; color: #66716a; font-size: 9px !important; background: rgba(255,255,255,.82) !important; }
.leaflet-control-attribution a { color: #375c49; }
.route-shadow { stroke: rgba(255,255,255,.9); }

.map-note {
  position: absolute;
  z-index: 500;
  left: 14px;
  bottom: 14px;
  max-width: 310px;
  padding: 8px 10px;
  color: #39443d;
  font-size: 11px;
  line-height: 1.35;
  background: rgba(255,255,255,.9);
  border: 1px solid rgba(211,218,209,.9);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}

.photo-marker {
  display: grid;
  width: 30px !important;
  height: 30px !important;
  place-items: center;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  background: var(--ink);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(14, 25, 18, .25);
}
.photo-marker::before { content: ''; width: 10px; height: 7px; border: 1.5px solid white; border-radius: 2px; }
.photo-marker span { position: absolute; right: -5px; top: -5px; display: grid; min-width: 16px; height: 16px; place-items: center; padding: 0 3px; color: var(--ink); font-size: 8px; background: #fff; border: 1px solid #d8ddd5; border-radius: 9px; }
.profile-position { width: 12px; height: 12px; background: #fff; border: 3px solid var(--accent); border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.3); }

.photo-drawer {
  position: absolute;
  z-index: 700;
  top: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  width: min(350px, calc(100% - 20px));
  min-height: 0;
  flex-direction: column;
  background: rgba(251,252,248,.97);
  border: 1px solid rgba(210,217,208,.95);
  border-radius: 12px;
  box-shadow: 0 16px 42px rgba(18, 30, 23, .18);
  backdrop-filter: blur(12px);
  transform: translateX(calc(100% + 24px));
  transition: transform .22s ease;
}
.photo-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; min-height: 55px; align-items: center; justify-content: space-between; padding: 9px 10px 9px 13px; border-bottom: 1px solid var(--line); }
.drawer-head strong { display: block; margin-top: 2px; font-size: 14px; }
.photo-grid { display: grid; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: max-content; align-content: start; gap: 5px; overflow: auto; padding: 6px; }
.photo-tile { position: relative; aspect-ratio: 4 / 3; overflow: hidden; padding: 0; background: #dfe4dc; border: 0; border-radius: 7px; cursor: zoom-in; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; transition: transform .2s ease; }
.photo-tile:hover img { transform: scale(1.025); }
.photo-tile span { position: absolute; inset: auto 0 0; overflow: hidden; padding: 18px 7px 6px; color: white; font-size: 9px; font-weight: 600; text-align: left; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; background: linear-gradient(transparent, rgba(7,15,10,.78)); }
.photo-empty { grid-column: 1 / -1; align-self: center; padding: 20px; color: var(--muted); font-size: 12px; text-align: center; }

.profile-panel { position: relative; z-index: 800; min-width: 0; overflow: hidden; padding: 8px 16px 8px; background: var(--panel); border-top: 1px solid var(--line); }
.profile-head { display: flex; height: 31px; align-items: center; justify-content: space-between; }
.profile-head strong { margin-left: 8px; font-size: 11px; }
.grade-key { display: flex; gap: 11px; color: var(--muted); font-size: 9px; }
.grade-key span { display: flex; align-items: center; gap: 4px; }
.grade-key i { width: 12px; height: 3px; border-radius: 3px; }
.grade-key .easy { background: var(--green); }
.grade-key .medium { background: var(--amber); }
.grade-key .hard { background: var(--red); }
#profile { display: block; width: 100%; height: calc(100% - 31px); overflow: visible; touch-action: none; }
.profile-grid { stroke: #e2e6df; stroke-width: 1; }
.profile-label-svg { fill: #7c867f; font-size: 9px; }
.profile-cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 3; opacity: .65; }

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  color: white;
  background: rgba(9, 13, 11, .96);
  border: 0;
}
.lightbox::backdrop { background: rgba(9,13,11,.85); }
.lightbox[open] { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; align-items: stretch; }
.lightbox figure { display: grid; min-width: 0; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; margin: 0; padding: 30px 0 18px; }
.lightbox img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.lightbox figcaption { display: flex; justify-content: space-between; gap: 30px; padding-top: 12px; color: #dfe4df; font-size: 12px; }
.lightbox-close { position: fixed; z-index: 3; top: 14px; right: 14px; display: grid; width: 38px; height: 38px; place-items: center; color: white; font-size: 25px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: 50%; cursor: pointer; }
.lightbox-nav { color: white; font-size: 38px; background: transparent; border: 0; cursor: pointer; }

@media (max-width: 880px) {
  .metrics .metric:nth-child(n+3) { display: none; }
  .route-heading { min-width: 180px; }
}

@media (max-width: 720px) {
  .app { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(290px, 88vw); box-shadow: 18px 0 50px rgba(17,28,21,.22); transform: translateX(-105%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .workspace { width: 100%; height: 100dvh; grid-template-rows: 54px minmax(0, 1fr) 132px; }
  .mobile-only { display: grid; }
  .topbar { gap: 9px; padding: 7px 8px; }
  .route-heading { min-width: 0; flex: 1; }
  .route-heading h1 { font-size: 14px; }
  .metrics { display: none; }
  .top-actions .compact-button:last-child { display: none; }
  .profile-panel { padding-inline: 9px; }
  .grade-key { display: none; }
  .map-note { right: 10px; bottom: 10px; left: 10px; max-width: none; }
  .photo-drawer { inset: 8px; width: auto; }
  .lightbox[open] { grid-template-columns: 42px minmax(0, 1fr) 42px; }
  .lightbox figure { padding-top: 52px; }
  .lightbox figcaption { padding-inline: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
