:root {
  --bg: #e8efe6;
  --panel: #f7faf5;
  --ink: #1c2a1f;
  --muted: #5a6b5e;
  --own: #1f6feb;
  --neighbor: #e0a800;
  --sent: #2f9e44;
  --no-box: #9aa0a6;
  --highlight: #e03131;
  --danger: #a33b2f;
  --line: #c5d2c4;
  --accent: #1f5c3a;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 0%, #d9e8d4 0%, transparent 50%),
    linear-gradient(160deg, #eef4ec, #dfe9db 60%, #d2dfd0);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 250, 245, 0.92);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

.modes {
  display: flex;
  gap: 0.35rem;
  flex: 1;
}

.mode {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.mode.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.badge {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: #e2ebe0;
  color: var(--muted);
  white-space: nowrap;
}

.badge.warn { background: #f3e4b5; color: #6a5410; }
.badge.ok { background: #d4ead8; color: #1f5c3a; }

.layout {
  display: grid;
  grid-template-columns: 1fr clamp(400px, 34vw, 560px);
  height: calc(100vh - 54px);
}

#map {
  width: 100%;
  height: 100%;
  border-right: 1px solid var(--line);
}

.panel {
  overflow: auto;
  padding: 1rem;
  background: var(--panel);
}

.panel h2, .panel h3 { margin: 0 0 0.5rem; }
.panel h3 { font-size: 0.95rem; margin-top: 1rem; color: var(--muted); }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.hint { color: var(--muted); font-size: 0.9rem; }

/* --- Sbalitelné bloky panelu --- */

.block {
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.block > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  background: #f1f6ef;
  list-style: none;
}

.block > summary::-webkit-details-marker { display: none; }

/* Vlastní šipka, ať se dá otočit při rozbalení. */
.block > summary::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.block[open] > summary::before { transform: rotate(45deg); }

.block > summary:hover { background: #e7f0e4; }

.block-title { flex: 1; }

.block-count {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.block-body { padding: 0.65rem; }

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.1rem 0 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover { background: #eef5ec; }

.chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.legend-box > summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: #fff;
  font-size: 0.92rem;
}

.detail.empty { color: var(--muted); }

.detail .meta { margin: 0.2rem 0; }
.detail .label { color: var(--muted); font-size: 0.8rem; }

.owners, .boxes { list-style: none; padding: 0; margin: 0.5rem 0; }
.owners li, .boxes li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem;
  margin-bottom: 0.4rem;
}

.boxes li.selected {
  outline: 2px solid var(--accent);
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.88rem;
}

.list li:hover { background: #eef5ec; }

.block-body > .list > li:last-child { border-bottom: none; }

/* Řádek, do kterého se vsune detail vybraného majitele nebo pozemku. */
li.detail-host {
  display: block;
  padding: 0;
  cursor: default;
  background: #f4f8f2;
  border-bottom: 1px solid var(--line);
}

li.detail-host:hover { background: #f4f8f2; }

li.detail-host > .detail {
  margin: 0.5rem;
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(31, 92, 58, 0.12);
}

#detailHome:empty { display: none; }

/* --- Přihlašovací stránka --- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 6px 24px rgba(28, 42, 31, 0.12);
}

.login-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1rem;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-form input {
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.login-error {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: #fbe6e2;
  color: var(--danger);
  font-size: 0.85rem;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.user-box form { margin: 0; }

.list li.group-item {
  display: block;
}

.list li .row-main {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.list li .owner-name {
  font-weight: 600;
}

.list li .row-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.filter-row select {
  flex: 1;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.hidden { display: none !important; }

.municipality-item { display: block; padding: 0; }

.municipality-item > details > summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  font-weight: 600;
  list-style: none;
}

.municipality-item > details > summary::-webkit-details-marker { display: none; }

.municipality-item > details > summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.12s;
}

.municipality-item > details[open] > summary::before { content: "▾"; }

.municipality-name { flex: 1; }

.municipality-count {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
}

.list.nested {
  margin: 0 0 0.3rem 1.4rem;
  border-left: 2px solid var(--line);
}

.list.nested li {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.manual-owner {
  margin: 0.5rem 0 0.2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.manual-owner > summary {
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.manual-owner form {
  padding: 0 0.6rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.manual-owner label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.manual-owner input[type="text"],
.manual-owner input:not([type]) {
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
}

.manual-owner .field-row {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 0.4rem;
}

.manual-owner .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
}

.manual-owner-msg { font-size: 0.78rem; min-height: 1em; }

.manual-detail > summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.15rem 0;
}

.manual-detail {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.parse-preview {
  font-size: 0.75rem;
  line-height: 1.35;
  min-height: 1em;
  white-space: pre-line;
}

.manual-owner .hint {
  font-size: 0.72rem;
  line-height: 1.4;
  margin: 0.35rem 0 0.2rem;
}

.owner-source {
  font-size: 0.72rem;
  color: var(--muted);
}

.list li.active {
  background: #fff3f0;
  box-shadow: inset 3px 0 0 var(--highlight);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.2rem 0 0.5rem;
}

.legend span { display: inline-flex; align-items: center; gap: 0.3rem; }

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.bulk-bar .checkbox-label { margin-bottom: 0; }

#messageForm label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

#messageForm input[type="text"],
#messageForm input:not([type]) {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
}

#messageForm input[type="file"] {
  width: 100%;
  margin-top: 0.2rem;
  font-size: 0.8rem;
}

#messageInfo {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  line-height: 1.4;
}

.warn-text { color: #b26a00; }
.ok-text { color: #2f7a3d; }

.preview-out {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfd;
  max-height: 380px;
  overflow-y: auto;
}
.preview-out h4 { margin: 0 0 6px; }
.preview-out h5 { margin: 12px 0 4px; }

.confirm-message {
  margin: 0.5rem 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafafa;
  font-size: 0.85rem;
}

.list li.row-with-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.list li.row-with-check .row-body { flex: 1; min-width: 0; }

.list li input[type="checkbox"] {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.list li.is-sent .owner-name { color: var(--sent); }

.batch-report {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.batch-report .ok { color: var(--accent); }
.batch-report .warn { color: #8a6d12; }

.group-parcels {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
}

.group-parcels li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.3rem;
}

.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
}
.dot.own { background: var(--own); }
.dot.neighbor { background: var(--neighbor); }
.dot.sent { background: var(--sent); }
.dot.no-box { background: var(--no-box); }
.dot.highlight { background: var(--highlight); }

.actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

button.primary, button.danger, .actions button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

button.linkish {
  background: transparent;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  max-width: 420px;
}

.confirm-form h3 { margin-top: 0; }

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh 1fr;
    height: auto;
  }
  #map { min-height: 55vh; border-right: none; border-bottom: 1px solid var(--line); }
  .modes { flex-wrap: wrap; }
}
