:root {
  --river: #0b5d6b;
  --river-2: #127f91;
  --river-soft: #e3f1f3;
  --ink: #17252a;
  --muted: #5d6f75;
  --line: #d9e3e5;
  --bg: #f6f8f8;
  --card: #ffffff;
  --warn: #d0621f;
  --warn-soft: #fdf0e6;
  --camp: #2f8a4c;
  --camp-soft: #e6f4ea;
  --shop: #6b5bb5;
  --radius: 14px;
  --top: 56px;
  --shadow: 0 6px 24px rgba(10, 40, 48, 0.16);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
a { color: var(--river-2); }
button, input { font: inherit; color: inherit; }
h1, h2 { margin: 0 0 6px; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }

#app { position: fixed; inset: 0; }

/* ---------- górny pasek ---------- */
.topbar {
  position: absolute; z-index: 1001; top: 0; left: 0; right: 0; height: var(--top);
  display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: var(--river); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .2px; flex: none; }
.brand img { border-radius: 8px; background: #fff; }
.search { position: relative; flex: 1; min-width: 0; }
.search input {
  width: 100%; height: 38px; border: 0; border-radius: 10px; padding: 0 12px;
  background: rgba(255,255,255,.16); color: #fff; outline: none;
}
.search input::placeholder { color: rgba(255,255,255,.75); }
.search input:focus { background: #fff; color: var(--ink); }
.search input:focus::placeholder { color: var(--muted); }
.search-results {
  position: absolute; top: 44px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: #fff; color: var(--ink); border-radius: 12px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto;
}
.search-results li button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.search-results li button:hover, .search-results li button:focus { background: var(--river-soft); }
.icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 10px; border: 0; cursor: pointer;
  background: rgba(255,255,255,.16); display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2; fill: #fff; }
.icon-btn svg path, .icon-btn svg circle[fill="none"] { fill: none; }

/* ---------- mapa ---------- */
#map { position: absolute; top: var(--top); left: 0; right: 0; bottom: 0; background: #dfe9ea; }
.leaflet-container { font: inherit; }
.leaflet-container.adding { cursor: crosshair; }
.mode-pill {
  position: absolute; z-index: 1000; top: calc(var(--top) + 10px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
  pointer-events: none; white-space: nowrap; max-width: calc(100% - 100px); overflow: hidden; text-overflow: ellipsis;
}

/* znaczniki */
.mk { display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; font-size: 12px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.mk-way { background: var(--river); width: 26px; height: 26px; }
.mk-start { background: #1f9d55; width: 30px; height: 30px; font-size: 13px; }
.mk-end { background: #111; width: 30px; height: 30px; font-size: 14px; }
.mk-night { background: #fff; color: var(--river); border: 3px solid var(--river); width: 30px; height: 30px; font-size: 13px; cursor: grab; }
.leaflet-drag-target .mk-night, .mk-night:active { cursor: grabbing; transform: scale(1.15); box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.mk-obstacle { background: var(--warn); width: 22px; height: 22px; border-radius: 5px; transform: rotate(45deg); }
.mk-obstacle b { transform: rotate(-45deg); }
.mk-soft { background: #e0a23a; }
.mk-camp { background: var(--camp); width: 22px; height: 22px; font-size: 12px; }
.mk-putin { background: var(--river-2); width: 20px; height: 20px; font-size: 11px; }
.mk-shop { background: var(--shop); width: 18px; height: 18px; font-size: 10px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.leaflet-popup-content .pop-title { font-weight: 700; margin-bottom: 2px; }
.leaflet-popup-content .pop-meta { color: var(--muted); font-size: 13px; }
.leaflet-popup-content .pop-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- panel (telefon: wysuwany od dołu) ---------- */
.panel {
  position: absolute; z-index: 1000; left: 0; right: 0; bottom: 0;
  height: var(--sheet-h, 190px);
  background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(10,40,48,.18);
  display: flex; flex-direction: column; transition: height .22s ease;
  padding-bottom: var(--safe-b);
}
.panel.dragging { transition: none; }
.panel[data-state="peek"] { --sheet-h: 190px; }
.panel[data-state="half"] { --sheet-h: 56%; }
.panel[data-state="full"] { --sheet-h: calc(100% - var(--top) - 8px); }
.sheet-handle { flex: none; height: 26px; border: 0; background: none; cursor: grab; display: grid; place-items: center; touch-action: none; }
.sheet-handle span { width: 44px; height: 5px; border-radius: 3px; background: #b9c7ca; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 0 12px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card.compact { padding: 10px 14px; }
.intro p { margin: 4px 0 8px; color: var(--muted); }
.examples { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.examples #examples { display: flex; gap: 6px; flex-wrap: wrap; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.status { color: var(--muted); font-size: 13px; text-align: right; }
.status.busy::before { content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 6px; vertical-align: -1px; border: 2px solid var(--river-2); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.summary { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 8px; }
.summary .stat { display: flex; flex-direction: column; }
.summary .stat b { font-size: 20px; line-height: 1.1; color: var(--river); }
.summary .stat span { font-size: 12px; color: var(--muted); }
.summary .empty { color: var(--muted); }
.warning { background: var(--warn-soft); color: #7a3510; border-radius: 10px; padding: 8px 10px; font-size: 14px; margin-bottom: 8px; }
.error { background: #fdeaea; color: #8a1f1f; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer;
  font-size: 14px; min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: #b4c6c9; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--river); border-color: var(--river); color: #fff; }
.btn.toggle[aria-pressed="true"] { background: var(--river-soft); border-color: var(--river-2); color: var(--river); font-weight: 600; }
.btn.danger { color: #a33; }
.btn.link { border: 0; background: none; color: var(--river-2); padding: 4px 2px; min-height: 0; text-decoration: underline; }

.seg { display: flex; background: var(--river-soft); border-radius: 10px; padding: 3px; margin: 4px 0 10px; }
.seg label { flex: 1; text-align: center; padding: 7px 6px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: #fff; color: var(--river); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input { height: 38px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; border-radius: 0; border-left: 0; border-right: 0; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper button { width: 40px; flex: none; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 18px; color: var(--river); }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; font-size: 14px; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--river); }
.more { margin-top: 8px; }
.more summary { cursor: pointer; color: var(--river-2); font-size: 14px; padding: 4px 0; }
.more .grid { margin-top: 6px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 13px; background: #fff; cursor: pointer; }
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed="false"] { opacity: .5; }

/* wybór rzeki */
.river-form { margin: 6px 0 4px; }
.river-form label { display: block; font-size: 14px; margin-bottom: 4px; }
.river-form .row input { flex: 1; min-width: 0; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; font-size: 16px; }
.river-form .row input:focus { outline: 2px solid var(--river-2); outline-offset: 0; }
.river-results { list-style: none; margin: 6px 0 4px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.river-results button { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.river-results button:hover, .river-results button:focus { border-color: var(--river-2); background: var(--river-soft); }
.river-results b { color: var(--river); }
.river-results small { display: block; color: var(--muted); font-size: 12.5px; }
.river-chosen, .river-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--river-soft); color: var(--river); border-radius: 10px; padding: 7px 10px; margin: 6px 0; font-size: 14px; }
.river-line { margin: 2px 0 8px; }
.river-chip { display: inline-flex; align-items: center; gap: 4px; background: #fff; border: 1px solid #b9dbe1; border-radius: 999px; padding: 2px 4px 2px 10px; }
.chip-x { border: 0; background: none; color: var(--muted); font-size: 17px; line-height: 1; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; }
.chip-x:hover { background: var(--river-soft); color: var(--ink); }
#route-card .river-form { margin-top: 4px; }

/* etapy */
.stages { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.stage { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--c, var(--river)); border-radius: var(--radius); padding: 10px 12px; }
.stage-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stage-head h3 { margin: 0; font-size: 15px; }
.stage-head .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.stage .places { font-size: 15px; margin: 2px 0 4px; font-weight: 600; }
.stage .nums { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; }
.stage .nums b { color: var(--river); }
.stage .breakdown { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stage ul { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13.5px; }
.stage li { display: flex; gap: 8px; padding: 3px 0; border-top: 1px dashed var(--line); }
.stage li:first-child { border-top: 0; }
.stage li .km { color: var(--muted); min-width: 54px; font-variant-numeric: tabular-nums; }
.stage li.ob .what { color: var(--warn); font-weight: 600; }
.stage li.soft .what { color: #a7701c; }
.stage .night { margin-top: 8px; padding: 7px 9px; border-radius: 10px; background: var(--camp-soft); color: #1d5a31; font-size: 13.5px; }
.stage .night.none { background: var(--warn-soft); color: #7a3510; }
.stage .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.stage .actions .shift { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 13px; }

.foot { color: var(--muted); font-size: 12.5px; padding: 4px 4px 12px; }
.foot p { margin: 6px 0; }

.toast {
  position: absolute; z-index: 1100; left: 50%; top: calc(var(--top) + 54px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px;
  max-width: calc(100% - 24px); text-align: center;
}

[hidden] { display: none !important; }

/* ---------- komputer: panel z boku ---------- */
@media (min-width: 900px) {
  .panel {
    top: var(--top); bottom: 0; left: 0; right: auto; width: 410px; height: auto;
    border-radius: 0; box-shadow: 2px 0 14px rgba(10,40,48,.12); padding-top: 12px; transition: none;
  }
  .panel[data-state] { --sheet-h: auto; }
  .sheet-handle { display: none; }
  #map { left: 410px; }
  .mode-pill { left: calc(50% + 205px); }
  .toast { left: calc(50% + 205px); top: auto; bottom: 24px; }
  .topbar { gap: 16px; padding: 0 16px; }
  .search { max-width: 460px; }
}
