/* W63 (2026-10-02): the ONE on/off switch of the whole CleanOne panel.
   Green track = on, grey track = off, ✓ / ✕ on the knob.
   A state word UNDER the switch only where on/off alone is not obvious ("wolno / nie wolno",
   "tylko administrator") — Robert 2026-10-03: a plain on/off switch carries no text.
   Class `cln-switch--word` marks a switch with a word (fixed width, words line up).
   Served by Brama like /theme.js; every screen links this file instead of drawing its own.

   Two forms, same look:
   1. <button class="cln-switch" role="switch" aria-checked="true|false">
        <span class="cln-switch-track"></span><span class="cln-switch-word">włączony</span></button>
      — built by CleanSwitch.set() in /switch.js; the code sets the word.
   2. <span class="cln-switch"><input type="checkbox" role="switch" class="cln-switch-input">
        <span class="cln-switch-track"></span>
        <span class="cln-switch-word" data-on="tak" data-off="nie"></span></span>
      — for forms; the word follows the checkbox by itself (CleanSwitch.wrapInput()).
   `.is-busy` on .cln-switch = saving: a ring on the knob and "zapisywanie…" as the word.

   Colours live ONLY on :root, so a switch inside a shadow root (warehouse panel) inherits
   the theme of its page through the custom properties; the theme is the device's choice
   (data-theme from /theme.js), never the phone's colour setting. */

:root {
  --cln-sw-on: #22c55e;
  --cln-sw-off: #52525b;
  --cln-sw-knob: #ffffff;
  --cln-sw-word-on: #4ade80;
  --cln-sw-word-off: #a1a1aa;
  --cln-sw-focus: #f4f4f5;
}
:root[data-theme="light"] {
  --cln-sw-on: #16a34a;
  --cln-sw-off: #c4c4c4;   /* neutral grey R=G=B (Robert 2026-10-03, light theme) */
  --cln-sw-knob: #ffffff;
  --cln-sw-word-on: #15803d;
  --cln-sw-word-off: #737373;
  --cln-sw-focus: #181818;
}

