/* ============================================
   ENERGYKLIK - Nordic Industrial Dashboard
   ============================================ */

:root {
  /* Base Colors */
  --bg-primary: #0f1419;
  --bg-secondary: #151b23;
  --bg-card: #1a222d;
  --bg-card-hover: #1f2937;

  /* Text */
  --text-primary: #f0f4f8;
  --text-secondary: #8b9cb3;
  --text-muted: #5c6b7f;

  /* Price States */
  --green-dark: #059669;
  --green-medium: #10b981;
  --green-light: #34d399;
  --grey: #64748b;
  --orange: #f59e0b;
  --red: #ef4444;

  /* Glows */
  --glow-green: rgba(16, 185, 129, 0.4);
  --glow-grey: rgba(100, 116, 139, 0.3);
  --glow-orange: rgba(245, 158, 11, 0.4);
  --glow-red: rgba(239, 68, 68, 0.4);

  /* Accents */
  --accent-blue: #3b82f6;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-active: rgba(255, 255, 255, 0.12);

  /* Sizing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ============================================
   RESET & BASE
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Background texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(16, 185, 129, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================
   APP LAYOUT
   ============================================ */

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-md);
  padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
}

/* ============================================
   HEADER
   ============================================ */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) 0;
  margin-bottom: var(--space-lg);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--green-medium);
  filter: drop-shadow(0 0 8px var(--glow-green));
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--green-medium);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.status-text {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

/* ============================================
   CURRENT PRICE CARD (compact)
   ============================================ */

.current-price-section {
  display: flex;
  justify-content: center;
}

.current-price-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  max-width: 480px;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--grey);
  transition: border-color var(--transition-base);
}

.current-price-card.green-dark,
.current-price-card.green-medium,
.current-price-card.green-light {
  border-left-color: var(--green-medium);
}

.current-price-card.grey {
  border-left-color: var(--grey);
}

.current-price-card.orange {
  border-left-color: var(--orange);
}

.current-price-card.red {
  border-left-color: var(--red);
}

.label-text {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.label-hour {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.price-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.price-unit {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-right: auto;
}

.current-price-indicator {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-xl);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  transition: background var(--transition-base), color var(--transition-base);
  white-space: nowrap;
}

.current-price-card.green-dark .current-price-indicator,
.current-price-card.green-medium .current-price-indicator,
.current-price-card.green-light .current-price-indicator {
  background: rgba(16, 185, 129, 0.15);
  color: var(--green-light);
}

.current-price-card.grey .current-price-indicator {
  background: rgba(100, 116, 139, 0.15);
  color: var(--grey);
}

.current-price-card.orange .current-price-indicator {
  background: rgba(245, 158, 11, 0.15);
  color: var(--orange);
}

.current-price-card.red .current-price-indicator {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

/* ============================================
   STATS SECTION
   ============================================ */

.stats-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.stats-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-left: var(--space-xs);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}

.stats-section-tomorrow {
  margin-top: var(--space-sm);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--transition-fast);
}

.stat-card:hover {
  border-color: var(--border-active);
}

.stat-icon {
  width: 40px;
  height: 40px;
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.stat-icon svg {
  width: 100%;
  height: 100%;
}

.stat-icon-low {
  background: rgba(16, 185, 129, 0.15);
  color: var(--green-medium);
}

.stat-icon-avg {
  background: rgba(100, 116, 139, 0.15);
  color: var(--grey);
}

.stat-icon-high {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

.stat-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ============================================
   HISTOGRAM SECTION
   ============================================ */

.histogram-section {
  flex: 1;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-md);
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.section-date {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Loading state */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-2xl);
  color: var(--text-muted);
  font-size: 0.875rem;
  width: 100%;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-card);
  border-top-color: var(--green-medium);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Loading overlay — fullscreen until data is ready */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  transition: opacity 0.3s ease;
}

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

.loading-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
}

.loading-overlay-icon {
  width: 48px;
  height: 48px;
  color: var(--green-medium);
}

.loading-overlay-text {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Histogram container — scrollable viewport */
.histogram-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--border-active) transparent;
}

.histogram-container::-webkit-scrollbar {
  height: 6px;
}

.histogram-container::-webkit-scrollbar-track {
  background: transparent;
}

.histogram-container::-webkit-scrollbar-thumb {
  background: var(--border-active);
  border-radius: 3px;
}

/* Histogram track — flex row of bars */
.histogram-track {
  display: flex;
  align-items: flex-end;
  height: 220px;
  gap: 2px;
  padding-top: 28px; /* space for "NU" label */
}

/* Bar column */
.bar-column {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 100%;
  justify-content: flex-end;
}

/* "NU" label above current bar */
.bar-now-label {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 2;
}

/* Bar fill */
.bar-fill {
  position: relative;
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: height var(--transition-base);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Bar color states */
.bar-fill.green-dark {
  background: linear-gradient(180deg, var(--green-dark), #047857);
}

.bar-fill.green-medium {
  background: linear-gradient(180deg, var(--green-medium), var(--green-dark));
}

.bar-fill.green-light {
  background: linear-gradient(180deg, var(--green-light), var(--green-medium));
}

.bar-fill.grey {
  background: linear-gradient(180deg, var(--grey), #475569);
}

.bar-fill.orange {
  background: linear-gradient(180deg, var(--orange), #d97706);
}

.bar-fill.red {
  background: linear-gradient(180deg, var(--red), #dc2626);
}

/* Price label inside bar */
.bar-price {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-primary);
  padding-top: 4px;
  white-space: nowrap;
  line-height: 1;
}

/* Short bars: price overflows above */
.bar-fill.short .bar-price {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding-top: 0;
  padding-bottom: 2px;
  color: var(--text-secondary);
}

/* Hour label below bar */
.bar-hour {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
}

/* Current hour highlight */
.bar-column.current .bar-fill {
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Past hours dimmed */
.bar-column.past {
  opacity: 0.5;
}

/* Day separator — vertical line between days */
.day-separator {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
  width: 24px;
  height: 100%;
}

.day-separator::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: calc(100% - 18px);
  background: var(--border-active);
}

.day-separator-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: lowercase;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ============================================
   FOOTER
   ============================================ */

.footer {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-subtle);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-update {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.footer-icon {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

/* ============================================
   ERROR TOAST
   ============================================ */

.toast {
  position: fixed;
  bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--red);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition-base), opacity var(--transition-base);
  z-index: 100;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablets */
@media (max-width: 768px) {
  .stats-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-card {
    flex-direction: column;
    text-align: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
  }

  .stat-icon {
    width: 36px;
    height: 36px;
  }

  .histogram-track {
    height: 200px;
  }

  .bar-column {
    width: 30px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  :root {
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
  }

  .app {
    padding: var(--space-sm);
  }

  .header {
    margin-bottom: var(--space-md);
  }

  .logo-text {
    font-size: 1.1rem;
  }

  .current-price-card {
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
  }

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

  .stats-row {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
  }

  .stats-header {
    font-size: 0.65rem;
  }

  .stat-card {
    padding: var(--space-sm);
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    padding: 6px;
  }

  .stat-value {
    font-size: 0.875rem;
  }

  .stat-label,
  .stat-time {
    font-size: 0.65rem;
  }

  .histogram-track {
    height: 180px;
  }

  .bar-column {
    width: 28px;
  }

  .footer-content {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
