/* =========================================
   LAYOUT — Header, panely, mapa, toggle
   =========================================
   Obsah:
   - Hlavní layout (#app, .main-content)
   - Header (logo, search, dropdown, jazyk, logout)
   - Levý panel — Filtry (panel-filters, filter-section, checkboxy, selecty, tagy)
   - Střední panel — Seznam firem (panel-list, list-header, řazení)
   - Pravý panel — Mapa (panel-map, leaflet overrides, markery)
   - Panel toggle tlačítka (sbalení/rozbalení panelů)
   - Collapsed stavy panelů
   ========================================= */

/* =========================================
   HLAVNÍ LAYOUT
   ========================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#app.hidden { display: none; }

/* =========================================
   HEADER
   ========================================= */
.header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--color-accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo-icon svg { width: 16px; height: 16px; }

.header-logo-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-logo-text span { color: var(--color-accent); }

.header-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.header-search-input {
  width: 100%;
  height: 36px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 0 36px 0 36px;
  outline: none;
  transition: var(--transition);
}

.header-search-input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface-3);
}

.header-search-input::placeholder { color: var(--color-text-dim); }

.header-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-dim);
  pointer-events: none;
}

.header-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: none;
  line-height: 1;
}

.header-search-clear.visible { display: block; }

/* Autocomplete dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

.search-dropdown.visible { display: block; }

.search-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--color-border);
  transition: var(--transition);
}

.search-dropdown-item:last-child { border-bottom: none; }
.search-dropdown-item:hover { background: var(--color-hover); }

.search-dropdown-item-icon {
  width: 32px;
  height: 32px;
  background: var(--color-surface-3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.search-dropdown-item-body { flex: 1; min-width: 0; }

.search-dropdown-item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-dropdown-item-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.search-dropdown-loading,
.search-dropdown-empty {
  padding: 16px 14px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
}

/* Dropdown — tlačítko přidat */
.search-dropdown-item-add {
  width: 28px;
  height: 28px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.search-dropdown-item-add:hover {
  background: var(--color-accent-glow);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Přepínač jazyka */
.lang-switcher {
  display: flex;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.lang-btn {
  padding: 4px 10px;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lang-btn.active {
  background: var(--color-accent);
  color: #fff;
}

/* Status indikátor */
.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Odhlášení */
.btn-logout {
  width: 32px;
  height: 32px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-logout:hover {
  background: var(--color-hover);
  color: var(--color-text);
  border-color: var(--color-border-light);
}

/* Tlačítko vymazat všechna data (globální) */
.btn-clear-all-cache {
  width: 32px;
  height: 32px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  opacity: 0.7;
}

.btn-clear-all-cache:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  opacity: 1;
}

/* =========================================
   HLAVNÍ OBSAH
   ========================================= */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* =========================================
   LEVÝ PANEL — FILTRY
   ========================================= */
.panel-filters {
  width: 280px;
  width: var(--sidebar-left, 280px);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.2s ease;
}

.panel-filters.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-text-muted);
}

.panel-action {
  font-size: 11px;
  color: var(--color-accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.panel-action:hover { text-decoration: underline; }

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel-action-secondary {
  font-size: 14px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.panel-action-secondary:hover {
  opacity: 1;
  text-decoration: none;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* Filtr sekce */
.filter-section {
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.filter-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  user-select: none;
}

.filter-section-header:hover { background: var(--color-hover); }

.filter-section-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-section-title svg {
  color: var(--color-text-muted);
}

.filter-section-arrow {
  color: var(--color-text-dim);
  transition: transform 0.2s ease;
}

.filter-section.open .filter-section-arrow {
  transform: rotate(180deg);
}

.filter-section-body {
  padding: 4px 10px 10px;
  display: none;
}

.filter-section.open .filter-section-body { display: block; }

/* Select filter */
.filter-select {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a82a0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.filter-select:focus { border-color: var(--color-accent); }

/* Range filter */
.filter-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.filter-range-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
  transition: var(--transition);
}

.filter-range-input:focus { border-color: var(--color-accent); }
.filter-range-input::placeholder { color: var(--color-text-dim); }

/* Checkbox list */
.filter-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.filter-checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
}

.filter-checkbox-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-accent);
  cursor: pointer;
  flex-shrink: 0;
}

.filter-checkbox-label {
  font-size: 12px;
  color: var(--color-text);
  cursor: pointer;
  flex: 1;
}

.filter-checkbox-count {
  font-size: 10px;
  color: var(--color-text-dim);
  font-family: var(--font-mono);
}

/* Tag filter */
.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.filter-tag {
  padding: 3px 8px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-light);
  border-radius: 20px;
  font-size: 11px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.filter-tag:hover,
.filter-tag.active {
  background: var(--color-accent-glow);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Filtr — vyhledávací input (obory) */
.filter-search-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
  transition: var(--transition);
  margin-bottom: 6px;
}

.filter-search-input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface-3);
}

.filter-search-input::placeholder {
  color: var(--color-text-dim);
}

/* Filtr — badge (počet vybraných) */
.filter-badge {
  display: none;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  background: var(--color-accent);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  line-height: 16px;
  margin-left: 4px;
}

.filter-badge.visible {
  display: inline-block;
}

/* Segmenty — položky */
.segment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: 12px;
  color: var(--color-text);
}

