/* ==========================================================================
   RSB Theme Switch — segmented light/dark control
   --------------------------------------------------------------------------
   Vanilla port of the shadcn "theme-switcher" segmented radio group: a pill
   with circular icon options and a ring indicator that slides between them.

   Markup contract
     <div class="rsb-ts rsb-ts--desktop" data-rsb-theme-switch role="radiogroup">
       <span class="rsb-ts__ind" aria-hidden="true"></span>
       <button class="rsb-ts__opt" role="radio" data-rsb-ts-value="light">…</button>
       <button class="rsb-ts__opt" role="radio" data-rsb-ts-value="dark">…</button>
     </div>

   The controller in includes/script.php keeps --ts-i (active option index) and
   the .is-active / aria-checked state in sync with the "rsb-theme" localStorage
   value ('auto' | 'light' | 'dark').

   Desktop groups expose light + dark only. The mobile app-bar group also
   exposes "system" (auto), which follows the device preference.
   ========================================================================== */

.rsb-ts {
  --ts-opt: 32px;
  --ts-icon: 15px;
  --ts-pad: 3px;
  --ts-i: 0;
  --ts-surface: #ffffff;
  --ts-ring: #e4e4e7;
  --ts-ink: #09090b;
  --ts-idle: #a1a1aa;
  position: relative;
  display: inline-flex;
  align-items: center;
  direction: rtl;
  padding: var(--ts-pad);
  border-radius: 999px;
  background: var(--ts-surface);
  box-shadow: inset 0 0 0 1px var(--ts-ring);
  -webkit-tap-highlight-color: transparent;
}

/* Sliding ring indicator (the motion.div with layoutId).
   A short scale pop on first paint replaces the component's fade-in: animating
   the container's opacity leaves the control composited at a stale alpha inside
   the fixed header, which paints the icons washed out. */
.rsb-ts__ind {
  position: absolute;
  top: var(--ts-pad);
  inset-inline-start: var(--ts-pad);
  width: var(--ts-opt);
  height: var(--ts-opt);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--ts-ring);
  transform: translateX(calc(var(--ts-i) * -1 * var(--ts-opt)));
  transition: transform .55s cubic-bezier(.34, 1.56, .64, 1);
  animation: rsb-ts-ind-pop .5s cubic-bezier(.34, 1.56, .64, 1);
  pointer-events: none;
}

@keyframes rsb-ts-ind-pop {
  from { transform: translateX(calc(var(--ts-i) * -1 * var(--ts-opt))) scale(.5); }
  to   { transform: translateX(calc(var(--ts-i) * -1 * var(--ts-opt))) scale(1); }
}

.rsb-ts__opt {
  position: relative;
  z-index: 1;
  width: var(--ts-opt);
  height: var(--ts-opt);
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ts-idle) !important;
  cursor: pointer;
  transition: color .3s ease;
}
/* Icons follow the option's colour and always use the solid face — the header
   has icon rules (#header .nav-link i, etc.) that would otherwise repaint or
   thin out these glyphs. */
.rsb-ts__opt i {
  font-size: var(--ts-icon);
  font-weight: 900;
  color: inherit !important;
  line-height: 1;
}
.rsb-ts__opt:hover {
  color: var(--ts-ink) !important;
}
.rsb-ts__opt.is-active {
  color: var(--ts-ink) !important;
}
.rsb-ts__opt:focus-visible {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Dark theme — zinc-950 pill, zinc-700 ring, zinc-50 ink */
[data-theme="dark"] .rsb-ts {
  --ts-surface: #09090b;
  --ts-ring: #3f3f46;
  --ts-ink: #fafafa;
  --ts-idle: #71717a;
}

/* Desktop header — sits in the nav row next to the menu */
.rsb-ts--desktop {
  --ts-opt: 30px;
  --ts-icon: 14px;
  vertical-align: middle;
}

/* Mobile app bar — compact, blended into the neumorphic shell */
.rsb-ts--compact {
  --ts-opt: 28px;
  --ts-icon: 13px;
  --ts-pad: 2px;
  --ts-surface: var(--rsb-p-bg, #e0e5ec);
  --ts-ring: rgba(163, 177, 198, .55);
  --ts-ink: var(--rsb-p-text, #3a3a4a);
  --ts-idle: var(--rsb-p-text-muted, #6b7280);
  box-shadow: var(--rsb-p-shadow-sm, 6px 6px 12px rgba(163, 177, 198, .5), -6px -6px 12px rgba(255, 255, 255, .45));
}
.rsb-ts--compact .rsb-ts__ind {
  background: rgba(255, 255, 255, .62);
  box-shadow: inset 0 0 0 1px var(--ts-ring), 0 2px 6px rgba(0, 0, 0, .08);
}
[data-theme="dark"] .rsb-ts--compact {
  --ts-surface: var(--rsb-p-bg-2, #232838);
  --ts-ring: rgba(255, 255, 255, .10);
  --ts-ink: #e0e6f0;
  --ts-idle: #9098b0;
}
[data-theme="dark"] .rsb-ts--compact .rsb-ts__ind {
  background: rgba(255, 255, 255, .07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), 0 2px 6px rgba(0, 0, 0, .35);
}

/* Small phones — keep three options from crowding the app bar */
@media (max-width: 400px) {
  .rsb-ts--compact { --ts-opt: 26px; --ts-icon: 12px; }
}
@media (max-width: 360px) {
  .rsb-ts--compact { --ts-opt: 24px; --ts-icon: 11px; }
}

/* --------------------------------------------------------------------------
   Mobile app-bar layout
   The bar has two explicit zones: controls on the left and brand on the right.
   This prevents the search button from ever entering the logo/title zone.
   These rules live here because this file is loaded after the mobile base CSS.
   -------------------------------------------------------------------------- */
@media (max-width: 1023.98px) {
  .rsb-p-appbar {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 8px;
    align-items: center;
    direction: ltr;
    overflow: hidden;
    box-sizing: border-box;
  }
  .rsb-p-appbar-right {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    min-width: 0;
    flex: none;
    direction: ltr;
  }
  .rsb-p-appbar-left {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    min-width: 0;
    max-width: 100%;
    direction: rtl;
  }
  .rsb-p-appbar-left > div {
    min-width: 0;
    overflow: hidden;
  }
  .rsb-p-appbar-btn {
    flex: 0 0 auto;
  }
  .rsb-ts--compact {
    flex: 0 0 auto;
  }
}

@media (max-width: 380px) {
  .rsb-p-appbar {
    column-gap: 6px;
  }
  .rsb-p-appbar-right {
    gap: 4px;
  }
  .rsb-p-appbar-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    font-size: 15px;
  }
  .rsb-ts--compact {
    --ts-opt: 24px;
    --ts-icon: 11px;
  }
}

@media (max-width: 340px) {
  .rsb-p-appbar-left > div {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rsb-ts__ind { animation: none; transition: none; }
}
