:root {
  --bg: #0b1220;
  --panel: #111827;
  --panel-2: #172033;
  --text: #eef2f7;
  --muted: #9ca3af;
  --border: #293548;
  --blue: #3b82f6;
  --yellow: #facc15;
  --darkbar: #6b7280;
  --accent: #60a5fa;
  --danger: #f87171;
  --day-width: 54px;
  --axis-width: 92px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, #172554 0, transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px 20px 10px;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
}

.version {
  color: var(--muted);
  font-size: 0.85rem;
}

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 10px 16px 40px;
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
}

.controls {
  display: grid;
  grid-template-columns:
    minmax(260px, 1.3fr)
    minmax(260px, 1fr)
    minmax(220px, 1fr)
    auto;
  gap: 18px;
  align-items: end;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group > label {
  font-weight: 650;
}

.coordinate-grid,
.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.coordinate-grid label,
.date-grid label {
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select,
button {
  min-height: 42px;
  border-radius: 9px;
  border: 1px solid #3a4659;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  color: var(--text);
  background: #0f172a;
}

button {
  padding: 8px 14px;
  cursor: pointer;
  color: var(--text);
  background: #273449;
}

button:hover:not(:disabled) {
  filter: brightness(1.12);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary {
  background: #2563eb;
  border-color: #3b82f6;
  font-weight: 700;
}

.secondary {
  background: #1f2937;
}

.location-line {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  color: #dbe5f2;
}

.summary strong {
  color: #fff;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-bottom: 18px;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.legend-box {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 5px;
  vertical-align: -2px;
  border-radius: 2px;
}

.legend-box.blue {
  background: var(--blue);
}

.legend-box.yellow {
  background: var(--yellow);
}

.legend-box.dark {
  background: var(--darkbar);
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
}

.charts {
  min-width: max-content;
}

.chart-grid {
  display: grid;
  grid-template-columns:
    var(--axis-width)
    repeat(var(--days), var(--day-width));
}

.date-row {
  border-bottom: 1px solid var(--border);
}

.axis-head,
.date-cell {
  min-height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.axis-head {
  color: var(--muted);
  font-size: 0.82rem;
}

.date-cell {
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  border-left: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
}

.date-cell:hover,
.bar-cell:hover,
.free-cell:hover {
  background: rgba(96, 165, 250, 0.08);
}

.date-cell.today {
  background: rgba(59, 130, 246, 0.17);
}

.date-cell .weekday {
  color: var(--muted);
  font-size: 0.7rem;
}

.chart-title-row {
  margin-top: 16px;
}

.chart-title {
  padding: 5px 0 4px;
  font-weight: 700;
}

.axis-spacer {
  border-right: 1px solid var(--border);
}

.plot-row {
  height: 220px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 54px,
      rgba(255,255,255,0.055) 54px,
      rgba(255,255,255,0.055) 55px
    );
}

.axis {
  position: relative;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
}

.axis-label {
  position: absolute;
  right: 9px;
  transform: translateY(50%);
}

.axis-label.top {
  top: -8px;
}

.axis-label.q3 {
  top: 24%;
}

.axis-label.mid {
  top: 49%;
}

.axis-label.q1 {
  top: 74%;
}

.axis-label.bottom {
  bottom: -7px;
}

.bar-cell {
  position: relative;
  display: flex;
  align-items: end;
  justify-content: center;
  cursor: pointer;
  border-left: 1px solid rgba(255, 255, 255, 0.04);
}

.bar {
  width: 62%;
  min-height: 0;
  border-radius: 5px 5px 0 0;
  transition: filter 0.12s ease;
}

.bar.blue {
  background: linear-gradient(to top, #2563eb, #60a5fa);
}

.bar.yellow {
  background: linear-gradient(to top, #ca8a04, #fde047);
}

.bar-value {
  position: absolute;
  top: 5px;
  width: 100%;
  text-align: center;
  color: #dce6f2;
  font-size: 0.66rem;
}

.free-row {
  min-height: 60px;
  border-bottom: 1px solid var(--border);
}

.free-axis {
  display: flex;
  align-items: center;
  padding-right: 9px;
  justify-content: end;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
}

.free-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-left: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.74rem;
}

.free-pill {
  min-width: 42px;
  padding: 5px 4px;
  text-align: center;
  border-radius: 7px;
  background: #374151;
  color: #f3f4f6;
}

.no-darkness {
  color: var(--muted);
}

.scroll-hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.details-panel h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
}

.detail-card {
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.detail-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
}

.detail-value {
  font-weight: 700;
  font-size: 1rem;
}

.error {
  color: var(--danger);
}

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

  .calculate-group {
    align-self: end;
  }

  .details-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  main {
    padding-left: 8px;
    padding-right: 8px;
  }

  .panel {
    padding: 12px;
    border-radius: 10px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .coordinate-grid,
  .date-grid {
    grid-template-columns: 1fr 1fr;
  }

  :root {
    --day-width: 50px;
    --axis-width: 82px;
  }

  .details-grid {
    grid-template-columns: 1fr 1fr;
  }
}


/* =========================================================
   Farbschema + Mondfrei-Balken ab v0.1.3
   Farbblindenfreundlich: Farbe ist nie alleiniger Informationsträger.
   ========================================================= */

:root {
  --blue: #0072B2;
  --yellow: #E69F00;
  --moonfree: #009E73;
  --moonfree-bg: #374151;
}

/* Mondhöhe */
.bar.blue {
  background: linear-gradient(
    to top,
    #005F8F,
    #56B4E9
  );
}

/* Beleuchtung */
.bar.yellow {
  background: linear-gradient(
    to top,
    #B77900,
    #F0C75E
  );
}

/* Legende Mondfrei ebenfalls mit Muster */
.legend-box.dark {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.30) 0,
      rgba(255, 255, 255, 0.30) 3px,
      transparent 3px,
      transparent 7px
    ),
    var(--moonfree);
}

/* Mondfreie Zeit:
   Grau = nicht mondfrei
   Türkis + Schraffur = mondfrei
*/
.free-pill {
  position: relative;
  width: 46px;
  min-width: 46px;

  padding: 6px 3px;

  color: #ffffff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;

  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 7px;

  text-align: center;

  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.95);

  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.28) 0,
      rgba(255, 255, 255, 0.28) 3px,
      transparent 3px,
      transparent 7px
    )
    left / var(--moonfree-percent, 0%) 100%
    no-repeat,

    linear-gradient(
      to right,
      var(--moonfree) 0,
      var(--moonfree) var(--moonfree-percent, 0%),
      var(--moonfree-bg) var(--moonfree-percent, 0%),
      var(--moonfree-bg) 100%
    );
}

