/* ============================================================
   Marktstammdaten Viewer — design system
   ============================================================ */
:root {
  /* palette */
  --bg: #fafbfc;
  --bg-elev: #ffffff;
  --bg-soft: #f1f5f9;
  --bg-sunken: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --accent: #0f766e;       /* teal-700 */
  --accent-hover: #0d6963;
  --accent-soft: #ccfbf1;
  --accent-text: #134e4a;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;

  /* radius & shadow */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.02);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.18);

  /* sizing */
  --topbar-h: 64px;
  --sidebar-w: 300px;

  /* motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 180ms;
}

/* ============================================================
   reset & base
   ============================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

code {
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

/* ============================================================
   topbar
   ============================================================ */
.topbar {
  height: var(--topbar-h);
  padding: 0 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px -4px rgba(15, 118, 110, 0.4);
}
.logo svg {
  width: 20px;
  height: 20px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-text strong {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-text span {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Data-freshness pill: shows record count + DB build date + age, colour-coded.
   Lives inside the brand block so it sits beside the app title. */
.data-freshness {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  margin-left: 14px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.data-freshness-fresh {
  background: #d1fae5;
  color: #065f46;
}
.data-freshness-stale {
  background: #fef3c7;
  color: #92400e;
}
.data-freshness-old {
  background: #fee2e2;
  color: #991b1b;
}
.data-freshness.hidden {
  display: none;
}
.data-freshness-sep {
  width: 1px;
  height: 14px;
  background: currentColor;
  opacity: 0.25;
  margin: 0 10px;
  flex-shrink: 0;
}

/* ============================================================
   buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-md);
  font-weight: 500;
  font-size: 14px;
  transition: transform var(--dur) var(--ease),
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
  border: 1px solid transparent;
  user-select: none;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px -2px rgba(15, 118, 110, 0.4);
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover {
  background: var(--bg-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-lg {
  padding: 12px 22px;
  font-size: 15px;
}
.btn-block {
  display: flex;
  width: 100%;
}

.btn-link {
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 0;
}
.btn-link:hover {
  text-decoration: underline;
}

.btn-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: background var(--dur);
}
.btn-close:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.btn-close svg {
  width: 18px;
  height: 18px;
}

/* ============================================================
   viewer layout
   ============================================================ */
.viewer {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-section {
  padding: 0 16px;
}
.sidebar-section + .sidebar-section {
  margin-top: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding: 0 4px;
}
.section-label.with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* table picker */
.table-picker {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tp-group {
  margin-top: 10px;
}
.tp-group:first-child {
  margin-top: 0;
}
.tp-group-label {
  font-size: 11px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px 4px;
  font-weight: 600;
}
.tp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  transition: background var(--dur);
  text-align: left;
  width: 100%;
}
.tp-item:hover {
  background: var(--bg-soft);
}
.tp-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 500;
}
.tp-item .tp-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tp-item .tp-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-sunken);
  padding: 2px 6px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.tp-item.active .tp-count {
  background: rgba(15, 118, 110, 0.15);
  color: var(--accent-text);
}
.tp-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.tp-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-hint {
  margin: 16px 16px 0;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-sunken);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}
.sidebar-hint svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--accent);
  margin-top: 1px;
}
.sidebar-hint strong {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  font-size: 12px;
}

/* ============================================================
   results
   ============================================================ */
.results {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* CRITICAL: grid children default to min-height:auto which lets the
     child table grow to its intrinsic height; forcing 0 lets the inner
     .table-wrap's `overflow: auto` actually kick in. */
  min-height: 0;
  padding: 20px 24px 24px;
  gap: 14px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-wrap {
  flex: 1;
  position: relative;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
#search-input {
  width: 100%;
  /* Right padding leaves room for the .search-kbd badge */
  padding: 12px 44px 12px 42px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur), box-shadow var(--dur);
}
#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
#search-input::placeholder {
  color: var(--text-soft);
}
/* Tiny "press / to focus" hint, GitHub-style. Hidden as soon as the
   input is focused or non-empty so it never blocks the value. */
.search-kbd {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  line-height: 1;
  transition: opacity var(--dur);
}
#search-input:focus ~ .search-kbd,
#search-input:not(:placeholder-shown) ~ .search-kbd {
  opacity: 0;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 2px;
}
.meta-count {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* table */
.table-wrap {
  position: relative;
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: auto;
  min-height: 0;
}

#result-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#result-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--dur);
  z-index: 1;
}
#result-table thead th:hover {
  color: var(--text);
}
/* sort indicator is rendered inside .th-sort, no pseudo-element needed */

