/* ===================================================
   CWE Power Grid Morning Briefing — Design System
   iOS Stocks-inspired · Dark-mode · Mobile-first
   =================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Backgrounds — iOS pure black + elevated surfaces */
  --bg-primary: #000000;
  --bg-secondary: #1c1c1e;
  --bg-card: #1c1c1e;
  --bg-card-hover: #2c2c2e;
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-tertiary: #2c2c2e;

  /* Accent colors — iOS system palette */
  --positive: #30D158;
  --negative: #FF453A;
  --warning: #FFD60A;
  --accent-gray: #48484a;

  /* Text — iOS label hierarchy */
  --text-primary: #ffffff;
  --text-muted: #8e8e93;
  --text-dim: #636366;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 14px;

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

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

html {
  color-scheme: dark;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--text-primary); text-decoration: none; }

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

.full-width {
  width: 100%;
  min-width: 0;
  margin-bottom: 1rem;
}

.section-header {
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.1rem;
}

.section-subtitle {
  font-size: 0.68rem;
  color: var(--text-muted);
}

main.container {
  padding-top: 0.75rem;
  padding-bottom: 2rem;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--bg-card-border);
  padding: 0.6rem 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.app-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-date {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: rgba(48, 209, 88, 0.1);
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  border: 1px solid rgba(48, 209, 88, 0.18);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--positive);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

.refresh-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--bg-card-border);
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
}

.refresh-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.refresh-btn.spinning {
  animation: spin 0.8s linear infinite;
  pointer-events: none;
}

/* ---------- Cards — iOS elevated surface ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: background var(--transition-base);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.card-title {
  color: var(--text-primary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 0.65rem;
  margin-top: 0.1rem;
}

/* ---------- NRV Traffic Light Timeline ---------- */
.timeline-legend {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-dot.green  { background: var(--positive); }
.legend-dot.yellow { background: var(--warning); }
.legend-dot.red    { background: var(--negative); }

.timeline-container {
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) transparent;
}

.timeline-container::-webkit-scrollbar {
  height: 3px;
}

.timeline-container::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

.timeline-track {
  display: flex;
  flex-direction: row;
  gap: 1.5px;
  align-items: center;
  min-width: max-content;
  padding: 2px 0;
}

.timeline-dot {
  width: 10px;
  height: 24px;
  border-radius: 2px;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  position: relative;
  flex-shrink: 0;
}

.timeline-dot:hover {
  opacity: 0.8;
  transform: scaleY(1.12);
}

.timeline-dot.green      { background: var(--positive); }
.timeline-dot.yellow-pos { background: var(--warning); }
.timeline-dot.yellow-neg { background: var(--warning); opacity: 0.65; }
.timeline-dot.red-pos    { background: var(--negative); }
.timeline-dot.red-neg    { background: var(--negative); opacity: 0.65; }

.timeline-labels {
  position: relative;
  color: var(--text-dim);
  font-size: 0.6rem;
  height: 18px;
  margin-top: 6px;
  min-width: max-content;
}

.timeline-label {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.timeline-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.6rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 10;
  border: 1px solid var(--bg-card-border);
}

.timeline-dot:hover .timeline-tooltip {
  opacity: 1;
}

.nrv-current-state {
  text-align: right;
  flex-shrink: 0;
}

.state-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.state-badge.green {
  background: rgba(48, 209, 88, 0.12);
  color: var(--positive);
  border: 1px solid rgba(48, 209, 88, 0.2);
}

.state-badge.yellow {
  background: rgba(255, 214, 10, 0.12);
  color: var(--warning);
  border: 1px solid rgba(255, 214, 10, 0.2);
}

.state-badge.red {
  background: rgba(255, 69, 58, 0.12);
  color: var(--negative);
  border: 1px solid rgba(255, 69, 58, 0.2);
}

/* ---------- Country Price Cards ---------- */
.country-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.country-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 0.85rem 0.85rem 0.65rem;
  transition: background var(--transition-base);
  min-width: 0;
  overflow: hidden;
}

.country-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.country-flag {
  font-size: 1.2rem;
  line-height: 1;
}

.country-code {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.85rem;
  letter-spacing: 0.03em;
}

.country-price {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.15rem;
  line-height: 1.2;
}

.price-positive { color: var(--positive); }
.price-negative { color: var(--negative); }

.country-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  gap: 0.2rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bg-card-border);
}

.stat-label {
  color: var(--text-dim);
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.stat-value {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.sparkline-container {
  height: 50px;
  width: 100%;
  margin-top: 0.5rem;
}

/* ---------- Profitability Heatmap ---------- */
.profitability-summary {
  margin-bottom: 0.75rem;
}

.summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  min-width: 130px;
  font-size: 0.7rem;
}

.summary-item .label {
  color: var(--text-muted);
}

.summary-item .value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.heatmap-container {
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) transparent;
  min-width: 0;
}

.heatmap-container::-webkit-scrollbar {
  height: 3px;
}

.heatmap-container::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

.heatmap-table {
  border-collapse: separate;
  border-spacing: 1.5px;
}

.heatmap-cell {
  min-width: 16px;
  height: 16px;
  border-radius: 2px;
  cursor: pointer;
  transition: outline-color var(--transition-fast), transform var(--transition-fast);
  font-size: 0;
  outline: 1px solid transparent;
}