.free-cell {
  min-width: var(--day-width);
}


/* ---------- Erweiterte Tagesdetails v0.1.4 ---------- */

.detail-wide {
  grid-column: 1 / -1;
}

.detail-intervals {
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.detail-value small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}


/* =========================================================
   Einstellungen, Standorte und PWA ab v0.2.0
   ========================================================= */

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

.install-button {
  min-height: 36px;
  padding: 6px 11px;
  color: #ffffff;
  background: #005F8F;
  border-color: #56B4E9;
  font-size: 0.82rem;
}

.saved-location-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
}

.location-name-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
}

.location-name-grid input {
  margin-top: 0;
}

.reset-button {
  margin-top: 4px;
  font-size: 0.82rem;
}

.saved-location-grid select {
  margin-top: 0;
}

.location-status {
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 700px) {

  .app-header {
    align-items: flex-start;
  }

  .header-actions {
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 6px;
  }

  .install-button {
    font-size: 0.75rem;
  }

}

@media (max-width: 480px) {

  .saved-location-grid,
  .location-name-grid {
    grid-template-columns: 1fr;
  }

}


/* =========================================================
   Ortssuche + Kalender v0.2.1
   ========================================================= */

.place-search-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
}

.place-search-grid input {
  margin-top: 0;
}

.place-search-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
}

.place-search-results {
  max-height: 270px;
  overflow-y: auto;

  border:
    1px solid
    var(--border);

  border-radius: 10px;

  background: #0f172a;
}

