:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #556070;
  --border: #e3e8f0;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --hover: #f0f4ff;
  --stream-switcher-max: 220px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans",
    "Apple Color Emoji", "Segoe UI Emoji";
}

#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100%;
}

/* ===== SIDEBAR ===== */
#menu {
  border-right: 1px solid var(--border);
  background: #fff;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  scrollbar-width: thin;
}

#menu::-webkit-scrollbar {
  width: 8px;
}

#menu::-webkit-scrollbar-track {
  background: transparent;
}

#menu::-webkit-scrollbar-thumb {
  background: #e5e7eb;
  border-radius: 8px;
}

#menu::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

/* Breadcrumb (město / jednotka + Obnovit) */
.menuTop {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

.menuTop #crumbCity,
.menuTop #crumbUnit {
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

.menuTop .sep {
  color: #cbd5e1;
  font-weight: 400;
}

.menuTop .btn.small {
  margin-left: auto;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;
}

/* === STROM LOKACÍ === */
.tree {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

/* Každé město (root group) */
.tree > li {
  padding: 0;
  margin: 0;
}

.tree .place {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 100ms ease;
}

.tree .place:hover {
  background: var(--hover);
}

/* Ikona město (malá tečka) */
.tree .place::before {
  content: "📍";
  font-size: 13px; /* Zmenšení fontu pro lepší renderování na Windows */
  flex-shrink: 0;
}

/* Seznam jednotek pod městem */
.tree .group {
  list-style: none;
  margin: 6px 0 6px 0;
  padding: 0 0 0 40px;
  display: grid;
  gap: 8px;
  border-left: 2px dotted #e5e7eb;
}

/* Jednotka řádek */
.tree .unit {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 6px;
  cursor: pointer;
  position: relative;
  transition: color 100ms ease;
  border-radius: 6px;
}

.tree .unit:hover {
  color: var(--text);
  background: rgba(37, 99, 235, 0.06);
}

/* Tečka u jednotky (vlevo na lince) */
.tree .unit::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 12px;
  width: 6px;
  height: 6px;
  background: #cbd5e1;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background-color 100ms ease;
}

/* Aktivní zvolená jednotka */
.tree .unit.is-active {
  font-weight: 700;
  color: var(--accent);
}

.tree .unit.is-active::before {
  background: var(--accent);
  width: 8px;
  height: 8px;
  left: -15px;
  top: 11px;
}

/* Inline akce jednotky (pill buttons) */
.options {
  display: flex;
  gap: 8px;
  margin: 6px 0 0 0;
  padding: 0;
  list-style: none;
  flex-wrap: wrap;
}

.options button {
  border: 1px solid #dbe4ff;
  color: #1e3a8a;
  background: #f5f8ff;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 100ms ease;
  white-space: nowrap;
}

.options button:hover {
  background: #eef4ff;
  border-color: #bfdbfe;
  color: #1e40af;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.options button:active {
  transform: scale(0.96);
}

/* Oddělovač měst (pokud jich bude víc) */
.tree > li + li {
  border-top: 1px dashed #e5e7eb;
  padding-top: 8px;
  margin-top: 2px;
}

.buttons button,
.view-buttons button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease, box-shadow 120ms ease;
}

.buttons button:hover,
.view-buttons button:hover {
  background: var(--hover); /* #f0f4ff */
  border-color: #bcd2ff;
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); /* jemný focus ring */
}

#content {
  padding: 16px 20px;
  overflow: auto;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

.dataTable {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
}

.dataTable th,
.dataTable td {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 10px;
}

.dataTable th {
  text-align: left;
  font-weight: 600;
}

.dataTable.center {
  max-width: 520px;
  margin: 0 auto;
}

.right {
  text-align: right;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.filters-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: end;
}

.buttons button,
.view-buttons button {
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.buttons button:hover,
.view-buttons button:hover {
  background: var(--hover);
}

.view-buttons .primary {
  background: var(--accent); /* #2563eb */
  border-color: var(--accent);
  color: #fff; /* KONTRASTNÍ text */
}

.view-buttons .primary:hover {
  background: var(--accent-2); /* #1d4ed8 */
  border-color: var(--accent-2);
  color: #fff;
}

.buttons button:disabled,
.view-buttons button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.filters-row .buttons button {
  border-color: var(--border);
}

.dates {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dates input {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.metrics {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#csvBox {
  width: 100%;
  min-height: 220px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

.muted {
  color: var(--muted);
}

/* Kontejner tabulkového pohledu – max šířka a centrování */
#tableView {
  max-width: 960px;
  margin: 0 auto;
  overflow-x: auto; /* Povolíme horizontální scroll vždy */
  -webkit-overflow-scrolling: touch; /* plynulejší scroll na iOS */
  padding-bottom: 8px; /* Místo pro scrollbar */
}

/* Samotná tabulka – využít 100 % šířky kontejneru */
#tableView .dataTable {
  width: 100%;
  min-width: 700px; /* Vynutíme minimální šířku, aby se zobrazil scrollbar */
  border-spacing: 0 4px;
}

/* Všechny buňky v tabulce nebudou zalamovat text */
#tableView .dataTable th,
#tableView .dataTable td {
  white-space: nowrap;
}

/* Číselné sloupce zarovnat doprava */
#tableView .dataTable th:nth-child(n + 3),
#tableView .dataTable td:nth-child(n + 3) {
  text-align: right;
}

