/* =====================================================================
   Rackinator custom controls
   Restyles every native form control (text/number/search/date inputs,
   selects, textareas, checkboxes, switches, sliders, color pickers,
   buttons, scrollbars) and styles the popups made by ui-controls.js
   (dropdown list, number stepper, slider value bubble).
   Loaded after styles.css, so these rules win over the old generic ones.
   ===================================================================== */
:root{
  --ctl-h: 34px;
  --ctl-bg: #191e25;
  --ctl-bg-hover: #1d232b;
  --ctl-border: #2c333d;
  --ctl-border-hover: #3b4450;
  --ctl-track: #2a313a;
  --ctl-ring: 0 0 0 3px rgba(63,217,199,0.22);
  --ctl-placeholder: #697380;
  --ctl-on-accent: #05211d;
  --pop-bg: #1b2129;
  --pop-border: #333b47;
  --pop-hover: #262d37;
  --thumb: #f4f7f9;
  --scroll-thumb: #333b46;
}
body.light-theme{
  --ctl-bg: #ffffff;
  --ctl-bg-hover: #f6f8fa;
  --ctl-border: #d2d8df;
  --ctl-border-hover: #b6bfc9;
  --ctl-track: #e2e7ec;
  --ctl-ring: 0 0 0 3px rgba(13,148,136,0.2);
  --ctl-placeholder: #9aa3ad;
  --ctl-on-accent: #ffffff;
  --pop-bg: #ffffff;
  --pop-border: #d5dbe2;
  --pop-hover: #eef3f5;
  --thumb: #ffffff;
  --scroll-thumb: #c5cdd5;
}
::selection{ background: rgba(63,217,199,0.32); }
body.light-theme ::selection{ background: rgba(13,148,136,0.22); }

