/* ===========================================
   DESIGN TOKENS
   =========================================== */

:root {
  /* -----------------------------------------
     AIR QUALITY (header background)
     ----------------------------------------- */
  --aq-v-bad: #7058E3;      /* Bardzo zły */
  --aq-bad: #F93822;        /* Zły */
  --aq-moderate: #F98122;   /* Dostateczny */
  --aq-sufficient: #F9C822; /* Umiarkowany */
  --aq-good: #3E9F4D;       /* Dobry */
  --aq-v-good: #3E9F97;     /* Bardzo dobry */
  --header-bg-color: #000;  /* Default until API sets real air-quality color */
  --header-text-color: #ffffff;  /* Default on black; JS may set to #000 for light AQ colors */
  
  /* -----------------------------------------
     TEMPERATURE (concentric circles)
     Scale: <-25°C to >38°C (Warsaw extremes)
     Non-linear mapping: tanh-based, centered on 10°C
     ----------------------------------------- */
  
  /* Gradient colors (cold → hot) */
  --temp-gradient-0: #001f3f;   /* 0% - extreme cold (-25°C) */
  --temp-gradient-15: #0074D9;  /* 15% - cold */
  --temp-gradient-35: #7FDBFF;  /* 35% - cool */
  --temp-gradient-50: #2ECC40;  /* 50% - mild (10°C center) */
  --temp-gradient-70: #FFDC00;  /* 70% - warm */
  --temp-gradient-85: #FF851B;  /* 85% - hot */
  --temp-gradient-100: #FF4136; /* 100% - extreme hot (+38°C) */
  
  /* Legacy discrete colors (kept for compatibility) */
  --temp-freezing: #001f3f;    /* < -10°C */
  --temp-cold: #0074D9;        /* -10°C to 0°C */
  --temp-cool: #7FDBFF;        /* 0°C to 10°C */
  --temp-mild: #2ECC40;        /* 10°C to 20°C */
  --temp-warm: #FFDC00;        /* 20°C to 30°C */
  --temp-hot: #FF4136;         /* > 30°C */
  
  /* Circle styling */
  --temp-circle-opacity: 0.85;
  --temp-center-glow: #FF0000;
  
  /* -----------------------------------------
     TEMPERATURE RING GEOMETRY (11 rings + center)
     Values in rem, ready for SVG rendering
     Based on specification scaled to canvas
     ----------------------------------------- */
  --temp-ring-count: 11;
  
  /* Center (filled circle) */
  --temp-center-radius: 2.12rem;
  
  /* Ring 1-11: radius (r) and stroke-width */
  --temp-ring-1-radius: 2.90rem;
  --temp-ring-1-stroke: 0.68rem;
  
  --temp-ring-2-radius: 4.03rem;
  --temp-ring-2-stroke: 0.61rem;
  
  --temp-ring-3-radius: 5.19rem;
  --temp-ring-3-stroke: 0.53rem;
  
  --temp-ring-4-radius: 6.35rem;
  --temp-ring-4-stroke: 0.53rem;
  
  --temp-ring-5-radius: 7.49rem;
  --temp-ring-5-stroke: 0.43rem;
  
  --temp-ring-6-radius: 8.63rem;
  --temp-ring-6-stroke: 0.40rem;
  
  --temp-ring-7-radius: 9.79rem;
  --temp-ring-7-stroke: 0.33rem;
  
  --temp-ring-8-radius: 10.94rem;
  --temp-ring-8-stroke: 0.26rem;
  
  --temp-ring-9-radius: 12.08rem;
  --temp-ring-9-stroke: 0.23rem;
  
  --temp-ring-10-radius: 13.23rem;
  --temp-ring-10-stroke: 0.13rem;
  
  --temp-ring-11-radius: 14.40rem;
  --temp-ring-11-stroke: 0.10rem;
  
  /* Mapping parameters (Warsaw):
     - Range: -25°C to +38°C (historic extremes)
     - High sensitivity zone: -5°C to +25°C (typical)
     - Center: 10°C (middle of typical range)
     - 2°C change in typical range = visible color shift */
  
  /* -----------------------------------------
     WATER LEVEL (Vistula river line)
     Fixed height bar, position reflects water level
     Non-linear mapping: tanh-based, centered on typical level
     Gradient: stan rzeki (designer) — dark red → red → magenta → violet → blue
     ----------------------------------------- */
  --water-bar-height: 20px;       /* Fixed bar height */
  --water-color-top: #1B0B0D;     /* Gradient start (dark red-black) */
  --water-color-bottom: #5300FF;   /* Gradient end (electric blue-violet) */
  /* Full 7-stop gradient (stan rzeki) — use when bar shows full spectrum */
  --water-gradient-to-bottom: linear-gradient(
    to bottom,
    #1B0B0D 0%,
    #4F0E10 15%,
    #FF0000 35%,
    #FF0055 50%,
    #FF00AA 60%,
    #AA00FF 75%,
    #5300FF 100%
  );
  --water-gradient-to-top: linear-gradient(
    to top,
    #1B0B0D 0%,
    #4F0E10 15%,
    #FF0000 35%,
    #FF0055 50%,
    #FF00AA 60%,
    #AA00FF 75%,
    #5300FF 100%
  );
  --water-min-position: 10%;      /* Min Y position (extreme low) */
  --water-max-position: 90%;      /* Max Y position (flood level) */
  /* Mapping parameters (Vistula Warsaw):
     - Range: 0-800 cm (record low ~15cm, flood ~800cm)
     - High sensitivity zone: 100-250 cm
     - Center: 175 cm (middle of typical range)
     - 5 cm difference should be clearly visible */
  
  /* -----------------------------------------
     PRECIPITATION (bottom gradients)
     ----------------------------------------- */
  --precip-snow: #FFFFFF;
  --precip-rain: #4169E1;         /* Royal blue */
  --precip-heavy: #8A2BE2;        /* Blue violet for heavy */
  --precip-gradient-end: transparent;
  
  /* -----------------------------------------
     SKY / DAY-NIGHT (column backgrounds)
     ----------------------------------------- */
  --sky-dawn: #87CEEB;            /* Light sky blue */
  --sky-day-clear: #00CED1;       /* Turquoise - clear day */
  --sky-day-cloudy: #B0C4DE;      /* Light steel blue */
  --sky-dusk: #DDA0DD;            /* Plum - sunset tones */
  --sky-dusk-red: #CD5C5C;        /* Indian red - red sunset */
  --sky-night: transparent;        /* Show stripes */
  --sky-overcast: #708090;        /* Slate gray */
  
  /* -----------------------------------------
     STRIPES (base pattern)
     Count is fixed, height scales with canvas
     ----------------------------------------- */
  --stripe-light: #FFFFFF;
  --stripe-dark: #000000;
  --stripe-count: 54;           /* 1080/20=54 single stripes (27 white + 27 black) */
  --stripe-opacity: 1;
  --grid-overlay-opacity: 0.8;  /* Black overlay on grid area */
  
  /* -----------------------------------------
     NEWS LABELS (keywords overlay)
     ----------------------------------------- */
  --news-label-bg: #FF0000;
  --news-label-text: #000000;
  --news-label-font: 'Arial Black', sans-serif;
  
  /* -----------------------------------------
     LAYOUT & TIMING
     ----------------------------------------- */
  --header-padding: 2rem;
  --transition-fast: 0.3s;
  --transition-normal: 0.5s;
  --grid-gap: 2px;
  
  /* -----------------------------------------
     CANVAS (timeline board)
     Fixed 16:9 aspect ratio (Full HD base)
     ----------------------------------------- */
  --canvas-max-width: 1920px;
  --canvas-max-height: 1080px;
  --canvas-aspect-ratio: 16 / 9;
  --canvas-margin: 20px;        /* Left/right margin inside canvas */
  --grid-columns: 24;           /* Hour columns (00:00 - 23:00) */
}