.heatmap-cell:hover {
  outline: 1px solid var(--text-primary);
  transform: scale(1.2);
  z-index: 2;
  position: relative;
}

.heatmap-header-cell {
  color: var(--text-dim);
  font-size: 0.5rem;
  text-align: center;
  padding: 1px;
  min-width: 16px;
  font-variant-numeric: tabular-nums;
}

.heatmap-country-label {
  position: sticky;
  left: 0;
  background: var(--bg-card);
  font-weight: 600;
  font-size: 0.7rem;
  padding-right: 6px;
  white-space: nowrap;
  z-index: 1;
  color: var(--text-primary);
}

/* Ensure profitability card doesn't expand beyond viewport */
#profitability-section {
  min-width: 0;
  overflow: hidden;
}

/* ---------- Weather Deltas ---------- */
.delta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.delta-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: background var(--transition-base);
  min-width: 0;
  overflow: hidden;
}

.delta-chart-container {
  height: 180px;
  position: relative;
}

.delta-value.increase { color: var(--positive); }
.delta-value.decrease { color: var(--negative); }
.delta-value.stable   { color: var(--text-muted); }

/* ---------- Generation Forecast Table ---------- */
.gen-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) transparent;
  min-width: 0;
}

.gen-table-container::-webkit-scrollbar {
  height: 3px;
}

.gen-table-container::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

.gen-table {
  width: 100%;
  text-align: left;
  border-collapse: collapse;
}

.gen-table th {
  color: var(--text-dim);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--bg-card-border);
  font-weight: 600;
  white-space: nowrap;
}

.gen-table td {
  padding: 0.4rem 0.5rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

.gen-table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.gen-table tr:last-child td {
  border-bottom: none;
}

.gen-country {
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-primary);
}

.gen-delta-positive {
  color: var(--positive);
  font-weight: 600;
}

.gen-delta-negative {
  color: var(--negative);
  font-weight: 600;
}

/* ---------- Weather Map ---------- */
.map-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.map-btn {
  padding: 5px 14px;
  border-radius: 18px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-base);
  font-size: 0.7rem;
  font-weight: 500;
  font-family: inherit;
}

.map-btn:hover {
  color: var(--text-primary);
  background: var(--accent-gray);
}

.map-btn.active {
  background: rgba(48, 209, 88, 0.15);
  color: var(--positive);
  border-color: rgba(48, 209, 88, 0.3);
}

.map-container {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--bg-card-border);
}

.map-iframe {
  width: 100%;
  height: 300px;
  border: none;
  display: block;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 1rem 0.75rem;
  color: var(--text-dim);
  font-size: 0.65rem;
  margin-top: 1.5rem;
  border-top: 1px solid var(--bg-card-border);
}

.app-footer p {
  margin-bottom: 0.2rem;
}

.app-footer p:last-child {
  margin-bottom: 0;
}

/* ---------- Utility ---------- */
.text-positive { color: var(--positive); }
.text-negative { color: var(--negative); }
.text-warning  { color: var(--warning); }

.hidden {
  display: none !important;
}

.loading-skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    rgba(255, 255, 255, 0.05) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* ---------- Animations ---------- */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.35);
    opacity: 0.45;
  }
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.spinning {
  animation: spin 0.8s linear infinite;
}

.fade-in {
  animation: fadeIn 0.35s ease-out;
}

/* ---------- Responsive ---------- */

/* Very small screens — tighten everything */
@media (max-width: 380px) {
  .country-price {
    font-size: 1.15rem;
  }

  .country-flag {
    font-size: 1rem;
  }

  .country-code {
    font-size: 0.75rem;
  }

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

  .sparkline-container {
    height: 40px;
  }

  .card-title {
    font-size: 0.72rem;
  }

  .gen-table th,
  .gen-table td {
    padding: 0.3rem 0.35rem;
    font-size: 0.65rem;
  }
}

/* 480px+ — slightly larger text */
@media (min-width: 480px) {
  .container {
    padding: 0 1rem;
  }

  .app-title {
    font-size: 1.1rem;
  }

  .section-title {
    font-size: 1rem;
  }

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

  .card {
    padding: 1.15rem;
  }

  .card-title {
    font-size: 0.85rem;
  }

  .country-card {
    padding: 1rem 1rem 0.75rem;
  }

  .sparkline-container {
    height: 55px;
  }
}

/* 768px+ — tablet / landscape */
@media (min-width: 768px) {
  .container {
    padding: 0 1.5rem;
  }

  .country-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }

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

  .map-iframe {
    height: 400px;
  }

  .app-title {
    font-size: 1.2rem;
  }

  .sparkline-container {
    height: 60px;
  }

  .gen-table th,
  .gen-table td {
    padding: 0.5rem 0.65rem;
    font-size: 0.8rem;
  }
}

/* 1024px+ — desktop */
@media (min-width: 1024px) {
  .container {
    padding: 0 2rem;
  }

  .country-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .card {
    padding: 1.35rem;
  }

  .country-card {
    padding: 1.1rem 1.1rem 0.8rem;
  }

  .map-iframe {
    height: 450px;
  }
}

/* ---------- Scrollbar (global) ---------- */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
