:root {
  /* Yungo palette, extracted from their own site (w:\INNOVATION\webpage\sample-html\
     example-yungo-main-page.html): cyan is the brand/accent color, but their own
     primary buttons are red-on-light, not cyan-on-light — kept as two separate
     tokens so buttons and accents (active tab, sort arrow, badges) can differ
     exactly as Yungo's own does. */
  --bg: #fafafb;
  --panel: #ffffff;
  --border: #d8dce2;
  --text: #1d133c;
  --muted: #667085;
  --accent: #0fb8d8;
  --brand-red: #da492b;
  --trench: #da492b;
}

* { box-sizing: border-box; }

/* An author `display` rule beats the UA stylesheet's `[hidden] { display: none }`,
   so any element given `display: flex` here would ignore its hidden attribute —
   which is exactly how both search panels ended up visible at once. Settle it once
   for every element rather than remembering per rule. */
[hidden] { display: none !important; }

body {
  margin: 0;
  /* Yungo's own site uses "Switzer Variable" loaded from their CDN. Loading a font
     cross-origin from someone else's CDN is fragile (no SRI, URL can change without
     notice) so this app falls back to Inter/system fonts instead of pointing at it -
     vendor the .ttf files locally (same pattern as frontend/vendor/leaflet.*) if
     Switzer itself is ever supplied. */
  font: 14px/1.5 "Switzer Variable", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  /* .controls stacks each label above its input (two lines); everything else in
     the header is single-line. `center` aligns items by their own midpoint, which
     put the Rok/Buffer inputs visibly lower than Spočítat/Vymazat/the badge -
     `flex-end` bottom-aligns every item instead, matching the rule .controls
     already uses for its own children (label-above-input toolbars are bottom-
     aligned by convention, so both levels should agree). */
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

/* header's own align-items:flex-end bottom-aligns every direct child to the same
   line - correct for the buttons/tabs (33px: 21px line-height + 12px padding), but
   the logo (22px), title (24px) and badge (22px) are shorter, so bottom-aligning
   them too puts their *centre* noticeably above the buttons' centre (their empty
   space collects entirely above them, since they have none below). Centring them
   instead overshoots the other way, using the *row's* full height (51px, set by
   the Rok/Buffer block) rather than the buttons' own 33px band within it.
   The fix is arithmetic, not a named alignment mode: nudge each one down by
   margin-bottom so its own centreline lands on the buttons' centreline
   (row height 51px, buttons span the bottom 33px of it => buttons' centre sits
   9px above the row's own centre). These numbers track the header's current
   font-sizes and paddings above; recompute if those change. */
header h1 { font-size: 16px; margin: 0 0 4.5px; font-weight: 600; }

.logo { display: flex; align-items: center; flex-shrink: 0; margin-bottom: 5.5px; }
.logo svg { height: 22px; width: auto; display: block; }

/* Pushes the testing badge and interest button to the right edge of the header,
   without disturbing the tabs/controls that come before and after it in source
   order (the header is one flex row with wrap, not a grid). */
.header-spacer { flex: 1; min-width: 8px; }

.testing-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #fff;
  background: var(--brand-red);
  border-radius: 4px;
  padding: 3px 8px;
  white-space: nowrap;
  margin-bottom: 5.5px;
}

.controls { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }

.controls label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
}

.controls input, .controls select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: inherit;
}

.controls input { width: 110px; }

button {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  /* Yungo's own primary CTA is red-on-light, not their brand cyan - cyan is kept
     for accents/active-state instead (view-tab active, sort arrow, badge count). */
  background: var(--brand-red);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s;
}

button:hover:not(:disabled):not(.secondary) { background: var(--text); }

button:disabled { opacity: .45; cursor: not-allowed; }

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.file-button { position: relative; cursor: pointer; }

.file-button {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  align-self: flex-end;
}

.file-button:hover { background: #f2f4f7; }

/* ------------------------------------------------------------- views ---- */

.views { display: flex; gap: 4px; }

.view-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.view-tab:hover:not(:disabled) { background: #f2f4f7; }

.view-tab.active {
  background: #eff5ff;
  color: var(--accent);
  border-color: #cfe0ff;
  font-weight: 600;
}

.badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
}

main { flex: 1; display: flex; min-height: 0; }

.view { display: none; flex: 1; min-height: 0; min-width: 0; }
.view.active { display: flex; }
.view[data-view="results"].active { flex-direction: column; }

#map-wrap { flex: 1; min-width: 0; position: relative; }

#map { position: absolute; inset: 0; }

/* ----------------------------------------------------------- search ---- */

#search {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 320px;
  max-width: calc(100% - 20px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .12);
  overflow: hidden;
}