/* ===========================================
   BASE STYLES
   =========================================== */

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

body {
  font-family: 'Roboto', sans-serif;
  background-color: #000;
  color: #fff;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Header - independent, full width */
#header {
  width: 100%;
  max-width: var(--canvas-max-width);
  padding: var(--header-padding);
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  background-color: var(--header-bg-color);
  transition: background-color 0.4s ease;
}

.title {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--header-text-color);
}

.date-navigation {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.date-arrow {
  background: none;
  border: none;
  color: var(--header-text-color);
  font-size: 2rem;
  cursor: pointer;
  padding: 0.5rem;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
  line-height: 1;
}

.date-arrow:hover {
  opacity: 1;
}

.date-arrow:active {
  opacity: 0.5;
}

.date-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.date {
  font-size: 2.5rem;
  font-weight: bold;
  opacity: 0.9;
  color: var(--header-text-color);
  min-width: 200px;
  text-align: center;
}

/* Viewport for timeline — on narrow screens it clips the rotated canvas */
.timeline-viewport {
  width: 100%;
}

/* Timeline Canvas - 16:9 aspect ratio, centered on desktop when viewport > max-width */
#timeline {
  position: relative;
  width: 100%;
  max-width: var(--canvas-max-width);
  margin-left: auto;
  margin-right: auto;
  aspect-ratio: var(--canvas-aspect-ratio);
  max-height: var(--canvas-max-height);
  overflow: hidden;
  container-type: inline-size;  /* Enable container queries for child scaling */
}