#result-table tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
#result-table tbody tr {
  transition: background var(--dur);
  cursor: pointer;
}
#result-table tbody tr:hover {
  background: var(--bg-sunken);
}
#result-table tbody tr.selected {
  background: var(--accent-soft);
}

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

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  pointer-events: none;
  /* Sit above Leaflet tile layers (which default to z-index 400) so the
     empty-state icon + caption stay visible on no-geo tables. */
  z-index: 500;
}
#map-empty {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(2px);
}
.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--bg-sunken);
  display: grid;
  place-items: center;
  color: var(--text-soft);
}
.empty-icon svg {
  width: 28px;
  height: 28px;
}
.empty-text {
  font-size: 14px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
}
.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
/* Small inline spinner for use next to text */
.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
  vertical-align: -2px;
  margin-right: 4px;
}
/* Spinner on a primary (accent) background — flip the colors for contrast */
.spinner-on-accent {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 4px 0;
}
.pagination-info {
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  min-width: 140px;
  text-align: center;
}

/* ============================================================
   no-db state
   ============================================================ */
.no-db {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 40px 20px;
  background: var(--bg);
}
.no-db-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 48px 56px;
  max-width: 480px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.no-db-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(15, 118, 110, 0.08));
  color: var(--accent);
  display: grid;
  place-items: center;
  margin: 0 auto 20px;
}
.no-db-icon svg {
  width: 36px;
  height: 36px;
}
.no-db h1 {
  font-size: 22px;
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.no-db p {
  color: var(--text-muted);
  margin: 0 0 28px;
  font-size: 14px;
}

/* ============================================================
   import overlay
   ============================================================ */
.import-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fadein var(--dur) var(--ease);
}
@keyframes fadein {
  from {
    opacity: 0;
  }
}

.import-card {
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: popin var(--dur) var(--ease);
}
@keyframes popin {
  from {
    transform: scale(0.96) translateY(8px);
    opacity: 0;
  }
}

.import-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}
.import-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.import-body {
  padding: 0 24px 24px;
  overflow-y: auto;
}
.import-state {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.db-info {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
}
.db-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.db-info-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-weight: 600;
}
.db-info-value {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.import-explain {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

.progress-phase {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-phase::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

.progress-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}
.progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, var(--accent), #14b8a6);
  border-radius: 999px;
  transition: width 500ms var(--ease);
}
.progress-pct {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  mix-blend-mode: difference;
  color: #fff;
}

.progress-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.stat strong {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records-table {
  margin-top: 4px;
}
.records-table summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 0;
  user-select: none;
}
.table-progress {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
}
.tp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.tp-row:nth-child(even) {
  background: var(--bg-sunken);
}
.tp-row-name {
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
  font-size: 11px;
}
.tp-row-val {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.error-icon,
.done-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto;
}
.error-icon {
  background: var(--danger-soft);
  color: var(--danger);
}
.done-icon {
  background: var(--success-soft);
  color: var(--success);
}
.error-icon svg,
.done-icon svg {
  width: 28px;
  height: 28px;
}
.error-text {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  color: var(--danger);
}
.done-summary {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
#import-error h3,
#import-done h3 {
  text-align: center;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

/* ============================================================
   column picker
   ============================================================ */
.col-picker {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 1700;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fadein var(--dur);
}
.col-picker-card {
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: min(440px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: popin var(--dur) var(--ease);
}
.col-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}
.col-picker-head h3 {
  margin: 0;
  font-size: 16px;
}
.col-picker-search {
  padding: 0 24px 12px;
}
.col-picker-search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 13px;
}
.col-picker-search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.col-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}
.col-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--dur);
  user-select: none;
}
.col-item:hover {
  background: var(--bg-soft);
}
.col-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.col-item-name {
  flex: 1;
  font-size: 13px;
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-item-type {
  font-size: 11px;
  color: var(--text-soft);
  text-transform: uppercase;
}
.col-picker-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* ============================================================
   detail drawer
   ============================================================ */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 1500; /* above Leaflet's control-container (z=1000) */
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.3);
  animation: fadein var(--dur);
}
.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100vh;
  width: min(540px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 48px -24px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  animation: slidein 300ms var(--ease);
}
@keyframes slidein {
  from {
    transform: translateX(100%);
  }
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 32px;
}
.drawer-field {
  display: grid;
  grid-template-columns: 38% 1fr;
  gap: 8px 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.drawer-field:last-child {
  border-bottom: 0;
}
.drawer-field-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.drawer-field-value {
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.drawer-field-value.null {
  color: var(--text-soft);
  font-style: italic;
}

/* ============================================================
   toasts
   ============================================================ */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: slideup var(--dur) var(--ease);
  pointer-events: auto;
  max-width: 360px;
}
.toast.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}
.toast.success {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}
@keyframes slideup {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

/* ============================================================
   Header column popover (per-column filter)
   ============================================================ */
.th-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.th-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.th-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.th-sort {
  font-size: 11px;
  color: var(--accent);
  width: 10px;
  text-align: center;
}
.th-filter {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  color: var(--text-soft);
  opacity: 0.35;
  transition: opacity var(--dur), background var(--dur), color var(--dur);
}
#result-table thead th:hover .th-filter {
  opacity: 0.85;
  color: var(--text-muted);
}
#result-table thead th .th-filter.active {
  opacity: 1;
  background: var(--accent);
  color: #fff;
}
.th-filter svg {
  width: 11px;
  height: 11px;
  stroke-width: 2.5;
}
#result-table thead th.filtered {
  background: linear-gradient(180deg, var(--accent-soft), var(--bg-sunken));
}