.search-tabs { display: flex; border-bottom: 1px solid var(--border); }

.tab {
  flex: 1;
  background: #f6f7f9;
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 7px 10px;
  font-size: 12px;
}

.tab.active { background: var(--panel); color: var(--text); font-weight: 600; }

.search-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; }

.search-body input {
  font: inherit;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.search-body input:disabled { background: #f6f7f9; color: var(--muted); }

.chosen {
  font-size: 12px;
  color: var(--accent);
  background: #eff5ff;
  border-radius: 4px;
  padding: 3px 6px;
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.results li + li { border-top: 1px solid #eef0f3; }

.results button {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  text-align: left;
  background: none;
  color: inherit;
  border: none;
  border-radius: 0;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.results button:hover,
.results button.active { background: #eff5ff; }

.results button.active { box-shadow: inset 2px 0 0 var(--accent); }

.results .label { color: var(--text); }

.results mark {
  background: #fff3bf;
  color: inherit;
  font-weight: 600;
  border-radius: 2px;
  padding: 0 1px;
}

/* Secondary line: which municipality and district a cadastral area belongs to,
   so identically named ones can be told apart. */
.results .hint-line { color: var(--muted); font-size: 11px; }

.results .empty { padding: 8px 10px; font-size: 12px; color: var(--muted); }

/* Empty when nothing is highlighted; padding-block stays 0 so it collapses away. */
.highlight-note {
  margin: 0;
  padding-inline: 10px;
  font-size: 11px;
  color: #7048e8;
  line-height: 1.4;
}

.highlight-note:has(#highlight-note:not(:empty)) { padding-block: 6px; }

button.link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 0 0 0 4px;
  font-size: 11px;
  cursor: pointer;
}

.scroll-x { overflow-x: auto; }

/* ------------------------------------------------------------ results ---- */

.results-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.results-toolbar .spacer { flex: 1; }

.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; }

.sheet-tab {
  background: #f6f7f9;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 6px 12px;
  font-size: 12px;
}

.sheet-tab.active {
  background: var(--panel);
  color: var(--text);
  border-bottom-color: var(--panel);
  font-weight: 600;
}

/* ------------------------------------------------- bulk edit dialog ---- */

#bulk-dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  max-width: 560px;
  width: calc(100% - 32px);
  box-shadow: 0 10px 40px rgba(16, 24, 40, .2);
  color: var(--text);
}

#bulk-dialog::backdrop { background: rgba(16, 24, 40, .35); }

#bulk-form { padding: 18px 20px 16px; }

#bulk-dialog h3 { margin: 0 0 4px; font-size: 15px; }

.bulk-note { margin: 0 0 14px; font-size: 12px; color: var(--muted); }

.bulk-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
}

.bulk-field {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) minmax(0, 1.3fr);
  align-items: center;
  gap: 8px;
}

.bulk-field label { font-size: 12px; color: var(--text); cursor: pointer; }

.bulk-field input[type="number"], .bulk-field select {
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  min-width: 0;
  width: 100%;
}

/* An unticked field is inert, so an untouched dialog changes nothing. */
.bulk-field input:disabled, .bulk-field select:disabled {
  background: #f6f7f9;
  color: var(--muted);
}

.bulk-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* --------------------------------------------- testing notice / interest --- */

/* Same card chrome as #bulk-dialog (border, radius, shadow, backdrop) - kept as
   separate rules rather than a shared class because each dialog's own <form>
   padding differs slightly and duplicating four lines of CSS per dialog is cheaper
   to read than threading a shared class through three markup blocks. */
#testing-notice, #interest-dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  max-width: 440px;
  width: calc(100% - 32px);
  box-shadow: 0 10px 40px rgba(16, 24, 40, .2);
  color: var(--text);
}

#testing-notice::backdrop, #interest-dialog::backdrop {
  background: rgba(16, 24, 40, .35);
}

