:root,
[data-theme="dark"] {
  --bg: #15110c;
  --surface: #1e1810;
  --surface-2: #291f14;
  --border: #3a2d1c;
  --text: #ece2cd;
  --text-muted: #a08f74;
  --gold: #c99a3d;
  --gold-bright: #e0b458;
  --copper: #a6512f;
  --green: #6f7d4f;
  /* Landmasse ohne Treffer bewusst neutral-grau: die Stufen mit Treffern
     heben sich dann nicht nur über die Helligkeit ab, sondern über den
     Farbton – das macht auch Stufe 1 klar erkennbar. */
  --map-land: #3a3630;
  --map-stroke: #15110c;
  --map-1: #a87c2e;
  --map-2: #c2913a;
  --map-3: #d4a646;
  --map-4: #e5bb57;
  --map-5: #f7d271;
  --map-bubble: #f0c766;
  --map-bubble-text: #15110c;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

[data-theme="light"] {
  --bg: #f7f2e8;
  --surface: #ffffff;
  --surface-2: #efe6d4;
  --border: #ddceac;
  --text: #2c2415;
  --text-muted: #7a6c50;
  --gold: #a8752b;
  --gold-bright: #8f5f1e;
  --copper: #8a4227;
  --green: #56612f;
  /* Im hellen Modus geht die Reihe von hell nach dunkel, die Landmasse ohne
     Treffer ist bewusst grau statt beige – so hebt sich schon die erste
     Stufe deutlich ab und nicht nur über die Helligkeit. */
  --map-land: #ddd8cd;
  --map-stroke: #ffffff;
  --map-1: #e8c072;
  --map-2: #d3a444;
  --map-3: #b8862c;
  --map-4: #94661d;
  --map-5: #6b4512;
  --map-bubble: #a8752b;
  --map-bubble-text: #ffffff;
}

[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse at top left, rgba(168, 117, 43, 0.08), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(138, 66, 39, 0.06), transparent 60%);
}

* { box-sizing: border-box; }

/* Links durchgehend in Gold statt im Browser-Blau */
a { color: var(--gold); text-decoration-color: rgba(201, 154, 61, 0.4); }
a:hover { color: var(--gold-bright); text-decoration-color: currentColor; }
a:visited { color: var(--gold); }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100%;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body {
  background-image:
    radial-gradient(ellipse at top left, rgba(201, 154, 61, 0.06), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(166, 81, 47, 0.05), transparent 60%);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 24px clamp(16px, 5vw, 48px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #f4ecd8;
}
.brand h1 { font-size: 1.5rem; letter-spacing: 0.01em; }
.brand-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 0.85rem; }

.tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 999px; border: 1px solid var(--border); }
.tab {
  font-family: var(--font-body);
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--gold); color: #1a1408; }

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

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
  position: relative;
}
.theme-toggle:hover { color: var(--gold); border-color: var(--gold); }
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { position: absolute; transition: opacity 0.15s ease, transform 0.15s ease; }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0); }
[data-theme="light"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0); }
[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg); }

main { padding: 28px clamp(16px, 5vw, 48px) 60px; max-width: 1100px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 28px; }
input, select, textarea, button {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.92rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}
#search-input { flex: 1; min-width: 200px; }

