/* TarApp — prototyp PWA. Mobile-first, bez frameworków. */

:root {
  --bg: #f7f4f0;
  --surface: #ffffff;
  --surface-2: #f2ede7;
  --text: #1c1917;
  --text-dim: #6f665f;
  --line: #e3dcd3;
  --accent: #b3450f;
  --accent-soft: #fdeee5;
  --shadow: 0 -8px 32px rgba(28, 25, 23, .16);
  --radius: 16px;
  --topbar-h: 60px;
  --chips-h: 46px;
  --sheet-peek: 92px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #201f24;
    --surface-2: #2a292f;
    --text: #f2efec;
    --text-dim: #a49d97;
    --line: #35333a;
    --accent: #f07a3c;
    --accent-soft: #3a2317;
    --shadow: 0 -8px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- topbar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}

.brand { display: flex; align-items: center; gap: 8px; flex: none; }

.brand__mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: 14px; }
.brand__text small { font-size: 11px; color: var(--text-dim); }

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid transparent;
}
.search:focus-within { border-color: var(--accent); }
.search__icon { color: var(--text-dim); font-size: 17px; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  outline: none;
}
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

/* ---------- category chips ---------- */

.chips {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  left: 0; right: 0;
  height: var(--chips-h);
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(var(--bg) 60%, transparent);
  z-index: 999;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- map ---------- */

#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: var(--surface-2);
}

.leaflet-control-container .leaflet-top { margin-top: calc(var(--topbar-h) + var(--chips-h) + 8px); }
.leaflet-control-attribution { font-size: 10px; }

.pin {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  font-size: 15px;
  transition: transform .15s ease;
}
.pin > span { transform: rotate(45deg); }
.pin.is-selected { transform: rotate(-45deg) scale(1.25); z-index: 500 !important; }
.pin.is-routed { border-color: #facc15; box-shadow: 0 0 0 3px rgba(250,204,21,.5); }

.pin__order {
  position: absolute;
  top: -8px; right: -8px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #facc15;
  color: #111;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  transform: rotate(45deg);
}

.me {
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(37,99,235,.5), 0 2px 8px rgba(0,0,0,.3);
}

/* ---------- floating buttons ---------- */

.fabs {
  position: fixed;
  right: 12px;
  bottom: calc(var(--sheet-peek) + var(--safe-b) + 12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 900;
  transition: bottom .25s ease;
}

.fab {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 19px;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.fab--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.fab.is-live { animation: pulse 1.6s infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(0,0,0,.18); }
  50% { box-shadow: 0 4px 14px rgba(0,0,0,.18), 0 0 0 6px rgba(37,99,235,.25); }
}

/* ---------- bottom sheet ---------- */

.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 950;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  transition: height .25s cubic-bezier(.4,0,.2,1);
  padding-bottom: var(--safe-b);
  --sheet-max: calc(100dvh - var(--topbar-h) - var(--chips-h) - env(safe-area-inset-top, 0px) - 8px);
  max-height: var(--sheet-max);
}

.sheet--peek { height: calc(var(--sheet-peek) + var(--safe-b)); }
.sheet--half { height: 52dvh; }
.sheet--full { height: var(--sheet-max); }

.sheet__handle {
  flex: none;
  border: 0;
  background: none;
  padding: 8px 16px 6px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.grip {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  align-self: center;
}

.sheet__summary {
  font-size: 13px;
  color: var(--text-dim);
}
.sheet__summary b { color: var(--text); }

.tabs {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  background: none;
  padding: 8px 10px 10px;
  font-size: 14px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab.is-active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

.badge {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.sheet__body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.pane { padding: 8px 12px 24px; }

/* ---------- place cards ---------- */

.card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  margin-bottom: 8px;
}
.card:active { background: var(--surface-2); }
.card.is-nearest { border-color: var(--accent); background: var(--accent-soft); }

.card__thumb {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: var(--surface-2);
}

.card__main { flex: 1; min-width: 0; }
.card__title {
  font-weight: 600;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card__title .order {
  flex: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.card__sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.card__meta span {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
}
.card__meta .dist { background: var(--accent); color: #fff; font-weight: 600; }

.card__add {
  flex: none;
  align-self: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 17px;
  display: grid;
  place-items: center;
}
.card__add.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- detail ---------- */

.detail__hero {
  height: 120px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 52px;
  margin-bottom: 12px;
  background: var(--surface-2);
}

.detail__back {
  border: 0;
  background: none;
  padding: 4px 0 8px;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
}

.detail h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
.detail__short { margin: 0 0 12px; color: var(--text-dim); font-size: 13.5px; }
.detail p { font-size: 14px; }

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}
.fact {
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-2);
}
.fact dt { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.fact dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; }

.actions { display: flex; gap: 8px; margin-bottom: 14px; }

.btn {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
}
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--ghost { background: var(--surface-2); }
.btn--block { width: 100%; margin-bottom: 4px; }

.tips { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--text-dim); }
.tips li { margin-bottom: 4px; }

.section-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin: 14px 0 6px;
}

/* ---------- route ---------- */

.route-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.route-summary .fact { flex: 1; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
}
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.leg {
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 0 6px 34px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--topbar-h) + var(--chips-h) + env(safe-area-inset-top, 0px) + 6px);
  z-index: 1200;
  max-width: 88vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(24, 22, 20, .93);
  color: #fff;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

/* ---------- desktop ---------- */

@media (min-width: 860px) {
  :root { --sheet-peek: 92px; }
  .sheet {
    left: 12px;
    right: auto;
    bottom: 12px;
    width: 400px;
    border-radius: var(--radius);
    max-height: calc(100vh - var(--topbar-h) - var(--chips-h) - 36px);
  }
  .sheet--peek { height: auto; }
  .sheet--half { height: 460px; }
  .sheet--full { height: calc(100vh - var(--topbar-h) - var(--chips-h) - 36px); }
  .chips { left: 424px; }
  .fabs { bottom: 24px; }
  .toast { left: auto; right: 12px; transform: none; }
}