.cln-switch {
  position: relative;
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
/* The button form must not look like a button: screens style every <button>. */
button.cln-switch,
button.cln-switch:hover,
button.cln-switch:active,
button.cln-switch:focus {
  background: none !important;
  border: 0 !important;
  box-shadow: none !important;
  /* SENTINEL (2026-10-19) SWITCH-44: 6 px above and below -> 32 + 12 = 44 px tall tap area for a switch WITHOUT a word (the
     Karta rule "every tap target >= 44 px", also the panel's); the track is unchanged. Was 4px 0 -> 40 px (56x40 measured
     19.10 in testy/karta-panel-browser, -d-browser, -r13-r14-browser). */
  padding: 6px 0 !important;
  margin: 0;
  min-height: 0 !important;
  width: auto !important;
  color: inherit !important;
  font: inherit;
  opacity: 1;
  outline: none;
}
/* With a word: fixed width, so a longer word ("tylko administrator", "zapisywanie…") does
   not push the switch sideways — switches in a column stay in one line. */
.cln-switch.cln-switch--word,
button.cln-switch.cln-switch--word { width: 96px !important; }
.cln-switch-track {
  position: relative;
  display: block;
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: var(--cln-sw-off, #52525b);
  transition: background .18s;
}
.cln-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  background: var(--cln-sw-knob, #fff) no-repeat center / 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 4l8 8M12 4l-8 8' stroke='%2371717a' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  transition: transform .18s;
}
.cln-switch[aria-checked="true"] > .cln-switch-track,
.cln-switch-input:checked + .cln-switch-track {
  background: var(--cln-sw-on, #22c55e);
}
.cln-switch[aria-checked="true"] > .cln-switch-track::after,
.cln-switch-input:checked + .cln-switch-track::after {
  transform: translateX(24px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3.2 3.2L13 5' fill='none' stroke='%2316a34a' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.cln-switch-word {
  display: block;
  max-width: 100%;
  font-size: 11.5px;
  line-height: 1.15;
  font-weight: 700;
  text-align: center;
  overflow-wrap: normal;
  hyphens: none;
  color: var(--cln-sw-word-off, #a1a1aa);
}
.cln-switch[aria-checked="true"] > .cln-switch-word,
.cln-switch-input:checked ~ .cln-switch-word {
  color: var(--cln-sw-word-on, #4ade80);
}
/* Form 2: the word comes from data-on / data-off. */
.cln-switch-word[data-off]::before { content: attr(data-off); }
.cln-switch-input:checked ~ .cln-switch-word[data-on]::before { content: attr(data-on); }

/* The real checkbox stays in the page (keyboard, forms, screen readers), just unseen.
   !important: screens size their checkboxes (e.g. `.kt-check input`), the switch must win. */
/* SENTINEL (2026-10-19) SWITCH-44: the checkbox is the switch's tap area — 56x44, centred on the 32 px track (6 px above and
   below, outside the switch's own box: nothing around it moves). Was top 4px / height 32px -> 56x32, and 4 px below the track. */
.cln-switch > .cln-switch-input {
  position: absolute !important;
  top: -6px !important;
  left: 50% !important;
  width: 56px !important;
  height: 44px !important;
  margin: 0 0 0 -28px !important;
  padding: 0 !important;
  /* SENTINEL (2026-10-21) SWITCH-44-BORDER (E-S34n 02:40, trial leadintel: tap area 56x46 — its page rule `input { min-height:
     46px }` outgrew the 44 px height): the page's input sizing never applies to the switch's checkbox — the tap area is exactly
     56x44 on every page (min/max height, box model and border fixed here too). */
  min-height: 0 !important;
  max-height: none !important;
  box-sizing: border-box !important;
  border: 0 !important;
  opacity: 0 !important;
  cursor: pointer;
  z-index: 1;
}

/* Focus from the keyboard only. */
button.cln-switch:focus-visible > .cln-switch-track,
.cln-switch-input:focus-visible + .cln-switch-track {
  outline: 2px solid var(--cln-sw-focus, #f4f4f5);
  outline-offset: 2px;
}

/* No right to change it: same switch, faded, not clickable. */
button.cln-switch:disabled:not(.is-busy),
.cln-switch.is-disabled {
  cursor: not-allowed;
}
button.cln-switch:disabled:not(.is-busy) > *,
.cln-switch:not(.is-busy) > .cln-switch-input:disabled + .cln-switch-track,
.cln-switch:not(.is-busy) > .cln-switch-input:disabled ~ .cln-switch-word {
  opacity: .45;
}
.cln-switch-input:disabled { cursor: not-allowed; }

/* Not decided yet (the „+ Osoba” wizard has no defaults, W61): outlined track, knob in the
   middle with a dash, word „do ustalenia” — it must not look like „wyłączony”. */
.cln-switch.is-undecided > .cln-switch-track {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--cln-sw-off, #52525b);
}
.cln-switch.is-undecided > .cln-switch-track::after {
  transform: translateX(12px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8h8' stroke='%2371717a' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}
.cln-switch.is-undecided > .cln-switch-word { color: #d4a017; }

/* Saving: the knob shows a ring until the server answers. */
.cln-switch.is-busy { cursor: progress; }
.cln-switch.is-busy .cln-switch-track::after { background-image: none; }
.cln-switch.is-busy .cln-switch-track::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 9px;
  left: 9px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #a1a1aa;
  border-top-color: transparent;
  animation: cln-switch-spin .8s linear infinite;
}
.cln-switch.is-busy[aria-checked="true"] .cln-switch-track::before,
.cln-switch.is-busy .cln-switch-input:checked + .cln-switch-track::before {
  left: 33px;
}
/* The word (if any) says "zapisywanie…"; a switch without a word shows only the ring. */
.cln-switch.is-busy .cln-switch-word { font-size: 0; }
.cln-switch.is-busy .cln-switch-word::before { content: none; }
.cln-switch.is-busy .cln-switch-word::after {
  content: "zapisywanie…";
  font-size: 11.5px;
  color: var(--cln-sw-word-off, #a1a1aa);
}
@keyframes cln-switch-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .cln-switch-track, .cln-switch-track::after { transition: none; }
  .cln-switch.is-busy .cln-switch-track::before { animation: none; }
}