.place-result {
  display: block;

  width: 100%;
  min-height: 0;

  padding: 10px 12px;

  border: 0;
  border-bottom:
    1px solid
    rgba(255, 255, 255, 0.07);

  border-radius: 0;

  text-align: left;

  background: transparent;
}

.place-result:last-child {
  border-bottom: 0;
}

.place-result:hover {
  background:
    rgba(96, 165, 250, 0.12);
}

.place-result-name {
  display: block;
  font-weight: 700;
}

.place-result-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.coordinate-grid-v021 {
  grid-template-columns:
    1fr
    1fr
    minmax(150px, 1.2fr);
}

#targetTimezone {
  color: #cbd5e1;
  cursor: default;
}

.geocoding-attribution {
  color: var(--muted);
  font-size: 0.68rem;
}

.geocoding-attribution a {
  color: #8ecdf0;
}


/* ---------- Datumsanzeige ---------- */

.date-display-button {
  display: block;
  width: 100%;

  margin-top: 4px;
  padding: 8px 10px;

  color: var(--text);
  background: #0f172a;

  border:
    1px solid
    #3a4659;

  text-align: left;

  font-variant-numeric:
    tabular-nums;
}

.date-display-button:hover {
  border-color: #60a5fa;
}

.quick-range-grid {
  display: grid;
  grid-template-columns:
    repeat(3, 1fr);

  gap: 6px;
}


/* ---------- Kalender ---------- */

.date-range-dialog {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);

  padding: 0;

  color: var(--text);
  background: #111827;

  border:
    1px solid
    #344155;

  border-radius: 14px;

  box-shadow:
    0 24px 80px
    rgba(0, 0, 0, 0.55);
}

.date-range-dialog::backdrop {
  background:
    rgba(0, 0, 0, 0.68);

  backdrop-filter:
    blur(3px);
}

.calendar-header {
  display: grid;

  grid-template-columns:
    48px 1fr 48px;

  align-items: center;

  gap: 8px;

  padding: 14px;

  border-bottom:
    1px solid
    var(--border);
}

.calendar-heading {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 750;
}

.calendar-instruction {
  margin-top: 3px;

  text-align: center;

  color: var(--muted);
  font-size: 0.75rem;
}

.calendar-nav {
  min-width: 42px;
  min-height: 42px;

  padding: 0;

  font-size: 1.8rem;
  line-height: 1;
}

.calendar-months {
  display: grid;

  grid-template-columns:
    repeat(2, minmax(280px, 1fr));

  gap: 22px;

  padding: 16px;

  overflow-y: auto;
}

.calendar-month-title {
  margin-bottom: 10px;

  text-align: center;

  font-weight: 750;
}

.calendar-weekdays,
.calendar-days {
  display: grid;

  grid-template-columns:
    repeat(7, 1fr);

  gap: 3px;
}

.calendar-weekdays {
  margin-bottom: 4px;

  color: var(--muted);

  text-align: center;

  font-size: 0.7rem;
}

.calendar-day-placeholder {
  aspect-ratio: 1 / 1;
}

.calendar-day {
  position: relative;

  min-height: 38px;

  padding: 4px;

  color: var(--text);

  background: transparent;

  border:
    1px solid
    transparent;

  border-radius: 8px;

  font-size: 0.82rem;
}

.calendar-day:hover {
  background:
    rgba(96, 165, 250, 0.14);

  border-color:
    rgba(96, 165, 250, 0.45);
}

.calendar-day.today {
  border-color: #56B4E9;
}

.calendar-day.in-range {
  background:
    rgba(0, 114, 178, 0.24);

  border-radius: 0;
}

.calendar-day.range-start,
.calendar-day.range-end {
  color: #ffffff;

  background: #0072B2;

  border-color: #56B4E9;

  border-radius: 8px;

  font-weight: 800;
}

.calendar-day.range-start.range-end {
  border-radius: 8px;
}

.calendar-footer {
  display: flex;

  justify-content: flex-end;

  padding: 12px 16px;

  border-top:
    1px solid
    var(--border);
}