#testing-notice form, #interest-dialog form { padding: 20px 22px 18px; }

#testing-notice h3, #interest-dialog h3 { margin: 0 0 10px; font-size: 15px; }

#testing-notice p { margin: 0 0 6px; font-size: 13px; color: var(--muted); line-height: 1.5; }

.interest-email {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 6px;
}

.interest-email input {
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

/* .results-error is shared with the Výsledky view, whose own margin assumes a
   full-width toolbar; flush it back to the form's own rhythm here. */
#interest-dialog .results-error { margin: 6px 0 0; }

.interest-success {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #e7fafd;
  border: 1px solid var(--accent);
  color: #0a7f96;
  font-size: 12px;
}

.downloads { display: flex; gap: 8px; align-items: flex-end; }

.results-body { flex: 1; min-height: 0; overflow: auto; padding: 0 16px 24px; }

.empty-results { padding: 40px 16px; color: var(--muted); text-align: center; }

table.priced { font-size: 12px; white-space: nowrap; width: 100%; }

/* A table cell must keep `display: table-cell`, or it drops out of the column
   grid — that is what knocked the header row out of alignment. The label inside
   it is a span, so it can be clamped freely. */
table.priced thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  box-shadow: inset 0 -1px 0 var(--border);
  vertical-align: bottom;
  padding: 8px 8px 6px 0;
  /* A column is sized by its widest cell. Several hold values like "0,26", which
     would squeeze the header into a one-character-per-line column, so give every
     column room for a word. */
  min-width: 92px;
  max-width: 168px;
}

