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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* Mapa je plne plátno aplikace, vsechno ostatni na ni lezi. */
.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: relative;
  z-index: var(--z-map-ui);
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  gap: var(--space-2);
  height: calc(var(--topbar-height) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space-2) + var(--safe-right)) 0 calc(var(--space-2) + var(--safe-left));
  background: var(--forest-800);
  color: var(--text-inverse);
  box-shadow: var(--shadow-1);
}

.topbar-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.2;
}

.topbar-title strong {
  font-size: 1.02rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title span {
  font-size: 0.76rem;
  color: rgba(246, 248, 246, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ------------------------------------------------------------------ mapa */

.map-region {
  position: relative;
  min-height: 0;
}

.map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}

.map.is-drawing {
  cursor: crosshair;
}

.map-overlay {
  position: absolute;
  z-index: var(--z-map-ui);
  pointer-events: none;
}

.map-overlay > * {
  pointer-events: auto;
}

.stat-strip {
  top: var(--space-2);
  left: calc(var(--space-2) + var(--safe-left));
  right: calc(var(--space-2) + var(--safe-right));
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.stat-strip::-webkit-scrollbar {
  display: none;
}

.banner-slot {
  top: calc(var(--space-2) + 58px);
  left: calc(var(--space-2) + var(--safe-left));
  right: calc(var(--space-2) + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ----------------------------------------------------------------- sheet */

/*
  Spodni panel ma tri polohy. Vyska se ridi promennou --sheet-height,
  kterou nastavuje JS pri tazeni, takze prechod mezi polohami je plynuly.
*/
.sheet {
  position: absolute;
  z-index: var(--z-sheet);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: var(--sheet-height, 42vh);
  max-height: calc(100% - var(--space-4));
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-3);
  transition: height 220ms cubic-bezier(0.2, 0, 0, 1);
  padding-bottom: var(--safe-bottom);
}

.sheet.is-dragging {
  transition: none;
}

/*
  Vysku slozeneho panelu urcuje JS z realne vysky uchytu a pasu zalozek,
  aby zalozky zustaly nad systemovym gestem telefonu. Natvrdo psana
  hodnota tu drive tuhle logiku prebijela.
*/

.sheet-grip {
  flex: none;
  display: grid;
  place-items: center;
  height: 28px;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}

.sheet-grip::before {
  content: "";
  width: 44px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
}

.sheet-tabs {
  flex: none;
  display: flex;
  gap: var(--space-1);
  padding: 0 var(--space-3) var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.sheet-tabs::-webkit-scrollbar {
  display: none;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 var(--space-4) var(--space-5);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

/* ---------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  z-index: var(--z-drawer);
  top: 0;
  bottom: 0;
  left: 0;
  width: min(88vw, 360px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform: translateX(-100%);
  transition: transform 240ms cubic-bezier(0.2, 0, 0, 1);
  padding-bottom: var(--safe-bottom);
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-head {
  flex: none;
  padding: calc(var(--space-4) + var(--safe-top)) var(--space-4) var(--space-4);
  background: var(--forest-800);
  color: var(--text-inverse);
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3) var(--space-3) var(--space-6);
}

.drawer-section {
  margin-bottom: var(--space-5);
}

.drawer-section > h3 {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-2);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-drawer) - 1);
  background: rgba(9, 18, 13, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms;
}

.scrim.is-open {
  opacity: 1;
  visibility: visible;
}

/* ------------------------------------------------------------------- FAB */

.fab-stack {
  position: absolute;
  z-index: var(--z-fab);
  right: calc(var(--space-4) + var(--safe-right));
  bottom: calc(var(--sheet-height, 42vh) + var(--space-4));
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--space-2);
  transition: bottom 220ms cubic-bezier(0.2, 0, 0, 1);
}

.fab-actions {
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--space-2);
}

.fab-actions[hidden] {
  display: none;
}

/* --------------------------------------------------------------- modaly */

.modal-host {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(9, 18, 13, 0.6);
}

.modal-host[hidden] {
  display: none;
}

.modal {
  width: min(100%, 460px);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

.modal-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  flex: 1;
  margin: 0;
  font-size: 1.08rem;
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
}

.modal-foot {
  flex: none;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 1px solid var(--border);
}

.modal-foot > * {
  flex: 1;
}

/* ---------------------------------------------------------------- toast */

.toast-host {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(var(--space-6) + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(92vw, 420px);
  pointer-events: none;
}

/* --------------------------------------------------- vetsi obrazovky ---- */

@media (min-width: 900px) {
  .app {
    grid-template-columns: 380px 1fr;
    grid-template-rows: auto 1fr;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  /*
    Radky prirazujeme vyslovne. Bez toho by automaticke rozmisteni dalo
    mape a panelu kazdemu vlastni radek, protoze map-region je v HTML driv
    nez sheet, a mapa by pak sloupec nevyplnila.
  */
  .sheet {
    position: relative;
    grid-column: 1;
    grid-row: 2;
    height: auto;
    min-height: 0;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    border-right: 1px solid var(--border);
  }

  .sheet[data-snap="closed"] {
    height: auto;
  }

  .sheet-grip {
    display: none;
  }

  .sheet-tabs {
    padding-top: var(--space-3);
  }

  .map-region {
    grid-column: 2;
    grid-row: 2;
  }

  .fab-stack {
    bottom: calc(var(--space-5) + var(--safe-bottom));
  }
}
