/* ============================================================================
   controls.css — custom checkbox / radio / mode-rail designs
   ----------------------------------------------------------------------------
   Adapted from the design drafts in /static:
     • new_principal_check_box.html   → Eclipse switch (default, green when ON)
     • new_radio_buttons_vertical_choice.html → Blade radio cards (vertical radio groups)
     • Dense/smaller spots (chat-settings menu toggles, RAG master toggles,
       deep-search, STARTTLS, store multi-select, admin row checks) use a plain
       styled checkbox: a small rounded box that fills themed-green with a white
       checkmark when checked.

   All tokens follow the app palette: dark = deep green + pale mint (--neon),
   light = cream + brand green (#1b6b4a). The ON state uses the themed green
   (--ctl-green) — clearly green, discreet, no neon halo. Sizes are tuned to
   the app's compact rows.
   ============================================================================ */

/* ---------------- Theme tokens ---------------- */
/* Color values follow the original design drafts in /static
   (new_principal_check_box.html, new_checkbox_more_square_line_...,
   new_check_box_rounded_and_square_clear.html): a matte/black track when ON
   with a true green (#00ff66) accent — not the pale mint that read as
   "crazy bright" against the theme. */
:root {
  --ctl-track-off: #1a1a1a;
  --ctl-track-on: #000000;
  --ctl-knob-off: #ffffff;
  --ctl-knob-on: #ffffff;
  --ctl-core: #00ff66;
  --ctl-green: #1f8a5f; /* themed ON green (eclipse track + checkbox fill) */
  --ctl-focus: #00ff66;
  --ctl-check-border: rgba(206, 223, 205, 0.35);
  --ctl-check-mark: #ffffff;
  --ctl-radio-text: #555555;
  --ctl-radio-text-on: #ffffff;
  --ctl-rail-track: rgba(206, 223, 205, 0.07);
  --ctl-rail-edge: rgba(206, 223, 205, 0.16);
  --ctl-rail-puck: linear-gradient(180deg, #16432f, #0c241a);
}
html[data-theme-appearance="light"] {
  --ctl-track-off: #e3ded6;
  --ctl-track-on: #1a1918;
  --ctl-knob-off: #ffffff;
  --ctl-knob-on: #ffffff;
  --ctl-core: #00ff66;
  --ctl-green: #1b6b4a; /* themed ON green (brand green in light mode) */
  --ctl-focus: #00ff66;
  --ctl-check-border: rgba(27, 107, 74, 0.40);
  --ctl-check-mark: #ffffff;
  --ctl-radio-text: #8a8580;
  --ctl-radio-text-on: #ffffff;
  --ctl-rail-track: rgba(27, 107, 74, 0.08);
  --ctl-rail-edge: rgba(27, 107, 74, 0.22);
  --ctl-rail-puck: linear-gradient(180deg, #1b6b4a, #155636);
}

/* ============================================================================
   1) ECLIPSE SWITCH — the principal checkbox design
   ----------------------------------------------------------------------------
   Applied to every checkbox in the app. The native control is hidden with
   appearance:none and redrawn as an oval track (input itself) + sliding ring
   (::before) + glowing eclipse core (::after). All form semantics, :checked,
   :disabled and validation keep working because we never remove the input.
   ============================================================================ */
input[type="checkbox"] {
  --ctl-w: 42px;
  --ctl-h: 24px;
  --ctl-knob: 18px;
  --ctl-gap: 3px;
  --ctl-core: 8px;

  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: var(--ctl-w) !important;
  height: var(--ctl-h) !important;
  margin: 0 !important;
  flex: 0 0 auto;
  align-self: center;
  vertical-align: middle;
  position: relative;
  box-sizing: border-box;
  border: none;
  border-radius: 999px;
  background: var(--ctl-track-off);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.30);
  cursor: pointer;
  padding: 0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

input[type="checkbox"]::before {
  content: "";
  position: absolute;
  width: var(--ctl-knob);
  height: var(--ctl-knob);
  left: var(--ctl-gap);
  top: 50%;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--ctl-knob-off);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55),
    background-color 0.3s ease;
  z-index: 1;
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: var(--ctl-core);
  height: var(--ctl-core);
  left: calc(var(--ctl-gap) + (var(--ctl-knob) - var(--ctl-core)) / 2);
  top: 50%;
  transform: translateY(-50%) scale(0);
  border-radius: 50%;
  background: var(--ctl-core);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.25s ease;
  z-index: 2;
}

