:root {
  --bg: #0e1216;
  --panel: #151a20;
  --card: #1d242d;
  --card-hover: #242d38;
  --line: #2a333f;
  --txt: #e9edf2;
  --muted: #8b97a6;
  --orange: #fc5200; /* aktualny brand orange Stravy */
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: "Barlow", system-ui, sans-serif; background: var(--bg); color: var(--txt); }

#app { display: flex; height: 100%; }
#main { flex: 1; position: relative; }
#map { position: absolute; inset: 0; background: #0e1216; }
#week-view {
  /* z-index ponad kontrolkami Leaflet (zoom = 1000), by ich nie było widać */
  position: absolute; inset: 0; z-index: 1100;
  background: var(--bg); overflow: auto; padding: 14px;
}

#panel {
  width: 390px;
  padding: 16px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

header h1 {
  font-family: "Barlow Condensed", sans-serif;
  font-style: italic;
  font-weight: 800;
  font-size: 34px;
  letter-spacing: 1px;
  margin: 0;
  text-transform: uppercase;
}
header h1 span { color: var(--orange); }
header h1 .logo { height: 17px; margin: 0 8px; vertical-align: -1px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

button {
  font-family: "Barlow Condensed", sans-serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 10px 14px;
  border: none;
  border-radius: 4px;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
}
button:hover { filter: brightness(1.12); }
/* oficjalny przycisk Connect with Strava — brand guidelines zabraniają modyfikacji */
button.strava-img { background: none; padding: 0; border: 0; align-self: flex-start; }
button.strava-img img { display: block; height: 48px; }
button.strava-img:hover { filter: brightness(1.08); }

.pwrd-by { height: 20px; align-self: flex-start; margin-top: 2px; }
button.secondary { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
button.link {
  background: none; color: var(--muted); padding: 0 4px; border: 0;
  text-decoration: underline; font-size: 12px; text-transform: none; letter-spacing: 0;
}

#logged-in { font-size: 14px; }

#controls { display: flex; flex-direction: column; gap: 12px; }

.btn-row { display: flex; gap: 8px; }
.btn-row #btn-search { flex: 1; }

.group {
  display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.group-title {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 13px; font-weight: 600;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--orange);
}

.foot-row { display: flex; justify-content: space-between; align-items: center; }

/* podwójny suwak długości segmentu: dwa nałożone range'y, klikalne są tylko uchwyty */
.dual-range { position: relative; height: 20px; }
.dual-range input[type=range] {
  position: absolute; inset: 0; width: 100%; height: 20px; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: none; pointer-events: none;
}
.dual-range input[type=range]::-webkit-slider-runnable-track {
  height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px;
}
.dual-range input[type=range]::-moz-range-track {
  height: 4px; background: var(--line); border-radius: 2px;
}
.dual-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--orange); border: none; margin-top: -5px;
}
.dual-range input[type=range]::-moz-range-thumb {
  pointer-events: auto;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--orange); border: none;
}

details.adv summary { cursor: pointer; user-select: none; }
details.adv summary::marker { color: var(--muted); }
.adv-select {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 4px;
  padding: 5px 6px;
  font-size: 13px;
  max-width: 60%;
}
#controls label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
#controls strong { color: var(--txt); }

input[type=range] { width: 100%; accent-color: var(--orange); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.speed-wrap { font-size: 13px; color: var(--muted); white-space: nowrap; }
#speed-input {
  width: 56px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 4px;
  padding: 5px 6px;
  font-size: 14px;
  text-align: right;
}

#route-select {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 4px;
  padding: 7px 8px;
  font-size: 13px;
  width: 100%;
}
#route-summary {
  font-size: 13px;
  background: var(--card);
  border-radius: 4px;
  padding: 7px 10px;
}

.chk { user-select: none; cursor: pointer; }
.chk input { accent-color: var(--orange); }

#wind-now {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  background: var(--card); border-radius: 4px; padding: 7px 10px;
}
#wind-arrow { display: inline-block; font-size: 18px; color: #5ec8f0; }

#status { font-size: 13px; color: var(--muted); min-height: 18px; }
#status.error { color: #ff6b5e; }

#segment-list { list-style: none; margin: 0; padding: 0; }
#segment-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  margin-bottom: 7px;
  border-radius: 5px;
  background: var(--card);
  border-left: 5px solid #888;
  cursor: pointer;
  font-size: 13px;
}
#segment-list li:hover { background: var(--card-hover); }
#segment-list li .name { font-weight: 600; display: block; font-size: 14px; }
#segment-list li .meta { color: var(--muted); font-size: 12px; }
#segment-list li .li-score {
  text-align: right;
  font-family: "Barlow Condensed", sans-serif;
  white-space: nowrap;
}
#segment-list li .li-score b { font-size: 21px; font-style: italic; }
#segment-list li .li-score small { color: var(--muted); margin-left: 3px; }
#segment-list li .watts { display: block; font-size: 12px; color: var(--muted); }