/* RWD: below this width rotate canvas 90° left so 16:9 lays vertically */
@media (max-width: 480px) {
  html {
    overflow-x: hidden;
    width: 100%;
  }

  body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
  }

  #app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .timeline-viewport {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    align-self: stretch;
    height: calc(100vw * 16 / 9);
    overflow: hidden;
    position: relative;
  }

  #timeline {
    position: absolute;
    width: calc(100vw * 16 / 9);
    height: 100vw;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
  }
}

/* Visualization layers: fade-in when first painted (reduces jarring load) */
.viz-layer-fade {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.viz-layer-fade.ready {
  opacity: 1;
}

/* Stripes - full canvas width, under everything */
/* Layer 1: Base stripes (lowest) */
.stripes-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  background: linear-gradient(
    to bottom,
    var(--stripe-light) 50%,
    var(--stripe-dark) 50%
  );
  background-size: 100% calc(100% / 27);
}

/* Dark overlay on grid area only (dims the stripes in grid, not margins) */
/* Layer 2: Mask overlay */
.grid-overlay {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  z-index: 2;
  background-color: #000;
  opacity: var(--grid-overlay-opacity);
  pointer-events: none;
}

/* Day/Night background layer - shows daylight hours */
/* Layer 3: Day/Night */
.day-night-layer {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 0;  /* No gap - white separators come from hour-column borders */
  pointer-events: none;
  z-index: 3;
  opacity: 0.8;
}

/* Air quality gradient overlay - first 8 stripes */
/* Layer 4: Gradient overlay (above day/night, below timeline-grid stacking context) */
.air-quality-gradient {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  height: calc(100% * 4 / 27);  /* First 4 stripes out of 27 (~14.8%) */
  z-index: 4;
  background: linear-gradient(
    to bottom,
    var(--header-bg-color) 0%,
    rgba(0, 0, 0, 0) 60%
  );
  pointer-events: none;
}

/* Grid sits on top with margins */
/* Layer 5: Grid container */
.timeline-grid {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), 1fr);
  gap: 0;  /* No gap - separators come from border-left on hour-column */
  z-index: 5;
}

.hour-column {
  position: relative;
  border-left: 1px solid rgba(255, 255, 255, var(--grid-opacity, 1));
  background: none !important;  /* No background - overlay on gradient */
  background-color: transparent !important;
  z-index: 8;  /* Above visualizations (7), below news keywords (9) */
  transition: background-color var(--transition-normal) ease, border-color 0.2s ease;
}

/* Layer 8: Hour labels (inside hour-column, same stacking context) */
/* RWD: scale down on narrow canvas so labels don’t overlap */
.hour-label {
  text-align: center;
  font-size: clamp(0.4rem, 0.6cqi, 0.66rem);
  padding: 0.25rem 0;
  background: none !important;  /* No background - overlay on gradient */
  background-color: transparent !important;
  color: rgba(255, 255, 255, var(--grid-opacity, 1));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);  /* Text shadow for readability on gradient */
  position: relative;
  z-index: 8;
  transition: color 0.2s ease, opacity 0.2s ease;
}

/* Hide hour labels when toggled off */
.hour-label.hidden {
  opacity: 0 !important;
}

/* ===========================================
   NEWS KEYWORDS (vertical labels)
   =========================================== */

