@charset "UTF-8";
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=Outfit:wght@400;500;600;700&display=swap');

/* ═══════════════════════════════════════
   THEME — haStrom Energy Dashboard
   Inspired by web2.stwhas.de brand
   ═══════════════════════════════════════ */
:root {
  /* Brand — Official Stadtwerk Haßfurt Colors */
  --brand: #941443;
  --brand-dark: #6c1130;
  --brand-deep: #471022;
  --brand-gray: #4e6475;
  --brand-gray-dark: #354351;

  /* Surfaces — Dark (default) */
  --bg-base: #1d222a;
  --bg-surface: #242a33;
  --bg-elevated: #2d333b;
  --bg-hover: #354351;
  --border: #4e6475;
  --border-subtle: #354351;

  /* Text */
  --text-primary: #e2e8f0;
  --text-secondary: #a8b2bd;
  --text-muted: #7d8590;

  /* Accent — brand wine red */
  --accent: #941443;
  --accent-hover: #b41a52;
  --accent-glow: rgba(148, 20, 67, 0.12);

  /* Prices */
  --price-low: #2ea043;
  --price-mid: #d29922;
  --price-high: #cf222e;
  --price-very-high: #8b0000;
  --price-negative: #1f9eba;

  /* Now indicator */
  --now-bg: rgba(148, 20, 67, 0.10);

  /* Fonts — Avenir-like via Outfit */
  --font-body: 'Avenir', 'Outfit', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Menlo', monospace;

  /* Sizing */
  --radius: 6px;
  --radius-lg: 12px;
  --radius-pill: 100px;
  --toolbar-height: 56px;
}

/* ═══════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ═══════════════════════════════════════
   TOOLBAR
   ═══════════════════════════════════════ */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--toolbar-height);
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-group:last-child {
  margin-left: auto;
}

/* Icon Buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}
.icon-btn svg { width: 18px; height: 18px; }

/* Segment Control (Resolution & View Toggle) */
.segment-control {
  display: inline-flex;
  background: var(--bg-base);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.segment-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.segment-btn:hover { color: var(--text-primary); }
.segment-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(148, 20, 67, 0.3);
}
.segment-btn svg { width: 14px; height: 14px; }

/* Date Picker Input */
.date-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.date-input-wrap svg {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--accent);
  pointer-events: none;
}
.date-input {
  width: 140px;
  padding: 6px 10px 6px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.date-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══════════════════════════════════════
   PRICE TABLE
   ═══════════════════════════════════════ */
.table-wrap {
  padding: 0 0 16px;
}

.price-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.price-table thead th {
  position: sticky;
  top: var(--toolbar-height);
  z-index: 10;
  padding: 10px 16px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: right;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.price-table thead th:first-child { text-align: left; }

.price-table tbody tr {
  transition: background 0.1s;
}
.price-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
.price-table tbody tr:hover {
  background: var(--bg-hover);
}

.price-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: right;
  white-space: nowrap;
}
.price-table td:first-child {
  text-align: left;
  color: var(--text-secondary);
}

/* Price cells with mono font */
.price-table .price {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
}
.price-table .unit {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
  margin-left: 4px;
}

/* Time cell */
.price-table .time-cell {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.price-table .time-cell .date-part {
  color: var(--text-muted);
  margin-right: 4px;
}

/* Status indicator — border-right on last cell */
.price-table .status-border {
  border-right: 3px solid transparent;
}

/* Now indicator — clearly visible current time slot */
.price-table tr.is-now td {
  background: rgba(148, 20, 67, 0.15);
  border-top: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  color: var(--text-primary);
}

/* ═══════════════════════════════════════
   INFO CARD
   ═══════════════════════════════════════ */
.info-card {
  margin: 24px 16px;
  padding: 20px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.info-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.info-card h2 svg { width: 16px; height: 16px; color: var(--accent); }

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 20px;
  font-size: 0.85rem;
}
.info-grid dt {
  color: var(--text-secondary);
  font-weight: 500;
}
.info-grid dd {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.info-grid .example {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════
   CHART
   ═══════════════════════════════════════ */
.chart-container {
  width: 100%;
  height: calc(100vh - var(--toolbar-height) - 40px);
  min-height: 400px;
  padding: 16px;
}

/* ═══════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════ */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 20px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(148, 20, 67, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(46, 160, 67, 0.04) 0%, transparent 60%),
    var(--bg-base);
}

.landing-header {
  text-align: center;
  margin-bottom: 48px;
}
.landing-logo {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.landing-title {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.landing-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-top: 8px;
}

.tariff-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  max-width: 700px;
  width: 100%;
}

.tariff-card {
  position: relative;
  padding: 32px 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all 0.25s ease;
  overflow: hidden;
}
.tariff-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.tariff-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.tariff-card .features {
  list-style: none;
  margin-bottom: 24px;
}
.tariff-card .features li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 4px 0;
}
.tariff-card .features li svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.tariff-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: transparent;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  border: 2px solid var(--text-primary);
  border-radius: var(--radius);
  transition: all 0.2s;
}
.tariff-link:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateX(2px);
}
.tariff-link svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════
   LOADING & ERROR STATES
   ═══════════════════════════════════════ */