.th-label {
  display: block;
  /* Wrap between words only. overflow-wrap/hyphens would break mid-word, which is
     what turned "Index komunikace" into a vertical stack of letters. */
  white-space: normal;
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: manual;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

/* "Celé názvy sloupců" swaps in the regulation's own wording, which needs room. */
.expanded-headers table.priced thead th { min-width: 120px; max-width: 210px; }
.expanded-headers .th-label { font-weight: 500; }

/* The widest sheet has 29 columns, so the four identifying columns stay put while
   the rest scrolls: the bulk-edit tick box, Parcela, Číslo and Katastrální území.
   Widths are fixed and named here because each sticky offset is the sum of the
   widths to its left — changing one means changing the next. */
table.priced {
  --w-pick: 32px;
  --w-parcela: 100px;
  --w-cislo: 78px;
  --w-ku: 124px;
}

table.priced th:nth-child(-n + 4),
table.priced tbody td:nth-child(-n + 4),
table.priced tfoot td:nth-child(-n + 4) {
  position: sticky;
  background: var(--panel);
  /* Cells are padded on the right only, so a frozen column would otherwise sit
     flush against the one it covers. */
  padding-left: 10px;
}

table.priced th:nth-child(1),
table.priced tbody td:nth-child(1),
table.priced tfoot td:nth-child(1) {
  left: 0;
  min-width: var(--w-pick);
  max-width: var(--w-pick);
  padding-left: 4px;
}

table.priced th:nth-child(2),
table.priced tbody td:nth-child(2),
table.priced tfoot td:nth-child(2) {
  left: var(--w-pick);
  min-width: var(--w-parcela);
  max-width: var(--w-parcela);
}

table.priced th:nth-child(3),
table.priced tbody td:nth-child(3),
table.priced tfoot td:nth-child(3) {
  left: calc(var(--w-pick) + var(--w-parcela));
  min-width: var(--w-cislo);
  max-width: var(--w-cislo);
}

table.priced th:nth-child(4),
table.priced tbody td:nth-child(4),
table.priced tfoot td:nth-child(4) {
  left: calc(var(--w-pick) + var(--w-parcela) + var(--w-cislo));
  min-width: var(--w-ku);
  max-width: var(--w-ku);
  /* Marks where the frozen block ends and the scrolling one begins. */
  box-shadow: 1px 0 0 var(--border);
}

/* The first scrolling column needs the same breathing room the frozen ones got. */
table.priced th:nth-child(5),
table.priced tbody td:nth-child(5),
table.priced tfoot td:nth-child(5) { padding-left: 12px; }

table.priced thead th:nth-child(-n + 4) { z-index: 3; }
table.priced tbody td:nth-child(-n + 4) { z-index: 1; }

/* A frozen cell is opaque, so the row tint has to be repeated on it. The selector
   has to out-rank the sticky block's own background, hence the extra qualifiers. */
table.priced tbody tr.has-error td:nth-child(-n + 4) { background: #fff8f7; }

/* The error row spans the table; it must not be frozen, sized or clipped by the
   sticky rules above — which are specific enough to need out-ranking here. */
table.priced tbody tr.error-row td {
  position: static;
  min-width: 0;
  max-width: none;
  padding-left: 12px;
  background: transparent;
}

/* ------------------------------------------------- sorting and picking --- */

table.priced thead th.sortable { cursor: pointer; user-select: none; }
table.priced thead th.sortable:hover .th-label { color: var(--accent); }

table.priced thead th.sorted .th-label::after {
  content: ' ▲';
  font-size: 9px;
  color: var(--accent);
}

table.priced thead th.sorted[data-dir="desc"] .th-label::after { content: ' ▼'; }

th.pick, td.pick { text-align: center; }

table.priced input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

#row-filter {
  width: 190px;
  font: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.row-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  align-self: center;
}

.bulk-scope {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
}

.bulk-scope select {
  font: inherit;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.results-error {
  margin: 10px 16px 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff5f4;
  border: 1px solid #f3b9b3;
  color: #b42318;
  font-size: 12px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

td.znak { white-space: normal; }
td.znak select { max-width: 200px; }

td.znak .span-value {
  width: 62px;
  margin-left: 4px;
  text-align: right;
}

input.detail-value { width: 84px; text-align: right; }

/* A base price the source data did not supply: the row cannot price until it is
   filled, so make the empty box obvious rather than looking like a plain zero. */
input.detail-value.missing {
  border-color: #e8590c;
  background: #fff6f0;
}

td.ku { color: var(--muted); font-variant-numeric: tabular-nums; }

table.priced input, table.priced select {
  font: inherit;
  font-size: 12px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fffdf5;
  text-align: right;
}

table.priced input[type="number"] { width: 62px; }
table.priced select { width: 130px; text-align: left; }

table.priced tfoot td {
  font-weight: 600;
  border-top: 2px solid var(--border);
  border-bottom: none;
  padding-top: 7px;
}

tr.has-error td { background: #fff8f7; }

tr.error-row td {
  color: #b42318;
  font-size: 11px;
  white-space: normal;
  padding: 2px 6px 6px 0;
  border-bottom: 1px solid #eef0f3;
}

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

#panel {
  width: 340px;
  flex-shrink: 0;
  padding: 16px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.hint { color: var(--muted); margin-top: 0; }

#status { min-height: 20px; color: var(--muted); }
#status.error { color: #b42318; }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

table.kv { width: 100%; border-collapse: collapse; }

table.kv th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

table.kv td {
  text-align: right;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.obce { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.warning {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff8e6;
  border: 1px solid #f2d98c;
  color: #7a5b00;
  font-size: 12px;
}

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }

table.grid th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 6px 6px 6px 0;
  position: sticky;
  top: 0;
  background: var(--panel);
}

table.grid td {
  padding: 5px 6px 5px 0;
  border-bottom: 1px solid #eef0f3;
  vertical-align: top;
}

table.grid a { color: var(--accent); }

@media (max-width: 820px) {
  main { flex-direction: column; }
  #panel { width: auto; border-left: none; border-top: 1px solid var(--border); }
  #map-wrap { min-height: 55vh; flex: none; }
  #search { width: 260px; }
}

/* ------------------------------------------------------------ progress ---- */

#progress {
  margin: 12px 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

.progress-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

#progress-phase {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text);
  /* Phases name municipalities, which can be long; wrap rather than clip. */
  overflow-wrap: anywhere;
}

.progress-track {
  height: 6px;
  border-radius: 3px;
  background: #e6e9ed;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width .25s ease;
}

/* Steps that cannot say how large they are - a single download, a WFS call -
   get a sliding bar rather than a stuck one. */
.progress-bar.indeterminate {
  width: 35%;
  animation: slide 1.4s ease-in-out infinite;
  transition: none;
}

@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(340%); }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar.indeterminate { animation: none; width: 100%; opacity: .45; }
  .progress-bar { transition: none; }
}

.progress-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

#progress-cancel { flex: none; }