#wind-canvas { pointer-events: none; }

/* legenda kolorów jako nakładka na mapie (dolny-lewy róg) */
#map-legend {
  position: absolute; left: 10px; bottom: 14px; z-index: 600;
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(14, 18, 22, .82); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; width: 190px; backdrop-filter: blur(2px);
}

.legend { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 8px; }
.scale .bar { height: 8px; border-radius: 4px; }
.scale .seg-bar {
  background: linear-gradient(90deg, hsl(0,75%,50%), hsl(60,75%,48%), hsl(120,75%,45%));
}
.scale .wind-bar {
  background: linear-gradient(90deg, hsla(200,70%,65%,.15), hsla(180,90%,80%,.6), hsla(160,100%,92%,.95));
}
.scale .ticks {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin-top: 3px;
}

/* modale (Aim Segment, O nas) */
#aim-modal, #about-modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(5, 8, 11, .75);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  width: min(620px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-close {
  position: absolute; top: 8px; right: 10px;
  background: none; color: var(--muted); font-size: 22px; padding: 2px 8px;
}
.modal-card h2 {
  font-family: "Barlow Condensed", sans-serif;
  font-style: italic; text-transform: uppercase;
  margin: 0; padding-right: 30px; font-size: 24px;
}
.modal-card h2 .logo { height: 17px; margin-right: 8px; vertical-align: -1px; }
.modal-card h2 .orange { color: var(--orange); }

#about-content { font-size: 13.5px; line-height: 1.55; }
#about-content p { margin: 0 0 8px; }
#about-content ul { margin: 0 0 8px; padding-left: 18px; }
#about-content li { margin-bottom: 7px; }
#about-content b { color: var(--orange); }
#about-content .tip-meta { color: var(--muted); font-size: 12px; }
#aim-stats, #aim-pr { font-size: 13px; }
#aim-now {
  font-size: 13.5px;
  background: var(--card); border-radius: 4px; padding: 7px 10px;
  min-height: 1px;
}
#aim-now:empty { display: none; }
#aim-link a { color: var(--orange); font-size: 13px; }
#aim-best {
  font-size: 15px; font-weight: 600;
  background: var(--card); border-left: 5px solid #0c0;
  border-radius: 4px; padding: 8px 12px;
}
#aim-note { font-size: 12px; color: var(--muted); }
/* heatmapa: etykieta dnia (stała) + 24 elastyczne komórki wypełniające szerokość
   modala — bez rozpychania i z osiowaniem godzin nad komórkami */
.aim-row { display: flex; align-items: center; gap: 2px; margin-bottom: 2px; }
.aim-day {
  width: 34px; flex: none; font-size: 11px; color: var(--muted); text-transform: uppercase;
}
.aim-cell {
  flex: 1 1 0; min-width: 0; height: 18px; border-radius: 2px;
  background: #20262e; cursor: pointer;
}
.aim-cell:hover { outline: 1px solid #fff; }
.aim-hours { display: flex; gap: 2px; margin-left: 34px; font-size: 10px; color: var(--muted); }
.aim-hours span { flex: 1 1 0; min-width: 0; text-align: center; }

.aim-btn {
  background: none; border: 1px solid var(--line); border-radius: 4px;
  padding: 2px 6px; font-size: 13px; flex: none;
}

/* numerowane znaczniki segmentów na mapie */
.seg-deco { background: none; border: none; }
.seg-start {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  color: #fff; font-size: 11px; font-weight: 700;
  border: 1.5px solid rgba(255,255,255,.85);
  box-shadow: 0 0 3px rgba(0,0,0,.6);
}
.seg-end {
  display: block; font-size: 17px; line-height: 16px;
  text-shadow: 0 0 2px rgba(0,0,0,.7);
}
.seg-start.beatable {
  width: 20px; height: 20px; font-size: 12px;
  border-color: #ffd24a;
  box-shadow: 0 0 6px 1px rgba(255,210,74,.9);
}
#segment-list li.beatable { border-left-color: #ffd24a; }
#segment-list li.beatable .li-rank { box-shadow: 0 0 0 2px #ffd24a; }
.rp-order {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: #111; color: #fff; font-size: 12px; font-weight: 700;
  border: 2px solid var(--orange);
}

/* numer rankingu na liście */
.li-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  color: #fff; font-size: 10px; font-weight: 700;
  margin-right: 6px; vertical-align: 1px;
}
.tip-rank {
  display: inline-block; min-width: 15px; padding: 0 4px;
  background: var(--orange); color: #fff; border-radius: 8px;
  font-size: 11px; font-weight: 700; text-align: center;
}

