/* ==========================================================================
   TIMELINE — the Windy-style forecast strip docked to the bottom of every map
   --------------------------------------------------------------------------
   See timeline.js for the why. This sheet only draws it:

     ┌──────────────────────────────────────────────────────────────────────────┐
     │      ┌ อ. 6 ต.ค. · 13:00 ┐                                              │
     │ (▶)  ━━━━━━━━━━━━━━●───────·──────·──────·─────────────  FORECAST [⟲ ตอนนี้]│
     │  วันนี้ │  อ. 6  │  พ. 7  │  พฤ. 8 │  ศ. 9  │  ส. 10 │ อา. 11 │ จ. 12   +15 ชม.     │
     └──────────────────────────────────────────────────────────────────────────┘

   Loaded after each page's own sheet and timemode.css, before theme.css (which must stay
   last). Every colour is a token (theme.js re-skins --accent / --panel / --text), and the
   few literals are the same translucent chrome the neighbouring map controls already use.
   ========================================================================== */

.tl {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 8;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center; column-gap: 14px;
  height: 62px; padding: 0 12px 0 11px;
  background:
    linear-gradient(180deg, rgba(18, 28, 43, 0.9) 0%, rgba(9, 14, 22, 0.93) 100%);
  border: 1px solid var(--border-2); border-radius: 14px;
  box-shadow: 0 18px 44px -20px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px) saturate(1.15); -webkit-backdrop-filter: blur(10px) saturate(1.15);
  color: var(--text); font-family: inherit; font-variant-numeric: tabular-nums;
  user-select: none; -webkit-user-select: none;
}
.tl[hidden], .tl [hidden] { display: none !important; }

/* ------------------------------------------------------------------ play -- */
.tl-play {
  position: relative; width: 38px; height: 38px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
  background: var(--accent); color: #04121a;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent),
              0 8px 18px -8px rgba(0, 0, 0, 0.9);
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.2s ease;
}
.tl-play:hover:not(:disabled) { filter: brightness(1.08); transform: scale(1.04); }
.tl-play:active:not(:disabled) { transform: scale(0.96); }
.tl-play:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.tl-play:disabled { opacity: 0.4; cursor: not-allowed; }
.tl-play svg { width: 17px; height: 17px; fill: currentColor; }
.tl-play .tl-i-pause { display: none; }
.tl.tl-playing .tl-play .tl-i-play { display: none; }
.tl.tl-playing .tl-play .tl-i-pause { display: block; }
.tl.tl-playing .tl-play {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent),
              0 0 22px -2px color-mix(in srgb, var(--accent) 55%, transparent);
}

/* ----------------------------------------------------------------- track -- */
.tl-track {
  position: relative; height: 100%; min-width: 0; cursor: pointer; outline: none;
  touch-action: none; border-radius: 10px;
}
.tl-track:focus-visible { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }
.tl.tl-dragging .tl-track { cursor: grabbing; }
/* everything is laid out against .tl-scale, inset so the knob is never clipped at either end */
.tl-scale { position: absolute; left: 8px; right: 8px; top: 0; bottom: 0; }