/* ---------- scrollbars ---------- */
*{ scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar{ width: 10px; height: 10px; }
::-webkit-scrollbar-track{ background: transparent; }
::-webkit-scrollbar-thumb{ background: var(--scroll-thumb); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover{ background-color: var(--muted); }
::-webkit-scrollbar-corner{ background: transparent; }

/* ---------- text-like fields + select ---------- */
input[type=text], input[type=search], input[type=number], input[type=email], input[type=url],
input[type=password], input[type=tel], input[type=date], input:not([type]), select, textarea{
  -webkit-appearance: none; appearance: none;
  height: var(--ctl-h); box-sizing: border-box;
  background-color: var(--ctl-bg); color: var(--text);
  border: 1px solid var(--ctl-border); border-radius: var(--radius-sm);
  padding: 0 11px; font: 500 13px/1.2 var(--font-ui);
  transition: border-color .14s ease, box-shadow .14s ease, background-color .14s ease;
  outline: none;
}
textarea{ height: auto; min-height: 72px; padding: 8px 11px; line-height: 1.5; resize: vertical; }
:is(input, select, textarea):hover:not(:disabled):not(:focus){ border-color: var(--ctl-border-hover); }
:is(input[type=text], input[type=search], input[type=number], input[type=email], input[type=url], input[type=password], input[type=tel], input[type=date], input:not([type]), select, textarea):focus{
  outline: none; border-color: var(--accent); box-shadow: var(--ctl-ring); background-color: var(--ctl-bg);
}
::placeholder{ color: var(--ctl-placeholder); opacity: 1; }
:is(input, select, textarea, button):disabled{ opacity: .45; cursor: not-allowed; }

/* select: custom chevron; the open list is drawn by ui-controls.js */
select{
  padding-right: 32px; cursor: pointer; text-overflow: ellipsis; white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%237d8794' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 12px;
}
select[aria-expanded="true"]{ border-color: var(--accent); box-shadow: var(--ctl-ring);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%233fd9c7' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7.5 6 4.5 9 7.5'/%3E%3C/svg%3E"); }
select option, select optgroup{ background: var(--pop-bg); color: var(--text); }

/* search: magnifier + custom clear button */
input[type=search]{
  padding-left: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none' stroke='%237d8794' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.2'/%3E%3Cpath d='M9.2 9.2 12.5 12.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 11px center; background-size: 14px;
}
input[type=search]::-webkit-search-cancel-button{
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; cursor: pointer; border-radius: 50%;
  background: var(--ctl-border-hover) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M5.5 5.5 10.5 10.5 M10.5 5.5 5.5 10.5'/%3E%3C/svg%3E") center / 16px no-repeat;
}
input[type=search]::-webkit-search-cancel-button:hover{ background-color: var(--accent); }

/* number: hide native spinners — ui-controls.js shows a custom stepper on hover/focus */
input[type=number]{ -moz-appearance: textfield; appearance: textfield; padding-right: 24px; font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button{ -webkit-appearance: none; margin: 0; }

/* date */
input[type=date]{ padding-right: 8px; color-scheme: dark; }
body.light-theme input[type=date]{ color-scheme: light; }
input[type=date]::-webkit-calendar-picker-indicator{ cursor: pointer; opacity: .65; border-radius: 4px; padding: 3px; transition: opacity .14s, background-color .14s; }
input[type=date]::-webkit-calendar-picker-indicator:hover{ opacity: 1; background-color: var(--ctl-bg-hover); }

/* compact fields inside tables and dense rows */
td :is(input[type=text], input[type=number], input[type=search], input[type=date], select){ height: 30px; font-size: 12.5px; }
.rack-gap input[type=number]{ height: 28px; padding: 0 20px 0 6px; text-align: center; }

/* ---------- color picker ---------- */
input[type=color]{
  -webkit-appearance: none; appearance: none; width: 34px; height: 34px; padding: 3px; flex: 0 0 auto;
  border: 1px solid var(--ctl-border); border-radius: var(--radius-sm); background: var(--ctl-bg); cursor: pointer;
  transition: border-color .14s, box-shadow .14s, transform .1s;
}
input[type=color]:hover{ border-color: var(--ctl-border-hover); }
input[type=color]:focus-visible{ outline: none; border-color: var(--accent); box-shadow: var(--ctl-ring); }
input[type=color]:active{ transform: scale(.95); }
input[type=color]::-webkit-color-swatch-wrapper{ padding: 0; }
input[type=color]::-webkit-color-swatch{ border: none; border-radius: 4px; }
input[type=color]::-moz-color-swatch{ border: none; border-radius: 4px; }
td input[type=color]{ width: 28px; height: 28px; padding: 2px; }

/* ---------- checkbox ---------- */
input[type=checkbox]{
  -webkit-appearance: none; appearance: none; margin: 0; flex: 0 0 auto; vertical-align: middle;
  width: 18px; height: 18px; border-radius: 5px; cursor: pointer; position: relative;
  border: 1.5px solid var(--ctl-border-hover); background: var(--ctl-bg);
  display: inline-grid; place-content: center;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
input[type=checkbox]::before{
  content: ""; width: 10px; height: 10px; transform: scale(0);
  background: var(--ctl-on-accent);
  clip-path: polygon(12% 50%, 0 64%, 40% 100%, 100% 20%, 87% 7%, 39% 72%);
  transition: transform .16s cubic-bezier(.34,1.56,.64,1);
}
input[type=checkbox]:hover{ border-color: var(--accent); }
input[type=checkbox]:checked{ background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::before{ transform: scale(1); }
input[type=checkbox]:focus-visible{ outline: none; box-shadow: var(--ctl-ring); }

/* ---------- toggle switch: class="switch", plus the app's on/off settings ---------- */
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle){
  width: 36px; height: 20px; border-radius: 999px; display: inline-block;
  border: 1px solid var(--ctl-border-hover); background: var(--ctl-track);
}
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle)::before{
  position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  clip-path: none; transform: none; background: var(--muted);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
  transition: transform .2s cubic-bezier(.34,1.4,.64,1), background-color .2s ease, width .15s ease;
}
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle):active::before{ width: 17px; }
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle):checked{ background: var(--accent); border-color: var(--accent); }
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle):checked::before{ transform: translateX(16px); background: #ffffff; }
:is(input[type=checkbox].switch, #persistToggle, #soundToggle, #confirmDeletesToggle, #showCablesToggle):checked:active::before{ transform: translateX(13px); }

/* ---------- slider ---------- */
input[type=range]{
  -webkit-appearance: none; appearance: none; height: 24px; padding: 0; margin: 0; border: none;
  background: transparent; cursor: pointer; --fill: 50%; outline: none; min-width: 80px;
}
input[type=range]::-webkit-slider-runnable-track{
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill), var(--ctl-track) var(--fill) 100%);
}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%;
  background: var(--thumb); border: 4px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.35);
  transition: transform .14s cubic-bezier(.34,1.56,.64,1), box-shadow .14s;
}
input[type=range]:hover::-webkit-slider-thumb{ transform: scale(1.12); }
input[type=range]:active::-webkit-slider-thumb{ transform: scale(1.22); }
input[type=range]:focus-visible::-webkit-slider-thumb{ box-shadow: var(--ctl-ring), 0 1px 4px rgba(0,0,0,.35); }
input[type=range]::-moz-range-track{ height: 6px; border-radius: 999px; background: var(--ctl-track); }
input[type=range]::-moz-range-progress{ height: 6px; border-radius: 999px; background: var(--accent); }
input[type=range]::-moz-range-thumb{ width: 10px; height: 10px; border-radius: 50%; background: var(--thumb); border: 4px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.35); }