#segment-list li.picked { outline: 2px solid var(--orange); }
.li-actions { display: flex; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.pick-btn {
  background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 2px 7px; font-size: 13px; line-height: 1;
}
.pick-btn.on { background: var(--orange); color: #fff; border-color: var(--orange); }

/* pasek propozycji trasy */
#route-picker {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px;
}
.rp-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
#rp-summary { font-size: 13px; color: var(--txt); }

/* przełącznik widoku Mapa / Tydzień */
#view-tabs { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
#view-tabs button {
  flex: 1; background: var(--card); color: var(--muted);
  border: none; border-radius: 0; padding: 7px 10px;
  font-family: "Barlow Condensed", sans-serif; font-size: 15px; letter-spacing: .5px;
}
#view-tabs button.on { background: var(--orange); color: #fff; }
#view-tabs button:disabled { opacity: .45; cursor: not-allowed; }

/* Mój tydzień — kalendarz w stylu Outlook (dni kolumny, godziny wiersze 2h) */
#week-status { font-size: 13px; color: var(--muted); min-height: 16px; margin-bottom: 8px; }
#week-cal { display: grid; gap: 2px; min-width: 720px; align-items: stretch; }
.wk-corner { background: transparent; }
.wk-day-lbl {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--txt);
  font-family: "Barlow Condensed", sans-serif; font-size: 14px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; padding: 4px 0;
}
.wk-hh {
  display: flex; align-items: flex-start; justify-content: flex-end;
  font-size: 11px; color: var(--muted); padding: 3px 6px 0 0;
}
.wk-cell { background: #161b21; min-height: 46px; display: flex; flex-direction: column; gap: 2px; padding: 2px; }
.wk-tile {
  display: flex; flex-direction: column; line-height: 1.2;
  background: #232c36; color: var(--txt); border-left: 3px solid #3a4654;
  border-radius: 3px; padding: 2px 5px 3px; cursor: pointer; overflow: hidden;
}
.wk-tile.reach { border-left-color: #d8a32a; }
.wk-tile.easy { border-left-color: #ffd24a; box-shadow: inset 0 0 0 1px rgba(255, 210, 74, .4); }
.wk-tile .wk-t-time { font-weight: 700; font-size: 11px; display: flex; align-items: center; gap: 3px; }
.wk-tile .wk-t-name { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-crown.out { filter: grayscale(1) brightness(1.6); opacity: .65; } /* szara korona */
.wk-crown.easy { text-shadow: 0 0 5px rgba(255, 210, 74, .9); }      /* złoto z rozbłyskiem */
.wk-tile:hover { outline: 2px solid #fff; }
#week-legend { margin-top: 10px; }

/* wybór tras dla najlepszego okna startu */
#week-routes { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
#wr-select { background: var(--card); border: 1px solid var(--line); color: var(--txt); border-radius: 4px; padding: 6px 8px; font-size: 13px; max-width: 280px; }
#wr-speed { width: 52px; background: var(--card); border: 1px solid var(--line); color: var(--txt); border-radius: 4px; padding: 5px 6px; font-size: 13px; text-align: right; }
#wr-list { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.wr-chip { display: flex; align-items: center; gap: 6px; background: #15324a; border: 1px solid #2b6aa0; border-radius: 14px; padding: 3px 6px 3px 10px; font-size: 12px; }
.wr-chip button { background: none; border: none; color: var(--muted); font-size: 14px; padding: 0 2px; cursor: pointer; }
/* pasek trasy w kalendarzu (nakładka na kratki, rozciągnięty przez bloki 2h) */
.wk-route {
  z-index: 2; align-self: stretch; margin: 1px;
  background: rgba(43, 106, 160, .9); border-left: 3px solid #5ec8f0; border-radius: 3px;
  color: #eaf4fb; font-size: 11px; line-height: 1.2; padding: 3px 5px; cursor: pointer; overflow: hidden;
}
.wk-route .wk-r-name { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-route:hover { outline: 2px solid #fff; }

/* dymek po najechaniu na segment */
.seg-tip {
  background: var(--card);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: "Barlow", sans-serif;
  font-size: 13px;
  line-height: 1.45;
  padding: 7px 10px;
  box-shadow: 0 3px 14px rgba(0,0,0,.5);
}
.seg-tip:before { border-top-color: var(--line); }
.seg-tip .tip-meta { color: var(--muted); font-size: 12px; }

/* popupy Leaflet w ciemnym stylu */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--card); color: var(--txt);
}
.leaflet-popup-content a { color: var(--orange); }
.popup-kom { color: #ffd24a; }
.popup-kom.muted { color: var(--muted); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

@media (max-width: 700px) {
  #app { flex-direction: column; }
  #panel { width: 100%; max-height: 48%; }
}
