:root {
  --bg: #0f1f17;
  --panel: #14271d;
  --accent: #3fa66a;
  --accent-strong: #2e8b57;
  --text: #f3faf5;
  --muted: #d4e6da;
  --error-bg: #7a1f1f;
  --error-fg: #ffd5d5;
}

* {
  box-sizing: border-box;
}

/* Ensure the hidden attribute always wins over display rules below. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Obere Leiste ---------- */
.panel {
  flex: 0 0 auto;
  background: var(--panel);
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--accent-strong);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  z-index: 1000; /* über der Leaflet-Karte */
}

.panel__row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.title {
  font-size: 1.25rem;
  margin: 0;
  white-space: nowrap;
}

.uploader {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.file-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* Visually hide the native file input; the label text acts as the button. */
.file-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

#file-label-text {
  display: inline-block;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

.file-label:hover #file-label-text {
  background: rgba(255, 255, 255, 0.2);
}

.file-label input[type="file"]:focus-visible + #file-label-text {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Click-to-paste / drop zone ---------- */
.paste-box {
  margin-top: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.9rem;
  cursor: text;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.paste-box:hover {
  border-color: rgba(255, 255, 255, 0.55);
}

.paste-box:focus,
.paste-box:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: rgba(63, 166, 106, 0.18);
  color: var(--text);
}

.paste-box--drag {
  border-color: var(--accent);
  border-style: solid;
  background: rgba(63, 166, 106, 0.28);
  color: var(--text);
}

.paste-box kbd {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 0 0.3rem;
  font-size: 0.8em;
}

#submit-btn {
  background: var(--accent-strong);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

#submit-btn:hover:not(:disabled) {
  background: var(--accent);
}