@media (max-width: 700px) {

  .coordinate-grid-v021 {
    grid-template-columns:
      1fr 1fr;
  }

  .coordinate-grid-v021 label:last-child {
    grid-column: 1 / -1;
  }

  .calendar-months {
    grid-template-columns: 1fr;
  }

  .calendar-month:nth-child(2) {
    display: none;
  }

}


@media (max-width: 480px) {

  .place-search-grid {
    grid-template-columns:
      1fr auto;
  }

  .quick-range-grid {
    grid-template-columns:
      repeat(3, 1fr);
  }

  .calendar-months {
    padding:
      12px 8px 16px;
  }

  .calendar-day {
    min-height: 40px;
  }

}


/* =========================================================
   Balken-Beschriftung v0.2.2
   Oberhalb der Balken bleibt immer Platz für den Wert.
   ========================================================= */

.plot-row .bar-cell {
  padding-top: 27px;
}

.plot-row .bar-value {
  top: 4px;
  z-index: 4;
  line-height: 18px;
  font-weight: 700;
  pointer-events: none;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.9);
}


/* =========================================================
   Direkte Navigation v0.2.3
   ========================================================= */

.header-nav-link {
  display: inline-flex;
  align-items: center;

  min-height: 36px;

  padding: 6px 11px;

  color: #eef2f7;
  background: #1f2937;

  border:
    1px solid
    #3a4659;

  border-radius: 9px;

  text-decoration: none;

  font-size: 0.82rem;
}

.header-nav-link:hover {
  border-color: #56B4E9;
  background: #273449;
}


/* =========================================================
   Korrekte Diagrammskalierung ab v0.2.4
   Der Balken nutzt wieder die vollständige Skala 0–100 %
   bzw. 0–90°. Werte stehen in einer separaten Zeile darüber.
   ========================================================= */

.plot-row .bar-cell {
  padding-top: 0;
}

.plot-row .bar-value {
  display: none;
}

.value-row {
  min-height: 28px;
}

.value-axis {
  border-right: 1px solid var(--border);
}

.value-cell {
  display: flex;
  align-items: center;
  justify-content: center;

  min-height: 28px;

  border-left:
    1px solid
    rgba(255, 255, 255, 0.04);

  color: #eef2f7;

  font-size: 0.72rem;
  font-weight: 700;

  font-variant-numeric: tabular-nums;
}


/* =========================================================
   Diagrammbeschriftung v0.2.5

   Die Skala bleibt mathematisch vollständig erhalten:
   100 % = exakt 100er-Linie
   90°   = exakt 90°-Linie

   Die Zahlen stehen in einem separaten Freiraum oberhalb.
   ========================================================= */

.value-row {
  display: none !important;
}


/*
 * 30 Pixel zusätzlicher Freiraum VOR dem eigentlichen Plot.
 * Die eigentliche Plot-Höhe von 220 px wird NICHT verändert.
 */
.plot-row {
  margin-top: 30px;
  overflow: visible;
}


/*
 * Keine künstliche Verkleinerung des Balkenbereichs mehr.
 */
.plot-row .bar-cell {
  padding-top: 0;
  overflow: visible;
}


/*
 * Der Zahlenwert gehört optisch über das Diagramm.
 */
.plot-row .bar-value {
  display: block;

  position: absolute;

  top: -27px;
  left: 0;

  width: 100%;

  z-index: 10;

  color: #eef2f7;

  font-size: 0.72rem;
  font-weight: 750;

  line-height: 22px;

  text-align: center;

  font-variant-numeric: tabular-nums;

  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.95);

  pointer-events: none;
}


/* =========================================================
   Zentrale Astro-Einstellungen v0.4.0
   ========================================================= */

.controls {
  display: none !important;
}

.header-nav-link {
  display: inline-flex;
  align-items: center;

  min-height: 36px;

  padding:
    6px 11px;

  color: #eef2f7;
  background: #1f2937;

  border:
    1px solid
    #3a4659;

  border-radius: 9px;

  text-decoration: none;

  font-size: 0.82rem;
}

.header-nav-link:hover {
  color: #ffffff;

  background: #273449;

  border-color: #56B4E9;
}