/* Stream switcher inline pod názvem jednotky – zarovnání a zeštíhlení */
.stream-switcher-inline {
  margin: 6px 0 6px 0;
  padding-left: 0; /* srovnáme s textem jednotky */
  width: min(var(--stream-switcher-max), 100%);
}
.stream-switcher-inline .stream-select {
  display: block;
  width: 100%;
  min-width: 0;
  height: 32px; /* štíhlejší */
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 30px 4px 10px; /* menší padding, místo na šipku */
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease,
    background-color 120ms ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' \
stroke='%236a7b8f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>\
<polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px 16px;
}
.stream-switcher-inline .stream-select:hover {
  background-color: var(--hover);
  border-color: #bcd2ff;
}
.stream-switcher-inline .stream-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
/* Když je kurzor nad řádkem jednotky, opticky sjednotíme select */
.tree .unit:hover + .stream-switcher-inline .stream-select {
  background-color: var(--hover);
}

/* Na úzkých displejích ještě zmenšíme max-šířku */

@media (max-width: 1200px) {
  #tableView {
    max-width: 820px;
  }
}

@media (max-width: 980px) {
  #tableView {
    max-width: 720px;
  }
}

/* Střední obrazovky: Zalamování filtrů do 3 řádků */

@media (max-width: 1432px) {
  .filters-row {
    display: flex;
    flex-direction: column; /* Stack all children vertically */
    gap: 16px;
    align-items: center; /* Center the rows horizontally */
  }

  /* Zajistíme, aby se vnitřní prvky každé řady také správně chovaly */

  .filters-row .buttons,
  .filters-row .dates,
  .filters-row .view-buttons,
  .metrics {
    /* Přidáme i pro .metrics */
    display: flex;
    flex-wrap: wrap; /* Umožní zalamování tlačítek, pokud by se nevešly */
    justify-content: center; /* Centruje tlačítka uvnitř jejich kontejneru */
    gap: 8px;
  }
}

/* ===== RESPONZIVITA ===== */

.menu-toggle {
  display: none; /* Skryto na desktopu */
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

@media (max-width: 820px) {
  #app {
    /* Na mobilu se menu zobrazí přes obsah, takže rušíme grid */
    grid-template-columns: 1fr;
  }

  #menu {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    max-width: 85%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 250ms ease-in-out;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.1);
  }

  /* Zobrazí menu po kliknutí na toggle */
  #app.menu-open #menu {
    transform: translateX(0);
  }

  #content {
    padding-top: 52px; /* Místo pro toggle button */
  }

  .menu-toggle {
    display: block; /* Zobrazíme toggle button */
  }

  /* Filtry pod sebe, vycentrované */

  .filters-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center; /* Centruje řádky jako celky */
  }

  .filters-row .buttons,
  .filters-row .dates,
  .filters-row .view-buttons,
  .metrics {
    width: 100%; /* Zajistí, že každý blok zabere celou šířku */
    /* Zbytek flex vlastností se dědí z max-width: 1432px nebo je specifický pro daný element */
  }

  .dates {
    width: 100%; /* Zajistíme, že kontejner datumů zabere plnou šířku */
    display: flex;
    flex-direction: column;
    align-items: center; /* Vycentruje labely uvnitř */
    gap: 12px;
  }

  .dates label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    /* width: 100% je zde již zbytečné, roztahuje ho rodič (.dates) */
  }

  .dates input {
    width: 100%; /* Roztáhne input na 100% šířky labelu */
  }

  /* Tabulka s daty: zrušit omezení a centrování z desktopu */

  #tableView {
    margin: 0;
    max-width: none;
  }

  #tableView .dataTable {
    border-spacing: 0 5px;
    min-width: 0; /* Na mobilu se šířka řídí obsahem */
  }

  #tableView .dataTable th,
  #tableView .dataTable td {
    padding: 9px 12px;
  }
}