button { cursor: pointer; }
button[type="submit"], .btn-primary {
  background: var(--gold);
  color: #1a1408;
  border: none;
  font-weight: 600;
}
button[type="submit"]:hover { background: var(--gold-bright); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

/* ---------- Ledger (Übersicht) ---------- */
.ledger-group { margin-bottom: 36px; }
.ledger-date {
  font-family: var(--font-mono);
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.ledger-date::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.ledger-note { color: var(--text-muted); font-size: 0.85rem; font-style: italic; margin: -4px 0 10px; }

.ledger-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.ledger-row:hover { background: rgba(201, 154, 61, 0.04); }

/* Aufklappbare Zeile: zeigt Fass, Farbstoff, Kühlfiltrierung und Link */
.ledger-row-wrap > summary { cursor: pointer; list-style: none; }
.ledger-row-wrap > summary::-webkit-details-marker { display: none; }
.ledger-row-wrap > summary::marker { content: ""; }
.ledger-row-wrap .lr-name::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.75em;
  margin-right: 7px;
  display: inline-block;
  transition: transform 0.15s;
}
.ledger-row-wrap[open] .lr-name::before { transform: rotate(90deg); }
.ledger-row-wrap[open] > summary { background: rgba(201, 154, 61, 0.06); }
.ledger-details {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 12px 16px 16px 30px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.ledger-detail-list { display: flex; flex-wrap: wrap; gap: 8px 22px; flex: 1; }

/* Flaschenfotos */
.ledger-row.has-thumb { grid-template-columns: 34px 1fr auto auto auto; }
.lr-thumb {
  width: 34px;
  height: 46px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--surface-2);
}
.ledger-photo { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.photo-credit { font-size: 0.68rem; color: var(--text-muted); text-align: center; }
.fetch-fail { margin: 4px 0 0; padding-left: 18px; color: var(--text-muted); font-size: 0.78rem; }
.fetch-fail li { margin-bottom: 2px; }
.ledger-photo img {
  max-width: 130px;
  max-height: 190px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
}
.image-field { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.image-field > label { flex: 1; min-width: 200px; }
.image-preview { display: flex; align-items: center; gap: 10px; padding-top: 18px; }
.image-preview img {
  max-width: 90px;
  max-height: 120px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* KI-Assistent */
.assist-card { border-color: var(--gold); }
.assist-model { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }
.assist-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.assist-row input[type="text"] { flex: 1; min-width: 220px; }
.assist-row input[type="file"] { flex: 1; min-width: 220px; }
.btn-assist { background: var(--surface-2); border: 1px solid var(--gold); color: var(--gold); white-space: nowrap; }
.btn-assist:hover:not(:disabled) { background: var(--gold); color: #1a1408; }
.btn-assist:disabled { opacity: 0.6; cursor: default; }
.assist-hint { margin-top: 8px; }
.assist-result { margin-top: 12px; font-size: 0.82rem; }
.assist-result p { margin: 4px 0; }
.assist-ok { color: var(--green); }
.assist-warn { color: var(--copper); }
.assist-sources { color: var(--text-muted); word-break: break-all; }
.assist-sources a { color: var(--gold); }

/* kurz aufleuchten, damit man sieht, was der Assistent angefasst hat */
@keyframes ai-flash {
  from { background: rgba(201, 154, 61, 0.35); }
  to { background: var(--surface); }
}
.ai-filled { animation: ai-flash 2.5s ease-out; }
.ledger-details b { color: var(--text); font-weight: 500; }
.ledger-details a { color: var(--gold); }
.tri-yes { color: var(--copper); }
.tri-no { color: var(--green); }
.tri-unknown { font-style: italic; }
.ledger-badge {
  font-family: var(--font-body);
  color: var(--text-muted);
  letter-spacing: 0;
  font-size: 0.78rem;
}
.ledger-date::after { order: 3; }
.lr-abv { display: flex; align-items: center; gap: 8px; }

.lr-name { font-weight: 600; }
.lr-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--gold); }
.lr-link:hover { color: var(--gold); }
.lr-distillery { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }
.lr-meta { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-muted); text-align: right; white-space: nowrap; }

/* ABV liquid-fill bar — the signature element */
.abv-gauge {
  width: 70px;
  height: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.abv-gauge-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--copper), var(--gold-bright));
  border-radius: 999px;
}
.abv-label { font-family: var(--font-mono); font-size: 0.78rem; color: var(--gold); min-width: 42px; text-align: right; }

.empty-state { color: var(--text-muted); padding: 20px 0; font-style: italic; }

/* ---------- Statistik ---------- */
.stat-summary {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.stat-summary .num-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 22px;
  min-width: 140px;
}
.num-card .num { font-family: var(--font-display); font-size: 2rem; color: var(--gold-bright); display: block; }
.num-card .label { color: var(--text-muted); font-size: 0.82rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card.wide { grid-column: 1 / -1; }
.card h3 { font-size: 1.05rem; margin-bottom: 14px; }

.bar-row { display: grid; grid-template-columns: 120px 1fr 34px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.85rem; }
.bar-row .bar-label { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--gold); border-radius: 999px; }
.bar-count { font-family: var(--font-mono); color: var(--text-muted); text-align: right; }