/* Per-hour cell inside .news-keywords-layer grid */
.news-keywords-container {
  position: relative;
  pointer-events: none;
  overflow: hidden;
}

/* Individual keyword label */
.news-keyword {
  position: absolute;
  background-color: #FF0000;
  color: var(--news-label-text);
  font-family: var(--news-label-font);
  font-size: clamp(0.4rem, 0.8cqi + 1px, 0.85rem + 1px);  /* Scales with canvas width */
  font-weight: bold;
  text-transform: uppercase;
  padding: 0.1em 0.2em;  /* em = relative to own font-size */
  white-space: nowrap;
  transform: rotate(-90deg);
  transform-origin: left top;
  letter-spacing: 0.05em;
  line-height: 1;
  pointer-events: auto;
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  font-size: 1.5rem;
}

/* ===================== */
/* Tuning Panel Styles   */
/* ===================== */
#tuning-container {
  width: 100%;
  max-width: var(--canvas-max-width);
  margin-left: auto;
  margin-right: auto;
  align-self: stretch; /* flex: take full width so panel is visible below canvas */
}

.tuning-panel {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 1rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.85rem;
  border-top: 2px solid #3a3a5e;
}

.tuning-panel-header {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}

.tuning-panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #00ff88;
}

.tuning-panel-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.tuning-section {
  background: #252540;
  border-radius: 8px;
  padding: 1rem;
  min-width: 0;
  overflow: hidden;
}

.tuning-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #3a3a5e;
}

.tuning-section-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: #90CAE5;
}

.tuning-reset-btn {
  background: transparent;
  border: 1px solid #3a3a5e;
  color: #888;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.tuning-reset-btn:hover {
  background: #3a3a5e;
  color: #e0e0e0;
}

.tuning-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-control {
  display: grid;
  grid-template-columns: minmax(100px, auto) 1fr;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-label {
  font-size: 0.75rem;
  color: #aaa;
  cursor: help;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  min-width: 0;
}

.tuning-number-container,
.tuning-color-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-slider {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  background: #3a3a5e;
  border-radius: 2px;
  outline: none;
}

.tuning-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #00ff88;
  border-radius: 50%;
  cursor: pointer;
}

.tuning-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #00ff88;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.tuning-value {
  min-width: 0;
  flex-shrink: 0;
  text-align: right;
  font-family: monospace;
  font-size: 0.75rem;
  color: #00ff88;
  white-space: nowrap;
}

.tuning-color-picker {
  width: 32px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.tuning-hex {
  font-family: monospace;
  font-size: 0.75rem;
  color: #888;
}

.tuning-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #3a3a5e;
}

.tuning-btn {
  background: #3a3a5e;
  border: none;
  color: #e0e0e0;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.tuning-btn:hover {
  background: #4a4a6e;
}

/* Checkbox control */
.tuning-control-checkbox {
  grid-template-columns: 1fr auto;
}

.tuning-checkbox-container {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.tuning-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #00ff88;
}

/* Select control */
.tuning-control-select {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tuning-select-container {
  display: flex;
  align-items: center;
}

.tuning-select {
  background: rgba(255, 255, 255, 0.08);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  max-width: 200px;
}

.tuning-select:focus {
  outline: 1px solid #00ff88;
  border-color: #00ff88;
}

.tuning-select option {
  background: #1a1a2e;
  color: #ccc;
}

/* Gradient control */
.tuning-control-gradient {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-control-gradient .tuning-label {
  margin-bottom: 0.25rem;
}

.tuning-gradient-container {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.tuning-gradient-picker {
  width: 100%;
  min-width: 0;
  min-height: 40px;
}

/* Grapick overrides for dark theme */
.tuning-panel .grp-wrapper {
  background: #252540;
  border: 1px solid #3a3a5e;
  border-radius: 4px;
}

.tuning-panel .grp-handler {
  width: 12px;
  height: 28px;
  margin-top: -4px;
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.tuning-panel .grp-handler-selected {
  border-color: #00ff88;
  box-shadow: 0 0 0 2px rgba(0,255,136,0.3);
}

.tuning-panel .grp-handler-close {
  display: none; /* Hide delete button, double-click to delete */
}

.tuning-panel .grp-preview {
  height: 30px;
  border-radius: 3px;
}