/* ---------- buttons ---------- */
button{
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--ctl-on-accent); border: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: 7px 14px; font: 650 12.8px/1.2 var(--font-ui); cursor: pointer;
  transition: background-color .14s ease, color .14s ease, border-color .14s ease, box-shadow .14s ease, transform .08s ease, filter .14s ease;
}
button:hover{ background: var(--accent); color: var(--ctl-on-accent); filter: brightness(1.08); }
button:active{ transform: translateY(1px) scale(.98); }
button:focus-visible{ outline: none; box-shadow: var(--ctl-ring); }
button.ghost{ background: transparent; border-color: var(--ctl-border); color: var(--text); font-weight: 500; }
button.ghost:hover{ background: var(--ctl-bg-hover); border-color: var(--ctl-border-hover); color: var(--text); filter: none; }
button.small{ padding: 4px 10px; font-size: 11.8px; }
button.danger{ background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover{ background: var(--danger); color: #fff; filter: none; }
button.seg{ background: transparent; border-color: var(--ctl-border); color: var(--muted); font-weight: 600; }
button.seg:hover{ color: var(--text); background: var(--ctl-bg-hover); filter: none; }
button.seg.active{ background: var(--accent-dim); color: var(--text); border-color: var(--accent); }
button.chip:hover{ filter: none; }
button:disabled{ opacity: .38; cursor: not-allowed; pointer-events: none; }

/* ---------- custom dropdown list (ui-controls.js) ---------- */
.cs-pop{
  position: fixed; z-index: 400; box-sizing: border-box; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--pop-bg); border: 1px solid var(--pop-border); border-radius: 10px;
  box-shadow: var(--shadow-lg); font-family: var(--font-ui);
  animation: csIn .14s cubic-bezier(.2,.8,.2,1);
}
.cs-pop.up{ animation-name: csInUp; }
@keyframes csIn{ from{ opacity: 0; transform: translateY(-4px) scale(.98); } to{ opacity: 1; transform: none; } }
@keyframes csInUp{ from{ opacity: 0; transform: translateY(4px) scale(.98); } to{ opacity: 1; transform: none; } }
.cs-search{ padding: 6px 6px 0; }
.cs-search input{ width: 100%; height: 30px; font-size: 12.5px; }
.cs-list{ overflow-y: auto; padding: 5px; overscroll-behavior: contain; }
.cs-opt{
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 30px; border-radius: 6px; cursor: pointer; user-select: none;
  font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cs-opt .cs-txt{ overflow: hidden; text-overflow: ellipsis; }
.cs-opt.active{ background: var(--pop-hover); }
.cs-opt.selected{ color: var(--accent); font-weight: 650; }
.cs-opt.selected::before{
  content: ""; position: absolute; left: 11px; top: 50%; width: 11px; height: 11px; margin-top: -5.5px; background: currentColor;
  clip-path: polygon(12% 50%, 0 64%, 40% 100%, 100% 20%, 87% 7%, 39% 72%);
}
.cs-opt.disabled{ opacity: .4; cursor: default; }
.cs-dot{ width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.cs-group{ padding: 9px 12px 4px; font-size: 10.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.cs-group:first-child{ padding-top: 4px; }
.cs-empty{ padding: 10px 12px; color: var(--muted); font-size: 12.5px; }

/* ---------- number stepper (ui-controls.js) ---------- */
.rk-stepper{
  position: fixed; z-index: 350; display: none; flex-direction: column; overflow: hidden;
  width: 20px; border-left: 1px solid var(--ctl-border); border-radius: 0 4px 4px 0; background: var(--ctl-bg);
}
.rk-stepper.show{ display: flex; animation: fadeIn .1s ease; }
.rk-stepper span{
  flex: 1 1 0; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); user-select: none;
  transition: background-color .1s, color .1s;
}
.rk-stepper span + span{ border-top: 1px solid var(--ctl-border); }
.rk-stepper span:hover{ background: var(--accent-dim); color: var(--accent); }
.rk-stepper span:active{ background: var(--accent); color: var(--ctl-on-accent); }
.rk-stepper svg{ width: 8px; height: 8px; }

/* ---------- slider value bubble (ui-controls.js) ---------- */
.rk-bubble{
  position: fixed; z-index: 350; pointer-events: none; transform: translate(-50%, -100%);
  background: var(--text); color: var(--bg); font: 700 11px/1 var(--font-mono);
  padding: 5px 7px; border-radius: 6px; white-space: nowrap; opacity: 0; transition: opacity .12s ease;
}
.rk-bubble::after{ content: ""; position: absolute; left: 50%; bottom: -4px; margin-left: -4px; border: 4px solid transparent; border-bottom: 0; border-top-color: var(--text); }
.rk-bubble.show{ opacity: 1; }

@media (prefers-reduced-motion: reduce){
  .cs-pop, .rk-stepper.show{ animation: none; }
  input[type=checkbox]::before, input[type=range]::-webkit-slider-thumb{ transition: none; }
}

/* colour pickers and checkboxes never stretch inside flexible form rows */
:is(.form-row, .toolbar, .row2) :is(input[type=color], input[type=checkbox]){ flex: 0 0 auto; min-width: 0; }

/* ---------- integration guards ----------
   View styles sometimes use the padding/background shorthands, which would wipe the
   gutters these controls need for their icons (search magnifier, select chevron,
   number stepper). These keep the structural bits intact everywhere. */
input[type=search]:not(#globalSearch){
  padding-left: 32px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none' stroke='%237d8794' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.2'/%3E%3Cpath d='M9.2 9.2 12.5 12.5'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: 11px center !important; background-size: 14px !important;
}
#globalSearch{ background-image: none !important; }
select{
  padding-right: 30px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%237d8794' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: right 10px center !important; background-size: 12px !important;
}
select[aria-expanded="true"]{
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%233fd9c7' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7.5 6 4.5 9 7.5'/%3E%3C/svg%3E") !important;
}
input[type=number]{ padding-right: 24px !important; }
.rack-gap input[type=number]{ padding-right: 20px !important; }
