/* ==============================================================
   Dashboard Day/Night Theme - shared, layout-free
   Sonographer in the Making
   Rides on the landing page and every report/tool page.
   Owns: palette variables, the fixed moon/sun toggle, the slider.
   Behavior + palette interpolation live in theme.js.
   ============================================================== */

/* Night is the default palette so the first paint is dark with no
   flash before theme.js confirms the stored preference. The values
   mirror palNight in theme.js. */
:root {
  --bg: #050710;
  --card-bg: #0a0e18;
  --text: #c0c8dd;
  --text-mute: #5a6880;
  --accent: #a0b8d8;
  --accent-dk: #7898c0;
  --border: #182030;
  --soft-1: #101828;
  --soft-2: #141e2e;
}

/* Smooth the palette transition everywhere the variables are used. */
body {
  transition: background-color 0.6s ease, color 0.6s ease;
}

/* ── Theme widget: fixed control cluster, top-right ── */
.sitm-theme {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--card-bg) 78%, transparent);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

/* Celestial toggle - the moon that morphs to a sun. */
.sitm-theme-toggle {
  position: relative;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: none;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  outline: none;
}
.sitm-theme-toggle:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

/* The celestial body itself. Night = pale moon. Day = warm sun. */
.sitm-theme-orb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: #d7deec;
  box-shadow: 0 0 10px rgba(190, 205, 235, 0.55), inset -4px -3px 0 0 rgba(120, 140, 175, 0.0);
  transition: width 0.5s ease, height 0.5s ease, margin 0.5s ease,
              background-color 0.5s ease, box-shadow 0.5s ease;
}
/* Crescent: a shadow disc bites the moon at night. */
.sitm-theme-orb::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card-bg);
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.45s ease, transform 0.45s ease, background-color 0.4s ease;
}
/* Sun rays, hidden at night, fade in toward day. */
.sitm-theme-rays {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(0.6) rotate(-30deg);
  transition: opacity 0.5s ease, transform 0.6s ease;
  pointer-events: none;
}
.sitm-theme-rays span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 5px;
  margin: -2.5px 0 0 -1px;
  border-radius: 2px;
  background: #f2c14e;
  /* JS sets transform: rotate(Ndeg) translateY(-13px) per ray */
}

/* Day state (set by theme.js when v >= 0.5). */
.sitm-theme.is-day .sitm-theme-orb {
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  background: #ffd24a;
  box-shadow: 0 0 14px rgba(255, 196, 74, 0.6);
}
.sitm-theme.is-day .sitm-theme-orb::after {
  opacity: 0;
  transform: scale(0.2);
}
.sitm-theme.is-day .sitm-theme-rays {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Slider - native range, restyled, compact. */
.sitm-theme-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, #0a0e18 0%, var(--accent-dk) 50%, #ffd24a 100%);
  outline: none;
  cursor: grab;
}
.sitm-theme-slider:active { cursor: grabbing; }
.sitm-theme-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--card-bg);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
  cursor: grab;
}
.sitm-theme-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--card-bg);
  cursor: grab;
}

/* Compact on small screens - keep the toggle, shrink the slider. */
@media (max-width: 600px) {
  .sitm-theme { top: 10px; right: 10px; gap: 8px; padding: 6px 10px 6px 8px; }
  .sitm-theme-slider { width: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .sitm-theme,
  .sitm-theme-orb,
  .sitm-theme-orb::after,
  .sitm-theme-rays { transition: none; }
}