.header-popover {
  position: fixed;
  z-index: 150;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: hp-pop 140ms var(--ease);
  max-height: 70vh;
  overflow: hidden;
}
@keyframes hp-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}
.hp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.hp-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hp-sort {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.hp-sort button {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.hp-sort button svg {
  width: 12px;
  height: 12px;
}
.hp-sort button:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
}
.hp-sort button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.hp-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.hp-loading {
  display: grid;
  place-items: center;
  padding: 24px;
}
.hp-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.hp-range {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: center;
}
.hp-range input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.hp-range input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.hp-range-sep {
  color: var(--text-soft);
  font-size: 13px;
}
.hp-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.hp-chip {
  padding: 4px 9px;
  font-size: 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur);
}
.hp-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.hp-hint {
  font-size: 11px;
  color: var(--text-soft);
  font-style: italic;
}
.hp-search {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 13px;
}
.hp-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.hp-list {
  display: flex;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.hp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background var(--dur);
  border-bottom: 1px solid var(--border);
}
.hp-item:last-child {
  border-bottom: 0;
}
.hp-item:hover {
  background: var(--bg-sunken);
}
.hp-item.selected {
  background: var(--accent-soft);
}
.hp-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.hp-item-label {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hp-item-count {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 999px;
}
.hp-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
.hp-text-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.hp-text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.hp-op {
  display: flex;
  gap: 4px;
}
.hp-op button {
  flex: 1;
  padding: 5px 8px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur);
}
.hp-op button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.hp-foot {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.btn-sm:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ============================================================
   View toggle (Tabelle / Karte)
   ============================================================ */
.view-toggle {
  display: inline-flex;
  gap: 0;
  padding: 3px;
  background: var(--bg-soft);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.vt-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 7px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all var(--dur);
}
.vt-btn svg {
  width: 14px;
  height: 14px;
}
.vt-btn:hover {
  color: var(--text);
}
.vt-btn.active {
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* ============================================================
   Map view
   ============================================================ */
.map-wrap {
  position: relative;
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-height: 0;
}
.map-wrap.hidden {
  display: none !important;
}
.map {
  position: absolute;
  inset: 0;
  background: var(--bg-sunken);
}

.map-info {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 12px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  max-width: 360px;
  line-height: 1.45;
}
.map-info-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.map-info-text strong {
  font-weight: 600;
  color: var(--accent-text);
}
.map-info-warn {
  color: var(--warning);
  font-size: 11px;
}

/* Custom MaStR marker — circle with category icon */
.mastr-marker {
  background: transparent;
  border: none;
}
.mastr-marker-inner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
  transition: transform 120ms var(--ease);
}
.mastr-marker:hover .mastr-marker-inner {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.45);
}
.mastr-marker-inner svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Custom marker popup */
.leaflet-popup-content-wrapper {
  border-radius: var(--r-md) !important;
}
.leaflet-popup-content {
  margin: 12px 16px !important;
  font-family: inherit;
}
.marker-popup-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--text);
}
.marker-popup-id {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.marker-popup-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 2px 0;
  gap: 12px;
}
.marker-popup-label {
  color: var(--text-muted);
}
.marker-popup-value {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.marker-popup-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
}
.marker-popup-link:hover {
  text-decoration: underline;
}