#submit-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ---------- Image preview thumbnails ---------- */
.previews {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.preview {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview__remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 16px;
  text-align: center;
  border: none;
  border-radius: 0 6px 0 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.preview__remove:hover {
  background: var(--error-bg);
}

/* ---------- Ladeanzeige ---------- */
.loading {
  margin-top: 0.6rem;
  color: var(--muted);
}

/* ---------- Fehler ---------- */
.error {
  margin-top: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--error-bg);
  color: var(--error-fg);
  border-radius: 6px;
  font-size: 0.95rem;
}

/* ---------- Ergebnis-Header ---------- */
.result {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.result__main {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.result__scientific {
  font-size: 1.35rem;
  font-weight: 700;
  font-style: italic;
}

.result__common {
  color: var(--muted);
  font-size: 1.05rem;
}

.result__meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.32);
  color: #ffffff;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Farblich codierte Zustände — hoher Kontrast (WCAG AA). */
.badge--good {
  background: #1c6b3f;
  border-color: #41c177;
  color: #ffffff;
}

.badge--warn {
  background: #e8a83d;
  border-color: #ffd591;
  color: #1b1200; /* dunkler Text auf hellem Amber */
}

.badge--bad {
  background: #b23838;
  border-color: #f08a8a;
  color: #ffffff;
}

/* ---------- Kandidaten-Auswahl ---------- */
.candidates {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.candidates__label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.candidates__list {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.candidate {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #1d3829;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.candidate:hover {
  background: #244633;
  border-color: rgba(255, 255, 255, 0.45);
}

.candidate--active {
  background: var(--accent-strong);
  border-color: #6fe3a0;
  box-shadow: 0 0 0 2px rgba(111, 227, 160, 0.45);
}

.candidate__name {
  font-style: italic;
  font-weight: 600;
}

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

.candidate--active .candidate__common {
  color: #e7f6ec;
}

.candidate__score {
  font-size: 0.78rem;
  padding: 0.1rem 0.45rem;
}

/* ---------- Main area: map + country sidebar ---------- */
.content {
  flex: 1 1 auto;
  display: flex;
  min-height: 0; /* allow children to shrink correctly */
}

.map {
  flex: 1 1 auto;
  min-width: 0; /* let the map shrink when the sidebar shows */
  min-height: 0;
}

/* ---------- Country sidebar ---------- */
.country-panel {
  flex: 0 0 272px;
  overflow-y: auto;
  background: var(--panel);
  border-left: 2px solid var(--accent-strong);
  padding: 0.9rem 1rem;
  transition: flex-basis 0.16s ease, padding 0.16s ease;
}

.country-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}

.country-panel__title {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.country-panel__toggle {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.country-panel__toggle:hover {
  border-color: #6fe3a0;
  background: rgba(63, 166, 106, 0.25);
}

.country-panel--collapsed {
  flex-basis: 48px;
  overflow: hidden;
  padding: 0.75rem 0.55rem;
}

.country-panel--collapsed .country-panel__header {
  justify-content: center;
  margin-bottom: 0;
}

.country-panel--collapsed .country-panel__title,
.country-panel--collapsed .country-panel__body {
  display: none;
}

.country-list__state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.country-row {
  margin-bottom: 0.6rem;
}

.country-row__head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.country-row__name {
  color: var(--text);
}

.country-row__metric {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.country-row__bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.country-row__fill {
  height: 100%;
  min-width: 2px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-strong), #6fe3a0);
}

.country-row__sub {
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.country-panel__note {
  margin: 0.8rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .content {
    flex-direction: column;
  }

  .country-panel {
    flex-basis: 38vh;
    border-left: none;
    border-top: 2px solid var(--accent-strong);
  }

  .country-panel--collapsed {
    flex-basis: 46px;
    padding: 0.45rem 0.75rem;
  }
}

/* Leaflet-Attribution dunkel lesbar halten */
.leaflet-container {
  background: #0a140e;
}

/* ---------- Collapsible image comparison ---------- */
/* Small toggle button (collapsed state) */
.images-toggle {
  position: fixed;
  left: 12px;
  bottom: 20px;
  z-index: 1100;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  background: rgba(15, 31, 23, 0.94);
  color: var(--text);
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.images-toggle:hover {
  background: rgba(30, 56, 41, 0.96);
  border-color: #6fe3a0;
}

/* Expanded state: modal overlay covering the map */
.images-panel {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
}

.images-dialog {
  position: relative;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  max-width: 96vw;
  max-height: 92vh;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--accent-strong);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  overflow: auto;
}

.images-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.images-close:hover {
  background: var(--error-bg);
}

.thumb {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thumb img {
  width: min(42vw, 440px);
  height: min(62vh, 440px);
  object-fit: contain;
  border-radius: 8px;
  background: #0a140e;
  display: block;
}

.thumb figcaption {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
}

.thumb .credit {
  display: block;
  font-size: 0.72rem;
  opacity: 0.8;
}

@media (max-width: 720px) {
  html,
  body {
    min-height: 100%;
    height: auto;
  }

  body {
    min-height: 100dvh;
  }

  .panel {
    padding: 0.65rem 0.75rem;
  }

  .panel__row {
    gap: 0.65rem;
  }

  .title {
    width: 100%;
    font-size: 1.08rem;
  }

  .uploader {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
  }

  .file-label,
  #file-label-text,
  #submit-btn {
    width: 100%;
  }

  #file-label-text,
  #submit-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .paste-box {
    width: 100%;
    min-height: 44px;
    padding: 0.55rem 0.7rem;
  }

  .paste-box span {
    line-height: 1.3;
  }

  body.has-result .panel {
    padding: 0.5rem 0.65rem;
  }

  body.has-result .paste-box,
  body.has-result .previews {
    display: none !important;
  }

  .loading,
  .error,
  .candidates,
  .result {
    margin-top: 0.45rem;
  }

  .result {
    gap: 0.5rem;
  }

  .result__main {
    width: 100%;
    gap: 0.35rem;
  }

  .result__scientific {
    font-size: 1.02rem;
    line-height: 1.2;
  }

  .result__common {
    font-size: 0.88rem;
  }

  .result__meta {
    gap: 0.35rem;
    overflow-x: auto;
    padding-bottom: 0.1rem;
    flex-wrap: nowrap;
    max-width: 100%;
  }

  .badge {
    font-size: 0.76rem;
    padding: 0.22rem 0.48rem;
  }

  .candidates {
    display: block;
  }

  .candidates__label {
    display: block;
    margin-bottom: 0.35rem;
  }

  .candidates__list {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.45rem;
    overflow-x: auto;
    padding: 0.1rem 0.05rem 0.35rem;
    scrollbar-width: thin;
  }

  .candidate {
    flex: 0 0 auto;
    max-width: min(78vw, 330px);
    min-height: 44px;
    padding: 0.38rem 0.55rem;
    gap: 0.4rem;
  }

  .candidate__name,
  .candidate__common {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .content {
    position: relative;
    flex: 1 1 auto;
    display: block;
    min-height: 62dvh;
  }

  .map {
    width: 100%;
    min-height: 62dvh;
    height: calc(100dvh - 172px);
  }

  body.has-result .map {
    min-height: 68dvh;
    height: calc(100dvh - 132px);
  }

  .leaflet-bottom.leaflet-left,
  .leaflet-bottom.leaflet-right {
    bottom: 58px;
  }

  .images-dialog {
    flex-direction: column;
    flex-wrap: nowrap;
    width: min(94vw, 460px);
    max-height: 88dvh;
    padding: 48px 14px 14px;
  }

  .images-close {
    width: 40px;
    height: 40px;
  }

  .thumb img {
    width: min(86vw, 440px);
    height: auto;
    max-height: 38vh;
  }

  .images-toggle {
    left: 12px;
    bottom: 68px;
    min-height: 44px;
    padding: 0.55rem 0.85rem;
  }

  .country-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1080;
    width: auto;
    max-height: 58dvh;
    overflow: hidden;
    border-left: none;
    border-top: 2px solid var(--accent-strong);
    border-radius: 14px 14px 0 0;
    padding: 0.65rem 0.85rem max(0.8rem, env(safe-area-inset-bottom));
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.52);
    transition: max-height 0.18s ease, padding 0.18s ease;
  }

  .country-panel__header {
    min-height: 44px;
    margin-bottom: 0.45rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .country-panel__title {
    font-size: 0.98rem;
  }

  .country-panel__toggle {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }

  .country-panel__body {
    max-height: calc(58dvh - 68px);
    overflow-y: auto;
    padding-right: 0.1rem;
  }

  .country-panel--collapsed {
    max-height: calc(58px + env(safe-area-inset-bottom));
    padding: 0.35rem 0.85rem max(0.35rem, env(safe-area-inset-bottom));
  }

  .country-panel--collapsed .country-panel__header {
    justify-content: space-between;
    margin-bottom: 0;
  }

  .country-panel--collapsed .country-panel__title {
    display: block;
  }

  .country-row {
    margin-bottom: 0.55rem;
  }

  .country-row__head {
    font-size: 0.86rem;
  }

  .country-panel__note {
    padding-bottom: 0.1rem;
  }
}
