:root {
  --bg: #f4f7fa;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #5d6b7a;
  --border: #dde5ec;
  --accent: #1e6fd9;
  --rating-excellent: #1e9e4f;
  --rating-good: #7cb518;
  --rating-marginal: #e8a000;
  --rating-nogo: #d63b2f;
  --shadow: 0 1px 3px rgba(20, 35, 50, 0.08), 0 4px 14px rgba(20, 35, 50, 0.06);
}

* { box-sizing: border-box; }

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

.site-header {
  background: linear-gradient(135deg, #1a4f9c 0%, #2e8bc0 100%);
  color: #fff;
  padding: 2rem 1.5rem 1.6rem;
  text-align: center;
}

.site-header h1 { margin: 0; font-size: 1.9rem; }
.tagline { margin: 0.3rem 0 0; opacity: 0.85; font-size: 0.95rem; }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* --- Suche --- */
.search-section { position: relative; margin-bottom: 1.2rem; }

.search-box { display: flex; gap: 0.5rem; }

.search-box input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.search-box input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.search-box button {
  padding: 0.7rem 1.1rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.search-box button:hover { filter: brightness(1.1); }
#geo-btn { background: var(--card); border: 1px solid var(--border); }

.search-results {
  position: absolute;
  z-index: 10;
  left: 0; right: 0;
  margin: 0.3rem 0 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-results li {
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
}

.search-results li:hover { background: #eef4fb; }
.search-results .result-meta { color: var(--muted); font-size: 0.85rem; }

.favorites {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.fav-toggle {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.fav-toggle:hover { border-color: var(--accent); }

.fav-toggle.saved {
  background: #fff7e0;
  border-color: #f0d890;
  color: #8a6d00;
}

.fav-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 0.3rem;
}

.fav-chip {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--card);
}

.fav-chip.active { border-color: var(--accent); }

.fav-chip .fav-go {
  padding: 0.35rem 0.4rem 0.35rem 0.75rem;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.fav-chip .fav-go:hover { color: var(--accent); }

.fav-chip .fav-del {
  padding: 0 0.6rem 0 0.4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.fav-chip .fav-del:hover { color: var(--rating-nogo); }

.pilot-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.7rem;
  font-size: 0.9rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.pilot-row select {
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}

/* --- Ortsinfo / Status --- */
.location-info {
  margin-bottom: 1rem;
  font-size: 1.05rem;
}
.location-info .elevation { color: var(--muted); font-size: 0.9rem; }

.status {
  padding: 0.8rem 1rem;
  border-radius: 8px;
  background: #fff7e0;
  border: 1px solid #f0d890;
  margin-bottom: 1rem;
}
.status.error { background: #fdeceb; border-color: #f2b3ae; }

/* --- Tageskarten --- */
.days {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}

.day-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
  border-top: 5px solid var(--muted);
}

.day-card:hover { transform: translateY(-2px); }
.day-card.selected { outline: 2px solid var(--accent); }

.day-card.r-excellent { border-top-color: var(--rating-excellent); }
.day-card.r-good      { border-top-color: var(--rating-good); }
.day-card.r-marginal  { border-top-color: var(--rating-marginal); }
.day-card.r-nogo      { border-top-color: var(--rating-nogo); }

.day-card h3 { margin: 0 0 0.4rem; font-size: 1rem; }

.rating-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.rating-badge.r-excellent { background: var(--rating-excellent); }
.rating-badge.r-good      { background: var(--rating-good); }
.rating-badge.r-marginal  { background: var(--rating-marginal); }
.rating-badge.r-nogo      { background: var(--rating-nogo); }

.day-card .day-meta {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.day-card .day-window { font-weight: 600; color: var(--text); }

/* --- Detailansicht --- */
.detail {
  margin-top: 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow);
}

.detail h2 { margin-top: 0; font-size: 1.25rem; }

.assessment {
  padding: 0.9rem 1rem;
  border-radius: 8px;
  background: #f0f5fb;
  margin-bottom: 1rem;
}

.assessment ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }

.hour-table-wrap { overflow-x: auto; }

table.hour-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  white-space: nowrap;
}

.hour-table th, .hour-table td {
  padding: 0.45rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.hour-table th:first-child, .hour-table td:first-child { text-align: left; }
.hour-table th { color: var(--muted); font-weight: 600; }

.score-pill {
  display: inline-block;
  min-width: 2.4rem;
  text-align: center;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
}

.score-pill.r-excellent { background: var(--rating-excellent); }
.score-pill.r-good      { background: var(--rating-good); }
.score-pill.r-marginal  { background: var(--rating-marginal); }
.score-pill.r-nogo      { background: var(--rating-nogo); }

/* Ampelstufen der Bewertungsmatrix (🟢🟡🟠🔴) */
.score-pill.lvl-0 { background: var(--rating-excellent); }
.score-pill.lvl-1 { background: #c9a800; }
.score-pill.lvl-2 { background: #e8731a; }
.score-pill.lvl-3 { background: var(--rating-nogo); }

/* --- Detail: Matrix + Checkliste --- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}

@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.matrix h3, .checklist h3 { margin: 0 0 0.6rem; font-size: 1rem; }
.checklist h4 { margin: 0.9rem 0 0.4rem; font-size: 0.9rem; color: var(--muted); }

.matrix-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  border-left: 4px solid transparent;
  background: #f6f8fb;
  font-size: 0.9rem;
}

.matrix-row.lvl-0 { border-left-color: var(--rating-excellent); }
.matrix-row.lvl-1 { border-left-color: #c9a800; }
.matrix-row.lvl-2 { border-left-color: #e8731a; }
.matrix-row.lvl-3 { border-left-color: var(--rating-nogo); background: #fdf0ef; }

.matrix-row small { color: var(--muted); }

.checklist ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

.checklist li {
  display: flex;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.checklist li small { color: var(--muted); }
.checklist li.check-fail { background: #fdf0ef; border-radius: 6px; padding-left: 0.3rem; }

.manual-checks li {
  border-bottom: none !important;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Startplätze (OpenAIP) --- */
.sites { margin: 0 0 1.2rem; }
.sites h3 { margin: 0 0 0.6rem; font-size: 1rem; }

.sites-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.sites-table th, .sites-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.sites-table th { color: var(--muted); font-weight: 600; }

.dir-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.dir-chip {
  padding: 0.15rem 0.45rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.dir-chip:hover { border-color: var(--accent); }

.dir-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.override-badge {
  font-size: 0.7rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: #eef4fb;
  color: var(--accent);
  border: 1px solid #cfe0f5;
  vertical-align: middle;
}

.sites-note { color: var(--muted); font-size: 0.82rem; margin: 0.5rem 0 0; }

/* --- Emagramm / Sounding --- */
.sounding { margin: 0 0 1.2rem; }
.sounding h3 { margin: 0 0 0.6rem; font-size: 1rem; }

.sounding-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.sounding-controls select {
  padding: 0.35rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}

.sounding button {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
}

.sounding button:hover { background: #eef4fb; }

#emagram-plot {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 0.5rem;
}

#emagram-verdict { font-weight: 600; color: var(--text); }

/* --- Textwetter-Briefing --- */
.briefing {
  margin: 0 0 1.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f6f8fb;
}

.briefing summary {
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}

.briefing-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0 0.9rem 0.6rem;
  flex-wrap: wrap;
}

.briefing-actions button {
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
}

.briefing-actions button:hover { background: #eef4fb; }

/* Gerenderte Briefing-Ansicht – Dokument-Look */
.briefing-html {
  margin: 0;
  padding: 1.1rem 1.4rem 1.4rem;
  border-top: 1px solid var(--border);
  background: var(--card);
  border-radius: 0 0 8px 8px;
  font-size: 0.92rem;
  line-height: 1.55;
}

.briefing-html h1 {
  margin: 0 0 0.3rem;
  font-size: 1.25rem;
  color: #1a4f9c;
}

/* Meta-Zeile direkt unter dem Titel (Datum/Modell/Koordinaten) */
.briefing-html h1 + p {
  color: var(--muted);
  font-size: 0.85rem;
  border-bottom: 2px solid #1a4f9c;
  padding-bottom: 0.7rem;
}

.briefing-html h2 {
  margin: 1.6rem 0 0.5rem;
  font-size: 1.08rem;
  color: #1a4f9c;
}

.briefing-html h3 {
  margin: 1.4rem 0 0.45rem;
  font-size: 0.98rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.briefing-html p { margin: 0.4rem 0; }
.briefing-html em { color: var(--muted); }

.briefing-html ul {
  margin: 0.3rem 0 0.7rem;
  padding-left: 1.25rem;
}

.briefing-html li { margin: 0.15rem 0; }

.briefing-html table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 0.8rem;
  font-size: 0.86rem;
}

.briefing-html th, .briefing-html td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.briefing-html thead th {
  background: #eef3f9;
  font-weight: 600;
}

.briefing-html tbody tr:nth-child(even) { background: #f7fafd; }

.briefing-html code {
  background: #eef2f7;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.wind-dir { display: inline-block; font-size: 1rem; }

/* --- Footer --- */
.site-footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.disclaimer {
  background: #fdf3e3;
  border: 1px solid #eedcb6;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
}

@media (max-width: 600px) {
  .days { grid-template-columns: 1fr 1fr; }
  .site-header h1 { font-size: 1.5rem; }
}

/* --- Inline-Hilfe: Help-Icon-Button --- */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  margin-left: 0.3em;
  padding: 0;
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.12s, background 0.12s;
  flex-shrink: 0;
}

.help-icon:hover,
.help-icon:focus-visible {
  opacity: 1;
  background: var(--accent);
  color: #fff;
  outline: none;
}

/* --- Inline-Hilfe: Popover --- */
.help-popover {
  position: absolute;
  z-index: 200;
  width: 360px;
  max-width: calc(100vw - 1rem);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow), 0 8px 30px rgba(20,35,50,0.14);
  padding: 0.85em 1em;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text);
}

.help-popover[hidden] { display: none; }

.help-popover h4 {
  margin: 0.8em 0 0.3em;
  font-size: 0.88rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.2em;
}

.help-popover h4:first-child { margin-top: 0; }

.help-popover p { margin: 0.35em 0; }

.help-popover ul {
  margin: 0.3em 0 0.5em;
  padding-left: 1.2em;
}

.help-popover li { margin: 0.15em 0; }

.help-popover pre {
  background: #f0f4f8;
  border-radius: 6px;
  padding: 0.5em 0.7em;
  font-size: 0.82em;
  overflow-x: auto;
  margin: 0.4em 0;
}

.help-popover table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84em;
  margin: 0.4em 0 0.6em;
}

.help-popover th,
.help-popover td {
  border: 1px solid var(--border);
  padding: 0.3em 0.5em;
  text-align: left;
  vertical-align: top;
}

.help-popover thead th {
  background: #eef3f9;
  font-weight: 600;
}

.help-popover tbody tr:nth-child(even) { background: #f7fafd; }

/* Callouts */
.help-callout {
  border-left: 3px solid var(--accent);
  padding: 0.45em 0.7em;
  margin: 0.45em 0;
  border-radius: 0 6px 6px 0;
  background: #f6f8fb;
  font-size: 0.9em;
}

.help-callout-title {
  display: block;
  margin-bottom: 0.2em;
  font-size: 0.9em;
}

.help-callout-warning  { border-left-color: var(--rating-marginal); background: #fffbf0; }
.help-callout-danger   { border-left-color: var(--rating-nogo);     background: #fdf0ef; }
.help-callout-info     { border-left-color: var(--accent); }
.help-callout-tip      { border-left-color: var(--rating-excellent); background: #f0faf3; }
.help-callout-success  { border-left-color: var(--rating-excellent); background: #f0faf3; }
.help-callout-important { border-left-color: #8b5cf6; background: #f5f0ff; }
.help-callout-example  { border-left-color: var(--muted); }
.help-callout-abstract { border-left-color: var(--accent); }
.help-callout-note     { border-left-color: var(--accent); }

.help-formula {
  font-family: ui-monospace, "Cascadia Code", "Fira Mono", monospace;
  font-size: 0.88em;
  background: #f0f4f8;
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

.help-skeleton,
.help-error {
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

@media (max-width: 600px) {
  .help-popover {
    left: 0.5rem !important;
    right: 0.5rem !important;
    width: auto !important;
    max-width: none !important;
  }
}