/* Tweak Leaflet's default marker cluster colors to match the theme */
.marker-cluster-small {
  background-color: rgba(20, 184, 166, 0.4);
}
.marker-cluster-small div {
  background-color: rgba(15, 118, 110, 0.9);
  color: #fff;
}
.marker-cluster-medium {
  background-color: rgba(13, 148, 136, 0.4);
}
.marker-cluster-medium div {
  background-color: rgba(15, 118, 110, 0.95);
  color: #fff;
}
.marker-cluster-large {
  background-color: rgba(15, 118, 110, 0.4);
}
.marker-cluster-large div {
  background-color: rgba(15, 118, 110, 1);
  color: #fff;
}
.marker-cluster {
  font-weight: 600;
  font-family: -apple-system, "Segoe UI", Inter, sans-serif;
}

/* ============================================================
   Active filter pills (above the result table)
   ============================================================ */
.filter-pills {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: 8px;
}
.filter-pills.hidden {
  display: none !important;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
}
.pill:hover {
  background: rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}
.pill-x {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  margin-left: 2px;
  background: rgba(15, 118, 110, 0.14);
  transition: background var(--dur);
}
.pill-x:hover {
  background: var(--accent);
  color: #fff;
}
.pill-x svg {
  width: 11px;
  height: 11px;
  stroke: currentColor;
}
.pill-clear {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  padding: 4px 12px;
}
.pill-clear:hover {
  background: var(--bg-soft);
  border-color: var(--text-muted);
}

/* ============================================================
   responsive
   ============================================================ */
@media (max-width: 960px) {
  .viewer {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }
  .progress-stats {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   scrollbar polish
   ============================================================ */
*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 3px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ============================================================
   Freemium UI — upgrade pill, lizenz badge, truncation hint
   ============================================================ */
.free-upgrade-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 4px 4px 4px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s;
}
.free-upgrade-pill:hover {
  border-color: var(--accent);
}
.free-upgrade-pill.hidden { display: none; }
.free-upgrade-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 10px;
  opacity: 0.7;
}
.free-upgrade-sep {
  width: 1px;
  height: 12px;
  background: currentColor;
  opacity: 0.2;
  margin: 0 8px;
}
.free-upgrade-limit {
  color: var(--text-soft);
}
.free-upgrade-limit strong {
  font-weight: 600;
  color: var(--text);
}
.free-upgrade-cta {
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

.lizenz-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid #5eead4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.lizenz-badge-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
}
.lizenz-badge-date {
  color: var(--accent-text);
  opacity: 0.85;
}
.lizenz-badge.warn {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.lizenz-badge.warn .lizenz-badge-date {
  color: #991b1b;
}
.lizenz-badge.expired {
  background: #f1f5f9;
  border-color: var(--border);
  color: var(--text-muted);
}

/* Inline truncation hint inside the result count */
.result-count-truncated {
  color: var(--text-muted);
  font-weight: 500;
}
.result-count-truncated .truncated-cta {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}
.result-count-truncated .truncated-cta:hover {
  color: var(--accent-hover);
}
.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* Excel button hint subtitle "(max. 500)" */
.btn .btn-hint {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
}

/* ============================================================
   Generic modal — used for export confirm dialog
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(520px, 92vw);
  max-height: 92vh;
  overflow: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: 16px;
}
.modal-body {
  padding: 18px 20px 20px 20px;
}
.modal-text p {
  margin: 0 0 10px 0;
  line-height: 1.55;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

/* ============================================================
   Global footer — data-license attribution + Impressum on every page
   ============================================================ */
.app-footer {
  flex-shrink: 0;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--dur), border-color var(--dur);
}
.app-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.app-footer .sep {
  color: var(--text-soft);
  user-select: none;
}
/* Auth / premium pages use a transparent background so the radial
   gradients still show through under the footer. */
.auth-body .app-footer,
.premium-body .app-footer {
  background: transparent;
  border-top: none;
  padding: 28px 24px 32px;
}