/* day segments: equal width, today first. The left edge of each is the midnight line. */
.tl-days { position: absolute; left: 0; right: 0; top: 27px; bottom: 3px; }
.tl-day {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}
.tl-day:first-child { border-left-color: transparent; }
/* 3-hourly ticks under the rail, a longer one at noon */
.tl-day::before {
  content: ""; position: absolute; left: 0; right: 0; top: 11px; height: 3px;
  background: repeating-linear-gradient(90deg,
    rgba(255, 255, 255, 0.2) 0 1px, transparent 1px 12.5%);
}
.tl-day::after {
  content: ""; position: absolute; left: 50%; top: 10px; width: 1px; height: 5px;
  background: rgba(255, 255, 255, 0.3);
}
.tl-day-lbl {
  position: absolute; left: 0; right: 0; bottom: 2px;
  display: flex; justify-content: center; align-items: baseline; gap: 4px;
  font-size: 10.5px; line-height: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; pointer-events: none;
}
.tl-day.tl-today { background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.025)); }
.tl-d-rel { color: var(--accent); font-weight: 700; }
.tl-d-num { color: #cfe0f0; }
.tl-day.tl-day-on .tl-day-lbl { color: #fff; }
.tl-day.tl-day-on .tl-d-num { color: #fff; font-weight: 800; }
.tl-day.tl-day-out .tl-day-lbl { opacity: 0.38; }

/* label density (timeline.js measures the width each day gets) */
.tl-d-rel, .tl-d-dow, .tl-d-num, .tl-d-mon { display: none; }
.tl[data-density="wide"] .tl-d-rel,
.tl[data-density="wide"] .tl-d-dow,
.tl[data-density="wide"] .tl-d-num,
.tl[data-density="wide"] .tl-d-mon { display: inline; }
.tl[data-density="mid"] .tl-d-rel,
.tl[data-density="mid"] .tl-d-num,
.tl[data-density="mid"] .tl-day:not(.tl-today):not(.tl-tomorrow) .tl-d-dow { display: inline; }
.tl[data-density="narrow"] .tl-d-num { display: inline; }
.tl[data-density="narrow"] .tl-today .tl-d-num { color: var(--accent); }

/* the rail */
.tl-rail {
  position: absolute; left: 0; right: 0; top: 33px; height: 4px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.13);
}
/* hours with no forecast: before the issue on the first day, after the last lead */
.tl-na {
  position: absolute; top: -1px; bottom: -1px; border-radius: 3px;
  background: repeating-linear-gradient(135deg,
    rgba(255, 255, 255, 0.07) 0 2px, rgba(0, 0, 0, 0.25) 2px 5px);
}
.tl-fill {
  position: absolute; top: 0; bottom: 0; border-radius: 3px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 45%, transparent), var(--accent));
  box-shadow: 0 0 10px -2px color-mix(in srgb, var(--accent) 70%, transparent);
}
/* the leads the model actually publishes; the hours between are interpolated */
.tl-dots i {
  position: absolute; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 0 0 1px rgba(4, 18, 26, 0.55);
}

/* the wall-clock now */
.tl-nowmark {
  position: absolute; top: 28px; width: 2px; height: 14px; margin-left: -1px;
  border-radius: 1px; background: #fff; opacity: 0.85; pointer-events: auto;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.45);
}
.tl-nowmark::before {
  content: ""; position: absolute; left: -3px; top: -5px;
  border: 4px solid transparent; border-top-color: #fff; border-bottom: 0;
}

/* hover: a hairline on the rail and a quiet bubble naming the hour under the pointer */
.tl-hoverline {
  position: absolute; top: 29px; width: 1px; height: 12px; margin-left: -0.5px;
  background: rgba(255, 255, 255, 0.7); pointer-events: none;
}
.tl-ghost {
  position: absolute; top: 5px; z-index: 3; height: 20px; padding: 0 8px;
  display: inline-flex; align-items: center; white-space: nowrap; pointer-events: none;
  font-size: 11px; font-weight: 600; color: var(--text);
  background: rgba(5, 10, 17, 0.95); border: 1px solid var(--border-2); border-radius: 6px;
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, 0.9);
}
.tl-ghost.tl-ghost-out { color: var(--faint); font-weight: 500; }
.tl-ghost.tl-ghost-same { visibility: hidden; }