.loading-msg, .error-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}
.error-msg { color: var(--price-high); }
.error-msg svg { width: 32px; height: 32px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ═══════════════════════════════════════
   FLATPICKR OVERRIDES
   ═══════════════════════════════════════ */
.flatpickr-calendar {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4) !important;
  font-family: var(--font-body) !important;
}
.flatpickr-day {
  color: var(--text-primary) !important;
  border-radius: var(--radius) !important;
}
.flatpickr-day:hover {
  background: var(--bg-hover) !important;
  border-color: transparent !important;
}
.flatpickr-day.selected {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}
.flatpickr-day.today {
  border-color: var(--accent) !important;
}
.flatpickr-day.flatpickr-disabled {
  color: var(--text-muted) !important;
}
.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months {
  background: transparent !important;
  color: var(--text-primary) !important;
}
.flatpickr-current-month input.cur-year {
  color: var(--text-primary) !important;
}
span.flatpickr-weekday {
  color: var(--text-muted) !important;
  font-weight: 500 !important;
}
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  fill: var(--text-secondary) !important;
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
  fill: var(--accent) !important;
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */
@media (max-width: 768px) {
  :root { font-size: 14px; }

  .toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
  }
  .toolbar-group:first-child,
  .toolbar-group:last-child {
    order: 1;
  }
  .toolbar-center {
    order: 2;
    width: 100%;
    justify-content: center;
    padding-bottom: 4px;
  }

  .price-table { font-size: 0.82rem; }
  .price-table td,
  .price-table thead th { padding: 6px 10px; }

  .info-card { margin: 16px 8px; padding: 16px; }
  .info-grid { font-size: 0.8rem; gap: 4px 12px; }

  .chart-container { height: 60vh; }

  .landing-title { font-size: 1.8rem; }
  .tariff-cards { grid-template-columns: 1fr; }

  .toolbar-center {
    position: static;
    transform: none;
  }
}

/* ═══════════════════════════════════════
   LIGHT THEME
   ═══════════════════════════════════════ */
:root[data-theme="light"] {
  --bg-base: #f7f7f8;
  --bg-surface: #ffffff;
  --bg-elevated: #f0f0f2;
  --bg-hover: #e9e9ec;
  --border: #d0d0d6;
  --border-subtle: #e4e4e8;

  --text-primary: #1a1a2e;
  --text-secondary: #4a4a5a;
  --text-muted: #6b6b7a;

  --accent: #941443;
  --accent-hover: #6c1130;
  --accent-glow: rgba(148, 20, 67, 0.08);

  --price-low: #1a7f37;
  --price-mid: #9a6700;
  --price-high: #cf222e;
  --price-very-high: #82071e;
  --price-negative: #0969da;

  --now-bg: rgba(148, 20, 67, 0.08);
}

/* Light theme flatpickr */
:root[data-theme="light"] .flatpickr-calendar {
  background: var(--bg-surface) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
}

/* Light theme segment */
:root[data-theme="light"] .segment-btn.active {
  background: var(--brand);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Light landing gradient */
:root[data-theme="light"] .landing {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(148, 20, 67, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(26, 127, 55, 0.03) 0%, transparent 60%),
    var(--bg-base);
}

/* Light theme title */
:root[data-theme="light"] .landing-title {
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--brand) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Light flatpickr selected uses brand */
:root[data-theme="light"] .flatpickr-day.selected {
  background: #941443 !important;
  border-color: #941443 !important;
}
:root[data-theme="light"] .flatpickr-day.today {
  border-color: #941443 !important;
}

/* Theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.theme-toggle:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.theme-toggle svg { width: 18px; height: 18px; }
