/* === Variables === */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a45;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --border: #2a3a5a;
  --electricity: #4fc3f7;
  --electricity-dim: rgba(79, 195, 247, 0.15);
  --gas: #ffb74d;
  --gas-dim: rgba(255, 183, 77, 0.15);
  --accent: #7c4dff;
  --annotation: #ef5350;
  --loader-bg: rgba(26, 26, 46, 0.95);
}

/* === Reset & Base === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Layout === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* === Loader === */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--loader-bg);
  z-index: 1000;
  transition: opacity 0.4s ease;
}

.loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--electricity);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-text {
  margin-top: 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* === Price Cards === */
.price-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.price-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.price-card--electricity {
  border-top: 3px solid var(--electricity);
}

.price-card--gas {
  border-top: 3px solid var(--gas);
}

.price-card__label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.price-card__value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.price-card--electricity .price-card__value {
  color: var(--electricity);
}

.price-card--gas .price-card__value {
  color: var(--gas);
}

.price-card__unit {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.price-card__period {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Controls === */
.controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
}

.toggle input[type='checkbox'] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.toggle input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input[type='checkbox']:checked::after {
  content: '\2713';
  position: absolute;
  top: -1px;
  left: 2px;
  font-size: 13px;
  color: #fff;
}

.toggle--electricity .toggle__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--electricity);
}

.toggle--gas .toggle__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gas);
}

/* === Chart === */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.chart-container svg {
  width: 100%;
  overflow: visible;
}

/* D3 chart styling */
.axis text {
  fill: var(--text-secondary);
  font-size: 11px;
}

.axis line,
.axis path {
  stroke: var(--border);
}

.axis-label {
  font-size: 12px;
  font-weight: 500;
}

.axis-label--electricity {
  fill: var(--electricity);
}

.axis-label--gas {
  fill: var(--gas);
}

.grid line {
  stroke: var(--border);
  stroke-opacity: 0.3;
}

.grid path {
  stroke: none;
}

.line-electricity {
  fill: none;
  stroke: var(--electricity);
  stroke-width: 2;
}

.line-gas {
  fill: none;
  stroke: var(--gas);
  stroke-width: 2;
}

.area-electricity {
  fill: var(--electricity-dim);
}

.area-gas {
  fill: var(--gas-dim);
}

.dot {
  stroke-width: 1.5;
}

.dot--electricity {
  fill: var(--electricity);
  stroke: var(--bg-card);
}

.dot--gas {
  fill: var(--gas);
  stroke: var(--bg-card);
}

/* Tooltip */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s ease;
  min-width: 160px;
}

.tooltip.visible {
  opacity: 1;
}

.tooltip__date {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.tooltip__label--electricity {
  color: var(--electricity);
}

.tooltip__label--gas {
  color: var(--gas);
}

/* Annotations */
.annotation-line {
  stroke: var(--annotation);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.annotation-label {
  fill: var(--annotation);
  font-size: 10px;
  font-weight: 500;
}

/* Source transition marker */
.source-transition {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

/* === Navigator === */
.navigator-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
}

.navigator-container svg {
  width: 100%;
  overflow: visible;
}

.brush .selection {
  fill: var(--accent);
  fill-opacity: 0.2;
  stroke: var(--accent);
  stroke-width: 1;
}

.brush .handle {
  fill: var(--accent);
  fill-opacity: 0.6;
}

.nav-line-electricity {
  fill: none;
  stroke: var(--electricity);
  stroke-width: 1;
  opacity: 0.6;
}

.nav-line-gas {
  fill: none;
  stroke: var(--gas);
  stroke-width: 1;
  opacity: 0.6;
}

/* === Footer === */
footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* === Error === */
.error-message {
  background: rgba(239, 83, 80, 0.1);
  border: 1px solid rgba(239, 83, 80, 0.3);
  border-radius: 8px;
  padding: 1rem;
  color: var(--annotation);
  text-align: center;
  margin: 2rem 0;
  display: none;
}

.error-message.visible {
  display: block;
}

/* === Responsive === */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.35rem;
  }

  .chart-container {
    padding: 1rem;
  }

  .navigator-container {
    padding: 0.75rem 1rem;
  }

  .price-card__value {
    font-size: 1.5rem;
  }
}
