/* ============================================================
   Pegel Österreich — Light, professional theme
   ============================================================ */

:root {
  /* Palette — light, professional, AT-inspired green accent */
  --bg: #f7f8fa;
  --bg-soft: #eef2f0;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e4e8ee;
  --border-strong: #cdd4dc;

  --text: #0d1f2d;
  --text-2: #324353;
  --text-muted: #5e6b78;
  --text-faint: #8a96a3;

  --primary: #0f5132;        /* deep green */
  --primary-2: #145539;
  --primary-soft: #e7f1ec;
  --accent: #22c55e;         /* fresh green accent */
  --accent-2: #16a34a;
  --warn: #eab308;
  --danger: #dc2626;
  --info: #3b82f6;
  --orange: #f97316;

  /* Status colors */
  --st-low: #3b82f6;
  --st-normal: #22c55e;
  --st-elevated: #eab308;
  --st-high: #f97316;
  --st-very-high: #dc2626;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Spacing / radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --shadow-sm: 0 1px 2px rgba(13, 31, 45, .04), 0 1px 3px rgba(13, 31, 45, .05);
  --shadow-md: 0 4px 14px rgba(13, 31, 45, .06), 0 2px 4px rgba(13, 31, 45, .04);
  --shadow-lg: 0 12px 32px rgba(13, 31, 45, .08), 0 4px 8px rgba(13, 31, 45, .04);

  --container-w: 1280px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--text); font-weight: 700; line-height: 1.2; margin: 0 0 .35em; }
h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.4rem, 2.4vw, 2rem); letter-spacing: -.01em; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 1em; color: var(--text-2); }
ul, ol { margin: 0; padding: 0; }

.container { max-width: var(--container-w); margin: 0 auto; padding: 0 24px; }

/* ============ Header ============ */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; gap: 24px;
  height: 64px;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  color: var(--text); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--primary-soft);
  border-radius: var(--r-md);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.brand-sub { font-size: .75rem; color: var(--text-muted); }
.site-nav { display: flex; gap: 20px; margin-left: auto; }
.site-nav a {
  color: var(--text-2); font-size: .9rem; font-weight: 500;
  padding: 6px 0; border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--primary); text-decoration: none; border-bottom-color: var(--accent); }
.header-status {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--text-muted);
  background: var(--surface);
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .55);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ============ Hero ============ */
.hero {
  background:
    radial-gradient(ellipse 800px 400px at 80% -10%, rgba(34, 197, 94, .12), transparent 60%),
    radial-gradient(ellipse 600px 300px at 10% 110%, rgba(15, 81, 50, .08), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 56px 0 64px;
}
.hero-inner { display: grid; grid-template-columns: 1.2fr 1fr; gap: 48px; align-items: center; }
.eyebrow {
  font-size: .75rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent-2); margin: 0 0 14px;
}
.hero-lede { font-size: 1.05rem; color: var(--text-2); max-width: 56ch; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }

.hero-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.hero-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  min-height: 110px;
}
.hero-stat-card .hs-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 8px; }
.hero-stat-card .hs-value { font-size: 1.6rem; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.hero-stat-card .hs-unit { font-size: .85rem; color: var(--text-muted); font-weight: 500; margin-left: 4px; }
.hero-stat-card .hs-sub { font-size: .75rem; color: var(--text-faint); margin-top: 4px; }
.hero-stat-card.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .9rem;
  padding: 10px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer; transition: all .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }

/* ============ Section ============ */
.section { padding: 64px 0; }
.section-grid { background: var(--bg); }
.section-map { background: var(--surface); border-top: 1px solid var(--border); }
.section-sources { background: var(--bg-soft); border-top: 1px solid var(--border); }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 28px; flex-wrap: wrap;
}
.section-sub { color: var(--text-muted); max-width: 70ch; font-size: .95rem; }