.stat-facts { display: flex; gap: 16px; flex-wrap: wrap; }
.fact {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 0.88rem;
}
.fact strong { color: var(--gold-bright); font-family: var(--font-display); display: block; font-size: 1.1rem; }

/* ---------- Verwalten ---------- */
.login-card {
  max-width: 400px;
  margin: 40px auto;
}
/* Untereinander statt in einer Zeile – nebeneinander wurden Name, Passwort
   und Button in der schmalen Karte zusammengequetscht. */
#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
#login-form input { width: 100%; }
#login-form button { margin-top: 4px; padding: 11px 12px; }
.error { color: #d9695a; font-size: 0.85rem; min-height: 1.2em; margin-top: 8px; }
.muted { color: var(--text-muted); font-size: 0.85rem; }
.hidden { display: none !important; }

.admin-header { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 16px; }
.pill { background: rgba(111, 125, 79, 0.2); color: var(--green); border: 1px solid rgba(111,125,79,0.4); padding: 4px 12px; border-radius: 999px; font-size: 0.8rem; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 20px; }
.admin-area form { display: flex; flex-direction: column; gap: 12px; }
.admin-area form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--text-muted); }
.admin-area form label .muted { font-size: 0.95em; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row > label { flex: 1; min-width: 150px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.mini-list { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; }
.mini-list-item { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--text-muted); border-bottom: 1px solid var(--border); padding: 4px 0; }

/* ---------- Tabellen (Brennereien + Verwalten) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:hover { background: rgba(201, 154, 61, 0.05); }
.data-table .num { text-align: right; font-family: var(--font-mono); }
.data-table .cell-wrap { max-width: 220px; color: var(--text-muted); font-size: 0.8rem; }
.data-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.data-table button { padding: 4px 10px; font-size: 0.78rem; white-space: nowrap; }
.data-table .empty-state { text-align: center; }

.table-scroll { max-height: 60vh; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.table-filter { width: 100%; margin-bottom: 12px; }

.sortable th[data-sort] { cursor: pointer; user-select: none; }
.sortable th[data-sort]:hover { color: var(--text); }
.sortable th.sorted { color: var(--gold); }
.sortable th[data-dir="asc"]::after { content: " ▲"; font-size: 0.7em; }
.sortable th[data-dir="desc"]::after { content: " ▼"; font-size: 0.7em; }

.count-badge { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.8rem; font-weight: 400; }
.result-count { color: var(--text-muted); font-size: 0.82rem; margin: -16px 0 16px; }

/* ---------- Verwalten: Panels + Rückmeldungen ---------- */
.subtabs { margin-right: auto; }
.admin-header { flex-wrap: wrap; justify-content: flex-start; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-panel > .card { margin-bottom: 18px; }

.form-msg { font-size: 0.82rem; align-self: center; }
.form-msg.is-ok { color: var(--green); }
.form-msg.is-error { color: #d9695a; }
.error.is-ok { color: var(--green); }
.btn-danger:hover { color: #d9695a; border-color: #d9695a; }

/* ---------- Weltkarte ---------- */
.map-card { margin-bottom: 24px; }
.map-container { margin-top: 12px; }
.map-container svg { width: 100%; height: auto; display: block; }
.map-container path { stroke: var(--map-stroke); stroke-width: 0.8; }
.country-off { fill: var(--map-land); }
.country-on { cursor: help; stroke: var(--map-stroke); stroke-width: 1.2; }
.country-on:hover { stroke: var(--text); stroke-width: 2; }
.country-on.level-1 { fill: var(--map-1); }
.country-on.level-2 { fill: var(--map-2); }
.country-on.level-3 { fill: var(--map-3); }
.country-on.level-4 { fill: var(--map-4); }
.country-on.level-5 { fill: var(--map-5); }

.map-scale { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 12px; font-size: 0.78rem; color: var(--text-muted); }
.scale-caption { font-weight: 500; }
.scale-step { display: inline-flex; align-items: center; gap: 5px; }
.scale-swatch { width: 16px; height: 12px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; }
.scale-swatch.level-1 { background: var(--map-1); }
.scale-swatch.level-2 { background: var(--map-2); }
.scale-swatch.level-3 { background: var(--map-3); }
.scale-swatch.level-4 { background: var(--map-4); }
.scale-swatch.level-5 { background: var(--map-5); }

/* Zahlenkreise: kleine Laender wie Taiwan oder Irland waeren ueber die
   Flaeche nicht zu erkennen. */
.map-bubbles .bubble {
  fill: var(--map-bubble);
  fill-opacity: 0.92;
  stroke: var(--map-bubble-text);
  stroke-width: 2;
  cursor: help;
}
.map-bubbles .bubble:hover { fill-opacity: 1; }
.map-bubbles .bubble-label {
  fill: var(--map-bubble-text);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}
.map-bubbles .bubble-line { stroke: var(--map-bubble); stroke-width: 1.6; stroke-opacity: 0.6; }

/* Großansicht beim Überfahren */
.zoom-preview {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
}
.zoom-preview img {
  display: block;
  max-width: 320px;
  max-height: 420px;
  border-radius: 6px;
}
.zoomable { cursor: zoom-in; }

.cell-thumb { width: 46px; padding-right: 0 !important; }
.preview-img { max-width: 90px; max-height: 120px; border-radius: 6px; border: 1px solid var(--border); }
.dist-thumb {
  width: 38px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: block;
}

.map-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }
.legend-item b { color: var(--gold); font-family: var(--font-mono); }
.legend-missing em { color: var(--copper); font-style: normal; }

.bars.scroll { max-height: 340px; overflow-y: auto; padding-right: 4px; }

/* ---------- Banner ---------- */
.banner {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 28px;
  border: 1px solid var(--border);
  max-height: 210px;
}
.banner img { width: 100%; height: 210px; object-fit: cover; display: block; }
.banner.banner-slim { max-height: 140px; margin-bottom: 24px; }
.banner.banner-slim img { height: 140px; }
.banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--bg) 2%, rgba(0, 0, 0, 0) 55%);
  opacity: 0.75;
}
.banner-text {
  position: absolute;
  left: 26px;
  bottom: 20px;
  z-index: 1;
}
.banner-text span {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--gold-bright);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