.segment-item:hover {
  background: var(--color-hover);
}

.segment-item-icon {
  color: var(--color-text-dim);
  flex-shrink: 0;
}

.segment-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-item-count {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-text-dim);
  flex-shrink: 0;
}

/* Panel footer — tlačítka */
.panel-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.btn-primary {
  width: 100%;
  height: 36px;
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary:hover { background: var(--color-accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  height: 32px;
  background: transparent;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-family: var(--font-main);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

/* Disabled/coming soon sekce */
.disabled-section {
  position: relative;
  opacity: 0.4;
  pointer-events: none;
}

.coming-soon-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 9px;
  font-weight: 500;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* =========================================
   STŘEDNÍ PANEL — SEZNAM FIREM
   ========================================= */
.panel-list {
  width: 360px;
  width: var(--sidebar-right, 360px);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.2s ease;
}

.panel-list.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

.list-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-count {
  font-size: 12px;
  color: var(--color-text-muted);
}

.list-count strong {
  color: var(--color-text);
  font-family: var(--font-mono);
}

/* Sorting */
.list-sort {
  display: flex;
  align-items: center;
  gap: 6px;
}

.list-sort-label {
  font-size: 11px;
  color: var(--color-text-dim);
}

.list-sort-select {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 11px;
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}

/* =========================================
   PRAVÝ PANEL — MAPA
   ========================================= */
.panel-map {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* Leaflet overrides */
.leaflet-container {
  background: #1a1e2e;
  font-family: var(--font-main);
}

.leaflet-control-zoom {
  border: 1px solid var(--color-border-light) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--color-surface) !important;
  color: var(--color-text-muted) !important;
  border-bottom: 1px solid var(--color-border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--color-hover) !important;
  color: var(--color-text) !important;
}

.leaflet-control-attribution {
  background: rgba(20,23,32,0.8) !important;
  color: var(--color-text-dim) !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a { color: var(--color-text-muted) !important; }

/* Vlastní marker */
.custom-marker {
  width: 28px;
  height: 28px;
  background: var(--color-accent);
  border: 2px solid #1a1e2e;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: all 0.2s ease;
}

.custom-marker.active {
  background: #fff;
  border-color: var(--color-accent);
  transform: rotate(-45deg) scale(1.2);
  box-shadow: 0 2px 12px rgba(61,126,255,0.5);
}

/* Map loading overlay */
.map-loading {
  position: absolute;
  inset: 0;
  background: rgba(13,15,20,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(2px);
}

.map-loading.hidden { display: none; }

/* Map info */
.map-info {
  position: absolute;
  bottom: 24px;
  left: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--color-text-muted);
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

/* =========================================
   PANEL TOGGLE TLAČÍTKA
   ========================================= */
.panel-toggle {
  width: 16px;
  flex-shrink: 0;
  background: var(--color-surface);
  border: none;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  z-index: 10;
}

.panel-toggle:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.panel-toggle svg {
  transition: transform 0.3s ease;
}

/* Šipky pro collapsed stavy */
.panel-toggle-filters.collapsed svg {
  transform: rotate(180deg);
}

.panel-toggle-list.collapsed svg {
  transform: rotate(180deg);
}

/* =========================================
   INSIGHTS PANEL — 4. sloupec, přes mapu
   ========================================= */
.insights-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 400px;
  width: 600px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border-light);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.3s, opacity 0.3s ease;
}

.insights-panel.open {
  visibility: visible;
  opacity: 1;
}