/* ============ KPI grid ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-card header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.kpi-label { font-size: .78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi-tag {
  font-size: .68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-muted);
}
.kpi-tag.is-ok { background: rgba(34, 197, 94, .12); color: var(--accent-2); }
.kpi-tag.is-warn { background: rgba(234, 179, 8, .14); color: #a16207; }
.kpi-tag.is-danger { background: rgba(220, 38, 38, .12); color: var(--danger); }
.kpi-tag.is-info { background: rgba(59, 130, 246, .12); color: var(--info); }
.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.8rem; font-weight: 700;
  color: var(--text); letter-spacing: -.02em;
  line-height: 1.1;
}
.kpi-unit { font-size: .8rem; color: var(--text-muted); font-weight: 500; font-family: var(--font-sans); }
.kpi-meta { font-size: .78rem; color: var(--text-faint); margin-top: 6px; }
.kpi-card-wide { grid-column: span 4; }

/* ============ Chart grid ============ */
.chart-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-sm);
}
.chart-card-wide { grid-column: span 3; }
.chart-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.chart-sub { color: var(--text-muted); font-size: .78rem; margin: 2px 0 0; }
.chart-legend { display: flex; gap: 14px; font-size: .75rem; color: var(--text-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-wrap { position: relative; height: 220px; }
.chart-wrap-donut { height: 220px; }
.genmix-list { list-style: none; margin-top: 12px; padding: 0; }
.genmix-list li {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .82rem; padding: 5px 0; border-bottom: 1px dashed var(--border);
}
.genmix-list li:last-child { border-bottom: 0; }
.genmix-list .gm-left { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.genmix-list .gm-swatch { width: 10px; height: 10px; border-radius: 2px; }
.genmix-list .gm-right { font-family: var(--font-mono); font-weight: 600; color: var(--text); }

/* ============ Map section ============ */
.map-toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.select-wrap { display: flex; flex-direction: column; gap: 4px; }
.select-wrap label { font-size: .72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.select-wrap select {
  appearance: none;
  font: inherit; font-size: .85rem;
  padding: 8px 30px 8px 12px;
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235e6b78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 8px center / 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  min-width: 170px;
  cursor: pointer;
}
.select-wrap select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Layout: Sidebar (left) + Map (right). On desktop both columns share the
 * full viewport-tall row; the map fills the available height instead of
 * being a fixed 560 px box (which previously got cut off). */
.map-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: stretch;
  /* The whole row is at least 600 px tall, but grows with viewport on large screens */
  min-height: min(72vh, 720px);
}
.map-sidebar {
  display: flex; flex-direction: column; gap: 14px;
  /* Sidebar scrolls internally if its content is taller than the map */
  max-height: min(72vh, 720px);
  overflow-y: auto;
  /* Hide scrollbar but keep functional */
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  padding-right: 4px;
}
.map-sidebar::-webkit-scrollbar { width: 6px; }
.map-sidebar::-webkit-scrollbar-track { background: transparent; }
.map-sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.legend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.legend-card h3 { margin-bottom: 6px; }
.legend-note { font-size: .8rem; color: var(--text-muted); margin-bottom: 12px; }
.legend-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.legend-list li { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: var(--text-2); }
.legend-list .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

.legend-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.legend-stats div { display: flex; flex-direction: column; gap: 2px; }
.legend-stats span { font-size: .68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.legend-stats strong { font-size: .95rem; color: var(--text); font-family: var(--font-mono); }

.top-list-card h3 { margin-bottom: 8px; }
.top-list { list-style: none; counter-reset: topc; }
.top-list li {
  counter-increment: topc;
  display: grid; grid-template-columns: 22px 1fr auto;
  gap: 8px; align-items: center;
  font-size: .82rem; padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.top-list li:last-child { border-bottom: 0; }
.top-list li::before {
  content: counter(topc);
  font-family: var(--font-mono);
  font-size: .72rem; color: var(--text-muted);
  background: var(--bg-soft);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.top-list .tl-name { color: var(--text); }
.top-list .tl-river { font-size: .72rem; color: var(--text-muted); display: block; }
.top-list .tl-val { font-family: var(--font-mono); font-weight: 600; color: var(--text); }
.top-list .tl-val small { color: var(--text-muted); font-weight: 400; font-family: var(--font-sans); }

.map-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #e9eef3;
  box-shadow: var(--shadow-sm);
  /* Fill the entire grid cell height (matches sidebar height) */
  height: 100%;
  min-height: 560px;
}
/* The leaflet container fills its wrapper. We use position:absolute + inset:0
 * so it tracks the wrapper's height precisely — no clipping, no overflow. */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.map-attribution {
  position: absolute; bottom: 6px; right: 8px;
  background: rgba(255, 255, 255, .85);
  padding: 4px 8px; border-radius: 6px;
  font-size: .7rem; color: var(--text-muted);
  z-index: 500;
}
.map-attribution a { color: var(--primary); }

/* Leaflet popup styling override */
.leaflet-popup-content-wrapper {
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
}
.leaflet-popup-content { margin: 12px 14px; font-family: var(--font-sans); }
.popup-station .ps-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.popup-station .ps-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.popup-station .ps-name { font-weight: 700; font-size: 1rem; color: var(--text); }
.popup-station .ps-river { font-size: .78rem; color: var(--text-muted); margin-bottom: 8px; }
.popup-station .ps-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .82rem; margin-bottom: 8px; }
.popup-station .ps-grid .ps-k { color: var(--text-muted); }
.popup-station .ps-grid .ps-v { font-family: var(--font-mono); font-weight: 600; color: var(--text); }
.popup-station .ps-link { display: inline-block; font-size: .78rem; color: var(--primary); }
.popup-station .ps-tag {
  display: inline-block; font-size: .68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin-left: auto;
}

/* Custom marker (color circle with white border) */
.hydro-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(13, 31, 45, .25), 0 2px 4px rgba(13, 31, 45, .2);
  cursor: pointer;
  transition: transform .15s ease;
}
.hydro-marker:hover { transform: scale(1.4); }
.hydro-marker.is-selected {
  transform: scale(1.6);
  box-shadow: 0 0 0 3px rgba(15, 81, 50, .35), 0 2px 6px rgba(13, 31, 45, .25);
}

/* ============ Sources grid ============ */
.sources-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.source-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.source-card h3 { color: var(--primary); margin-bottom: 8px; }
.source-card p { font-size: .9rem; color: var(--text-2); }
.source-card .source-link { font-size: .82rem; color: var(--text-muted); margin-top: 12px; }

/* ============ Footer ============ */
.site-footer { background: var(--text); color: #cdd4dc; padding: 24px 0; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.footer-brand { color: #fff; font-weight: 700; margin: 0 0 4px; }
.footer-meta { color: #8a96a3; font-size: .8rem; margin: 0; }

/* ============ Responsive ============ */

/* Tablet landscape & smaller desktop: slightly narrower sidebar */
@media (max-width: 1280px) {
  .map-layout {
    grid-template-columns: 280px 1fr;
    min-height: min(68vh, 660px);
  }
  .map-sidebar { max-height: min(68vh, 660px); }
}

/* Tablet portrait: stack map ON TOP, sidebar BELOW */
@media (max-width: 1024px) {
  .hero-inner { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-card-wide { grid-column: span 2; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: span 1; }
  .map-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .map-wrap {
    order: 1;
    height: 60vh;
    min-height: 420px;
  }
  .map-sidebar {
    order: 2;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
    overflow: visible;
  }
  .legend-card { flex: 1 1 280px; }
  .sources-grid { grid-template-columns: 1fr; }
  .site-nav { display: none; }
}

/* Mobile: compact toolbar, taller map, single-column sidebar */
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .section { padding: 44px 0; }
  .hero { padding: 40px 0 48px; }
  .hero-stats { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card-wide { grid-column: span 1; }
  .map-toolbar { width: 100%; gap: 8px; }
  .select-wrap { flex: 1 1 100%; }
  .select-wrap select { min-width: 0; width: 100%; }
  #hydro-refresh { flex: 1 1 100%; justify-content: center; }
  .map-wrap {
    height: 65vh;
    min-height: 360px;
    border-radius: var(--r-md);
  }
  .map-sidebar {
    flex-direction: column;
    flex-wrap: nowrap;
    max-height: none;
    overflow: visible;
  }
  .legend-card { flex: 1 1 auto; }
  .map-attribution {
    font-size: .65rem;
    bottom: 4px; right: 4px;
    padding: 3px 6px;
  }
  .header-status { display: none; }
  .section-head { align-items: flex-start; }
}

/* ============ Loading states ============ */
.is-faded { opacity: .55; }

/* ============ Utility ============ */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