input[type="checkbox"]:checked {
  /* Themed-green fill — clearly green, no bright halo. */
  background: var(--ctl-green);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
}

input[type="checkbox"]:checked::before {
  transform: translateY(-50%)
    translateX(calc(var(--ctl-w) - var(--ctl-knob) - 2 * var(--ctl-gap)));
  background: var(--ctl-knob-on);
  box-shadow: none;
}

input[type="checkbox"]:checked::after {
  opacity: 1;
  transform: translateY(-50%)
    translateX(calc(var(--ctl-w) - var(--ctl-knob) - 2 * var(--ctl-gap)))
    scale(1);
  /* Small themed-green core dot on the white knob — no glow. */
  background: var(--ctl-green);
  box-shadow: none;
}

input[type="checkbox"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: saturate(0.5);
}

input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--ctl-focus);
  outline-offset: 3px;
}

/* The original draft (new_principal_check_box.html) hides the glowing eclipse
     core in light mode — the switch becomes a plain green track with a white
     knob only. */
html[data-theme-appearance="light"] input[type="checkbox"]:not([name="item-store"]):not(.users-row-check):not(.tasks-row-check):not(#users-select-all-visible):not(#tasks-select-all-visible):not(.dd-item.toggle-row input[type="checkbox"]):not(.deep-search-form-check input[type="checkbox"]):not(#rag-docs-toggle):not(#rag-globally-enabled):not(#deep-search-autorefresh):not(#mailbox-modal-starttls-input)::after {
  background: transparent;
  box-shadow: none;
}

/* ============================================================================
   2) NORMAL CHECKBOX — simple styled checkbox for dense/smaller spots
   ----------------------------------------------------------------------------
   Replaces the earlier split/blade switch experiments: the chat-settings menu
   toggles (TTS/STT/RAG/file-gen capability rows), RAG master toggles, the
   deep-search dialog + auto-refresh toggles, the mailbox STARTTLS toggle, the
   store multi-select and the admin table row checks all use a plain, clearly
   usable checkbox: a small rounded box that fills themed-green with a white
   checkmark when checked. Native click / :checked / label semantics intact.
   ============================================================================ */
.dd-item.toggle-row input[type="checkbox"],
#rag-docs-toggle,
#rag-globally-enabled,
#deep-search-autorefresh,
#mailbox-modal-starttls-input,
.deep-search-form-check input[type="checkbox"],
input[name="item-store"],
input[type="checkbox"].users-row-check,
input[type="checkbox"].tasks-row-check,
#users-select-all-visible,
#tasks-select-all-visible,
.users-bulk-checklist-body .inline-check input[type="checkbox"] {
  --ctl-w: 18px;
  --ctl-h: 18px;
  --ctl-knob: 0px;
  --ctl-core: 0px;
  border-radius: 5px;
  border: 1px solid var(--ctl-check-border);
  background: var(--ctl-track-off);
  box-shadow: none;
}

.dd-item.toggle-row input[type="checkbox"]::before,
#rag-docs-toggle::before,
#rag-globally-enabled::before,
#deep-search-autorefresh::before,
#mailbox-modal-starttls-input::before,
.deep-search-form-check input[type="checkbox"]::before,
input[name="item-store"]::before,
input[type="checkbox"].users-row-check::before,
input[type="checkbox"].tasks-row-check::before,
#users-select-all-visible::before,
#tasks-select-all-visible::before,
.users-bulk-checklist-body .inline-check input[type="checkbox"]::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 10px;
  border: solid var(--ctl-check-mark);
  border-width: 0 2px 2px 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s ease;
  z-index: 2;
}