/* ---------- Tortendiagramme ---------- */
.pie-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.pie-svg { width: 200px; height: 200px; flex-shrink: 0; }
.pie-slice { stroke: var(--surface); stroke-width: 1.5; transition: opacity 0.15s; cursor: help; }
.pie-slice:hover { opacity: 0.75; }
.pie-center-num {
  text-anchor: middle;
  font-family: var(--font-display);
  font-size: 26px;
  fill: var(--gold-bright);
}
.pie-center-label { text-anchor: middle; font-size: 10px; fill: var(--text-muted); }
.pie-legend {
  flex: 1;
  min-width: 190px;
  max-height: 210px;
  overflow-y: auto;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pie-legend-item { display: flex; align-items: center; gap: 7px; }
.pie-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.pie-legend-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pie-legend-value { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.72rem; white-space: nowrap; }
.btn-tiny { padding: 2px 8px !important; font-size: 0.72rem !important; margin-left: 8px; font-weight: 400; }

/* Sprungziel aus der Statistik */
.fact-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--gold-bright);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(201, 154, 61, 0.4);
}
.fact-link:hover { text-decoration-color: currentColor; }
.row-highlight > summary { animation: ai-flash 2.5s ease-out; }

footer { text-align: center; color: var(--text-muted); font-size: 0.78rem; padding: 20px; border-top: 1px solid var(--border); }

@media (max-width: 640px) {
  .ledger-row { grid-template-columns: 1fr; gap: 6px; }
  .lr-meta { text-align: left; }
  .table-scroll { max-height: none; }
}