/* the playhead: a bubble naming the day + hour, a notch, and the knob on the rail */
.tl-head { position: absolute; top: 0; bottom: 0; width: 0; z-index: 2; pointer-events: none; }
.tl-bubble {
  --tl-notch: 50%;
  position: absolute; left: 0; top: 4px; height: 21px; padding: 0 9px;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  border-radius: 6px; background: var(--accent); color: #04121a;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.01em;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.85);
  /* grabbable: pressing the bubble or the knob drags the playhead from where it is
     (timeline.js), rather than jumping to the hour under the pressed edge */
  pointer-events: auto; cursor: grab;
}
.tl-bubble::after {
  content: ""; position: absolute; left: var(--tl-notch); bottom: -5px; margin-left: -5px;
  border: 5px solid transparent; border-top-color: var(--accent); border-bottom: 0;
}
.tl-b-sep { opacity: 0.55; font-weight: 600; }
.tl-b-time { font-weight: 800; }
.tl-knob {
  position: absolute; left: -7px; top: 28px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  pointer-events: auto; cursor: grab;
}
.tl.tl-dragging .tl-bubble, .tl.tl-dragging .tl-knob { cursor: grabbing; }
.tl-track:hover .tl-knob,
.tl.tl-dragging .tl-knob { transform: scale(1.15); }
.tl.tl-dragging .tl-knob,
.tl-track:focus-visible .tl-knob {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 28%, transparent), 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------- readout -- */
/* width: set by timeline.js to the widest label this forecast can produce, so the track
   beside it never changes width as the hour moves */
.tl-side { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 96px; }
.tl-kind { display: inline-flex; align-items: center; gap: 6px; }
.tl-kind-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.tl-kind-label { font-size: 10px; font-weight: 800; letter-spacing: 0.12em; color: var(--accent); }
.tl-rel {
  max-width: 100%; font-size: 11.5px; font-weight: 600; color: #dbe9f7;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tl-side.tl-k-live .tl-kind-dot { background: var(--good); animation: tl-pulse 1.8s ease-in-out infinite; }
.tl-side.tl-k-live .tl-kind-label { color: var(--good); }
@keyframes tl-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); }
  50% { box-shadow: 0 0 0 4px transparent; }
}

.tl-live {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border-radius: 8px; border: 1px solid var(--border-2); cursor: pointer;
  background: rgba(17, 29, 44, 0.86); color: var(--text);
  font-family: inherit; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tl-live svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tl-live:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tl-live:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tl-live:disabled { opacity: 0.38; cursor: default; }

/* ------------------------------------------------------- empty / inert -- */
.tl-loading {
  position: absolute; left: 0; right: 0; top: -21px; text-align: center;
  font-size: 11px; color: var(--muted);
}
.tl.tl-empty .tl-rail { background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.16), rgba(255,255,255,0.06)); background-size: 200% 100%; animation: tl-shimmer 1.4s linear infinite; }
@keyframes tl-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.tl.tl-disabled .tl-track,
.tl.tl-disabled .tl-side { opacity: 0.32; pointer-events: none; }
.tl.tl-disabled .tl-head { visibility: hidden; }
/* (not `.tl-note`: impact.css already owns that name for the arrival-rail warning) */
.tl-strip-note {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4;
  max-width: calc(100% - 140px); padding: 5px 12px; border-radius: 999px;
  background: rgba(9, 15, 24, 0.94); border: 1px solid var(--border-2);
  font-size: 11.5px; color: #dbe9f7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}

/* ------------------------------------------------------------ narrowing -- */
.tl.tl-compact { column-gap: 10px; }
.tl.tl-compact .tl-side { display: none; }
.tl.tl-tiny .tl-live span { display: none; }
.tl.tl-tiny .tl-live { padding: 0 8px; }

@media (prefers-reduced-motion: reduce) {
  .tl-play, .tl-knob { transition: none; }
  .tl-side.tl-k-live .tl-kind-dot, .tl.tl-empty .tl-rail { animation: none; }
}

/* --------------------------------------------- the map's own bottom chrome -- */
/* MapLibre's corner stacks (zoom, compass, attribution) sit above the strip on every
   screen. Page-specific overlays do the same with `calc(… + var(--tl-space, 0px))` in their
   own sheets; --tl-space is 0px while the strip is hidden, so nothing moves needlessly. */
.tl-host .maplibregl-ctrl-bottom-left,
.tl-host .maplibregl-ctrl-bottom-right { bottom: var(--tl-space, 0px); }