.dd-item.toggle-row input[type="checkbox"]:checked,
#rag-docs-toggle:checked,
#rag-globally-enabled:checked,
#deep-search-autorefresh:checked,
#mailbox-modal-starttls-input:checked,
.deep-search-form-check input[type="checkbox"]:checked,
input[name="item-store"]:checked,
input[type="checkbox"].users-row-check:checked,
input[type="checkbox"].tasks-row-check:checked,
#users-select-all-visible:checked,
#tasks-select-all-visible:checked,
.users-bulk-checklist-body .inline-check input[type="checkbox"]:checked {
  background: var(--ctl-green);
  border-color: var(--ctl-green);
  box-shadow: none;
}

.dd-item.toggle-row input[type="checkbox"]:checked::before,
#rag-docs-toggle:checked::before,
#rag-globally-enabled:checked::before,
#deep-search-autorefresh:checked::before,
#mailbox-modal-starttls-input:checked::before,
.deep-search-form-check input[type="checkbox"]:checked::before,
input[name="item-store"]:checked::before,
input[type="checkbox"].users-row-check:checked::before,
input[type="checkbox"].tasks-row-check:checked::before,
#users-select-all-visible:checked::before,
#tasks-select-all-visible:checked::before,
.users-bulk-checklist-body .inline-check input[type="checkbox"]:checked::before {
  transform: rotate(45deg) scale(1);
}

.dd-item.toggle-row input[type="checkbox"]::after,
#rag-docs-toggle::after,
#rag-globally-enabled::after,
#deep-search-autorefresh::after,
#mailbox-modal-starttls-input::after,
.deep-search-form-check input[type="checkbox"]::after,
input[name="item-store"]::after,
input[type="checkbox"].users-row-check::after,
input[type="checkbox"].tasks-row-check::after,
#users-select-all-visible::after,
#tasks-select-all-visible::after,
.users-bulk-checklist-body .inline-check input[type="checkbox"]::after {
  display: none !important;
  content: none !important;
}

/* ============================================================================
   3) MINI ECLIPSE — compact switch inside small pill chips (life feed)
   ============================================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip input[type="checkbox"] {
  --ctl-w: 32px;
  --ctl-h: 18px;
  --ctl-knob: 13px;
  --ctl-gap: 2.5px;
  --ctl-core: 6px;
}

/* ============================================================================
   4) BLADE RADIO CARDS — vertical radio groups
   ----------------------------------------------------------------------------
   From new_radio_buttons_vertical_choice.html. The label becomes a full-width
   card; a dark blade slides in from the left and a neon strip parks at the
   right edge when the radio is checked. Text is wrapped in a span by the
   tool-panels template so it sits above the blade.
   ============================================================================ */
.ai-toolhub-radio-label {
  position: relative;
  display: flex !important;
  align-items: center;
  min-height: 52px;
  padding: 0 16px;
  margin: 6px 0 !important;
  border-radius: 12px;
  background: var(--ctl-track-off);
  cursor: pointer;
  overflow: hidden;
  color: var(--ctl-radio-text, #555555);
  font-weight: 600;
  font-size: 16px;
  transition: color 0.4s ease;
}

.ai-toolhub-radio-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

.ai-toolhub-radio-label::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--ctl-track-on);
  transform: translateX(-101%);
  transition: transform 0.5s cubic-bezier(0.77, 0, 0.175, 1);
  z-index: 1;
}

.ai-toolhub-radio-label::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--ctl-core);
  box-shadow: 0 0 12px var(--ctl-core);
  transform: translateX(-100%);
  transition: transform 0.5s cubic-bezier(0.77, 0, 0.175, 1),
    left 0.5s cubic-bezier(0.77, 0, 0.175, 1);
  z-index: 3;
}

.ai-toolhub-radio-text {
  position: relative;
  z-index: 2;
}

