:root {
  --bg: #f4f6f9;
  --panel-bg: #ffffff;
  --border: #d8dee9;
  --text: #2e3440;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --accent: #0ea5e9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

header {
  background: var(--text);
  color: white;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
header h1 { margin: 0; font-size: 1.3rem; }
header .tagline { color: #cbd5e1; font-size: 0.85rem; }
.header-spacer { flex: 1; }
.mapy-key-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: #cbd5e1;
}
.mapy-key-row input {
  width: 11rem;
  background: #1e293b;
  color: white;
  border: 1px solid #475569;
}
.mapy-key-row button {
  background: #334155;
  color: white;
  border-color: #475569;
}
.mapy-key-row button:hover { background: #475569; }

main {
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 50px);
}

/* Mobile tab nav (hidden on desktop) */
.mobile-tabs { display: none; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-y: auto;
}
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.panel h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.row label { font-size: 0.85rem; display: flex; gap: 0.3rem; align-items: center; }
.row label.grow { flex: 1; }
.row label.grow input { flex: 1; }
.row.constraints label { font-size: 0.8rem; }

input[type=text], input[type=number], select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
}
input[type=text] { min-width: 0; flex: 1; }

button {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
button:hover { background: #f1f5f9; }
button.primary { background: var(--primary); color: white; border-color: var(--primary); }
button.primary:hover { background: var(--primary-hover); }
button.small { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
button.danger { color: var(--danger); }

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.2rem 0 0.5rem;
}
.hint code { background: #eef2f7; padding: 1px 4px; border-radius: 3px; }

.dead-hint {
  font-size: 0.75rem;
  color: #b45309;
  background: #fef9c3;
  border: 1px solid #fde68a;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  margin: -0.1rem 0 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stage-row, .var-row, .wp-row, .expr-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.3rem;
}
.stage-row input.name { width: 5rem; }
.var-row input.var-name { width: 3rem; text-align: center; text-transform: uppercase; }
.var-row input.var-spec { flex: 1; }
.expr-row input.expr-text { flex: 1; }
.expr-row input.expr-val { width: 6rem; }

.wp-row select { width: 7em; }
.wp-icon { background: none !important; border: none !important; }
.wp-icon span { font-size: 20px; line-height: 24px; }
.actions { margin-top: 0.8rem; }

.status {
  margin-top: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  min-height: 1.4rem;
}
.status.error { background: #fee2e2; color: var(--danger); }
.status.ok { background: #dcfce7; color: #166534; }
.estimate { font-size: 0.85rem; color: var(--muted); margin-top: 0.3rem; min-height: 1.2em; }
.estimate.warn { color: #b45309; font-weight: 600; }
.progress { margin-top: 0.5rem; }
.progress-bar { height: 10px; background: #e5e7eb; border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.15s linear; width: 0; }
.progress-text { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }

.map-section {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1rem;
  min-height: 0;
}

#map {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  min-height: 400px;
}

.results {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.results-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.results h2 { margin: 0; font-size: 1rem; }
.gc-link { font-size: 0.85rem; color: var(--primary); text-decoration: none; font-weight: 600; }
.gc-link:hover { text-decoration: underline; }
.filter { display: flex; flex-direction: column; gap: 0.25rem; margin: 0.4rem 0; font-size: 0.85rem; }
.filter:empty { margin: 0; }
.filter select { padding: 0.15rem 0.3rem; }
.filter-row { display: flex; align-items: center; gap: 0.3rem; }
.filter-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filter-only-lbl { font-size: 0.8rem; display: flex; align-items: center; gap: 0.25rem; cursor: pointer; }
.results li.dimmed { opacity: 0.35; }
.results li.selected { background: #fef3c7 !important; border-left: 3px solid #f59e0b; }
.results li.wp-item { background: #fef3c7; border-left: 3px solid #f59e0b; }
.wp-dot { background: none !important; font-size: 1rem; line-height: 1; padding: 0; width: auto !important; height: auto !important; }
.results ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  flex: 1;
  overflow-y: auto;
  font-size: 0.78rem;
}
.results li {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}
.results li:hover { background: #f8fafc; }
.results li.active { background: #e0f2fe; }
.results li .meta { color: var(--muted); font-size: 0.7rem; }
.results li .del-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-weight: bold;
  cursor: pointer;
  padding: 0 0.3rem;
}

.group-badge {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0 0.3rem;
  border-radius: 3px;
  border: 1px solid #bae6fd;
  vertical-align: middle;
}

.group-combos {
  list-style: none;
  padding: 0.1rem 0 0 1.5rem;
  margin: 0;
}

.group-combo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.1rem 0;
  font-size: 0.72rem;
  color: var(--muted);
  border-bottom: none;
  cursor: default;
}
.group-combo-item .combo-text {
  background: #eef2f7;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: monospace;
}
.group-combo-item.dimmed { opacity: 0.35; }

.li-main {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}

.stage-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid white;
  box-shadow: 0 0 0 1px #cbd5e1;
  flex-shrink: 0;
  margin-top: 3px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  padding: 0.3rem 0;
  font-size: 0.75rem;
  color: var(--muted);
  border-bottom: 1px solid #f1f5f9;
}
.legend:empty { display: none; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.legend .stage-dot { margin-top: 0; }

/* ---- Marker popup ---- */
.popup-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.popup-actions button {
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
}

/* ---- Mapy.cz logo control ---- */
.mapy-logo {
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.mapy-logo img { display: block; height: 16px; }

/* ---- Panorama modal ---- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
}
.modal.open { display: flex; }
.modal-content {
  background: white;
  border-radius: 8px;
  width: min(1100px, 96vw);
  height: min(800px, 92vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--text);
  color: white;
  font-weight: 600;
}
.modal-close {
  background: transparent;
  color: white;
  border: 1px solid #475569;
  font-size: 0.9rem;
  padding: 0.1rem 0.5rem;
}
.modal-close:hover { background: #475569; }
.modal-content iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: #0f172a;
}
.modal-footer {
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.modal-footer a { color: var(--primary); }
.modal-hint { color: var(--muted); font-size: 0.75rem; }

/* ===== Mobile / tablet portrait layout ===== */
@media (max-width: 900px) {
  header { padding: 0.4rem 0.6rem; gap: 0.5rem; flex-wrap: wrap; }
  header h1 { font-size: 1.05rem; }
  header .tagline { display: none; }
  .mapy-key-row { font-size: 0.7rem; gap: 0.25rem; }
  .mapy-key-row input { width: 7rem; padding: 0.2rem 0.3rem; }

  .mobile-tabs {
    display: flex;
    background: var(--text);
    border-top: 1px solid #1f2937;
    position: sticky;
    top: 0;
    z-index: 500;
  }
  .mobile-tabs .mt-btn {
    flex: 1;
    background: transparent;
    color: #cbd5e1;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: 0.55rem 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
  }
  .mobile-tabs .mt-btn:hover { background: #1f2937; }
  .mobile-tabs .mt-btn.active {
    color: white;
    border-bottom-color: var(--primary);
    background: #1f2937;
  }

  main {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    gap: 0;
    height: calc(100dvh - 92px);
    overscroll-behavior-x: contain;
  }
  /* Hide scrollbar but keep functionality */
  main::-webkit-scrollbar { display: none; }
  main { scrollbar-width: none; }

  /* Unwrap .map-section so #map and .results become direct flex children of main */
  .map-section { display: contents; }

  .panel,
  #map,
  .results {
    flex: 0 0 100vw;
    width: 100vw;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    height: 100%;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    overflow-y: auto;
  }
  #map {
    min-height: 100%;
    border: 0;
  }

  .panel { padding: 0.7rem; }
  .panel h3 { margin: 0.8rem 0 0.3rem; }

  .results { padding: 0.5rem; }

  /* Compact form elements on mobile */
  .row { gap: 0.35rem; margin-bottom: 0.35rem; }
  input[type=text], input[type=number], select {
    font-size: 16px;  /* prevents iOS zoom on focus */
    padding: 0.4rem 0.5rem;
  }
  button {
    font-size: 0.9rem;
    padding: 0.45rem 0.7rem;
    min-height: 36px;  /* easier tap target */
  }
  button.small {
    font-size: 0.85rem;
    padding: 0.3rem 0.55rem;
    min-height: 32px;
  }

  .stage-row, .var-row, .wp-row, .expr-row {
    flex-wrap: wrap;
  }
  .var-row input.var-spec, .expr-row input.expr-text { min-width: 8rem; }

  /* Result list compact */
  .results li { padding: 0.4rem 0.3rem; }

  /* Modal: full-screen on mobile */
  .modal { padding: 0; }
  .modal-content { width: 100vw; height: 100dvh; border-radius: 0; }
}