.ai-toolhub-radio-label:has(input:checked) {
  color: var(--ctl-radio-text-on, #ffffff);
}

.ai-toolhub-radio-label:has(input:checked)::before {
  transform: translateX(0);
}

.ai-toolhub-radio-label:has(input:checked)::after {
  left: calc(100% - 4px);
  transform: translateX(0);
}

.ai-toolhub-radio-label:has(input:focus-visible) {
  outline: 2px solid var(--ctl-focus);
  outline-offset: 2px;
}

html[data-theme-appearance="light"] .ai-toolhub-radio-label:has(input:checked) {
  color: var(--ctl-radio-text-on, #ffffff);
}

/* ============================================================================
   5) CAPSULE RAIL — segmented mode selector with sliding puck
   ----------------------------------------------------------------------------
   From new_advanced_default_zen_modes_radio_button.html. The puck is a
   ::before element whose position/width are driven by JS through
   --ctl-rail-x / --ctl-rail-w (see index.html _positionModeRails), which keeps
   it correct even when a mode button is hidden (e.g. Advanced unavailable).
   ============================================================================ */
.chat-mode-strip,
.menu-mode-switcher {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
}

/* ---- top chat-mode strip ---- */
.chat-mode-strip {
  gap: 0;
  padding: 4px;
  background: var(--ctl-rail-track);
  border: 1px solid var(--ctl-rail-edge);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.45);
}

/* Puck: a real child element positioned via inline style in JS, so the
   slide transition always runs (pseudo-element + var()-driven transforms
   can freeze in some engines). */
.chat-mode-strip .mode-rail-puck,
.menu-mode-switcher .mode-rail-puck {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: 60px;
  border-radius: 999px;
  background: var(--ctl-rail-puck);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(206, 223, 205, 0.16);
  transform: translateX(0px);
  transition: transform 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.15);
  z-index: 1;
  pointer-events: none;
}

.chat-mode-strip .mode-rail-puck {
  top: 4px;
  bottom: 4px;
}

.chat-mode-btn {
  position: relative;
  z-index: 2;
  background: transparent !important;
  border-color: transparent !important;
}

.chat-mode-btn:hover {
  background: rgba(206, 223, 205, 0.06) !important;
  border-color: transparent !important;
}

.chat-mode-btn.is-active {
  background: transparent !important;
  border-color: transparent !important;
  color: #ffffff !important;
  box-shadow: none !important;
}

html[data-theme-appearance="light"] .chat-mode-btn.is-active {
  color: #ffffff !important;
}

/* ---- menu footer mode switcher ---- */
.menu-mode-switcher {
  gap: 0;
  padding: 3px;
  background: var(--ctl-rail-track) !important;
  border: 1px solid var(--ctl-rail-edge) !important;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.40) !important;
}

.menu-mode-switcher .mode-rail-puck {
  top: 3px;
  bottom: 3px;
}

.menu-mode-btn {
  position: relative;
  z-index: 2;
  min-width: 62px;
  text-align: center;
  background: transparent !important;
}

.menu-mode-btn:hover {
  color: var(--accent, #cedfcd) !important;
}

.menu-mode-btn.is-active {
  background: transparent !important;
  color: #ffffff !important;
}

html[data-theme-appearance="light"] .menu-mode-btn {
  color: #44594d !important;
}

html[data-theme-appearance="light"] .menu-mode-btn.is-active {
  background: transparent !important;
  color: #ffffff !important;
}

/* Keep the rail readable on the very compact menu footer */
.menu-footer-center {
  min-width: 0;
}

/* ============================================================================
   4) SELECT / DROPDOWN MENUS — Dark & Light Mode Legibility
   ----------------------------------------------------------------------------
   Ensures native <select> elements and their popup <option> menus always have
   solid, legible background and high-contrast text in both dark and light modes.
   Prevents browser default transparent-white dropdown popup issue.
   ============================================================================ */

select {
  color-scheme: dark;
}

select option,
select optgroup {
  background-color: #0b1a14;
  color: #e6f6ef;
}

select option:checked {
  background-color: #163a2c;
  color: #ffffff;
}

html[data-theme-appearance="light"] select {
  color-scheme: light;
}

html[data-theme-appearance="light"] select option,
html[data-theme-appearance="light"] select optgroup {
  background-color: #ffffff;
  color: #1f1d1a;
}

html[data-theme-appearance="light"] select option:checked {
  background-color: #e6f3ec;
  color: #1b6b4a;
}
