/* HoloAlmanac Toolkit settings panel (v2)
   Standalone-capable: all tokens are declared on .toolkit-panel.
   Layers cleanly on v1 ha.css + v2/ha.css when those are present
   (font stack, --focus, skip-link, wordmark). Does not @import or use url().

   Colors are sampled from team/ref/toolkit-search-results.png and kept
   as a cooler Toolkit chrome palette. Close ha.css mappings:
     page  #141416  ~ --bg        #12110E
     card  #1F1F22  ~ --surface   #1B1914
     title #F2F2F5  ~ --text      #F3EEE4
     muted #ACACB5  ~ --text-muted #A39A88
     focus uses var(--focus, #E0C078)
   The on-track #86A5FF is the Toolkit switch from the reference, not gold.

   Contrast notes (1.4.11):
     White on #86A5FF is 2.38:1, so the knob has a #1F1F22 ring (6.92:1).
     Off-track fill #48484E is 1.81:1 on the card, so it keeps a #9797A0
     border (5.68:1 vs card, 3.14:1 vs fill).
*/

.toolkit-panel {
  --tp-page: #141416;
  --tp-bg: #1f1f22;
  --tp-title: #f2f2f5;
  --tp-muted: #acacb5;
  --tp-header: #acacb5;
  --tp-on: #86a5ff;
  --tp-off: #48484e;
  --tp-off-border: #9797a0;
  --tp-knob: #ffffff;
  --tp-knob-ring: #1f1f22;
  --tp-tab: #2c2c32;
  --tp-tab-hover: #36363c;
  --tp-focus: var(--focus, #e0c078);
  --tp-radius: 12px;
  --tp-switch-w: 38px;
  --tp-switch-h: 22px;
  --tp-knob-size: 18px;
  --tp-font: var(--font, system-ui, -apple-system, "Segoe UI", sans-serif);

  box-sizing: border-box;
  width: 100%;
  max-width: 22.5rem;
  font-family: var(--tp-font);
  color: var(--tp-title);
  -webkit-font-smoothing: antialiased;
}

.toolkit-panel *,
.toolkit-panel *::before,
.toolkit-panel *::after {
  box-sizing: border-box;
}

/* ---- Tabs (CSS-only radios) ------------------------------------------- */

.tp-tab-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tp-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0 0 0.75rem;
}

.tp-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.375rem 0.8125rem;
  border: 0;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--tp-muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.tp-tab:hover {
  background: var(--tp-tab-hover);
  color: var(--tp-title);
}

#tp-tab-search:checked ~ .tp-tabs [for="tp-tab-search"],
#tp-tab-gixen:checked ~ .tp-tabs [for="tp-tab-gixen"],
#tp-tab-saved:checked ~ .tp-tabs [for="tp-tab-saved"],
#tp-tab-cardladder:checked ~ .tp-tabs [for="tp-tab-cardladder"],
#tp-tab-settings:checked ~ .tp-tabs [for="tp-tab-settings"] {
  background: var(--tp-tab);
  color: var(--tp-title);
}

#tp-tab-search:focus-visible ~ .tp-tabs [for="tp-tab-search"],
#tp-tab-gixen:focus-visible ~ .tp-tabs [for="tp-tab-gixen"],
#tp-tab-saved:focus-visible ~ .tp-tabs [for="tp-tab-saved"],
#tp-tab-cardladder:focus-visible ~ .tp-tabs [for="tp-tab-cardladder"],
#tp-tab-settings:focus-visible ~ .tp-tabs [for="tp-tab-settings"] {
  outline: 2px solid var(--tp-focus);
  outline-offset: 2px;
}

.tp-panel {
  display: none;
}

#tp-tab-search:checked ~ #tp-panel-search,
#tp-tab-gixen:checked ~ #tp-panel-gixen,
#tp-tab-saved:checked ~ #tp-panel-saved,
#tp-tab-cardladder:checked ~ #tp-panel-cardladder,
#tp-tab-settings:checked ~ #tp-panel-settings {
  display: block;
}

/* ---- Card + rows ------------------------------------------------------ */

.tp-card {
  margin: 0;
  padding: 1rem 0.75rem 0.75rem;
  background: var(--tp-bg);
  border-radius: var(--tp-radius);
  border: 0;
}

.tp-heading {
  margin: 0 0 0.25rem;
  padding: 0 0.25rem;
  color: var(--tp-header);
  font-size: 0.6875rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tp-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tp-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 0.75rem 0.25rem;
  cursor: pointer;
}

.tp-copy {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.tp-title {
  color: var(--tp-title);
  font-size: 0.9375rem;
  font-weight: 650;
  line-height: 1.25;
}

.tp-desc {
  color: var(--tp-muted);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.35;
}

.tp-empty {
  margin: 0;
  padding: 0.75rem 0.25rem 0.5rem;
  color: var(--tp-muted);
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* ---- Switch (real checkbox, role=switch) ------------------------------ */

.tp-switch-wrap {
  position: relative;
  flex: 0 0 var(--tp-switch-w);
  width: var(--tp-switch-w);
  height: var(--tp-switch-h);
  align-self: center;
}

.tp-switch-input {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.tp-switch {
  position: relative;
  display: block;
  width: var(--tp-switch-w);
  height: var(--tp-switch-h);
  border: 1.5px solid var(--tp-off-border);
  border-radius: 999px;
  background: var(--tp-off);
  pointer-events: none;
}

.tp-switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: var(--tp-knob-size);
  height: var(--tp-knob-size);
  border-radius: 50%;
  background: var(--tp-knob);
  box-shadow: 0 0 0 1px var(--tp-knob-ring);
  transform: translateY(-50%);
  transition: transform 160ms ease;
}

.tp-switch-input:checked + .tp-switch {
  background: var(--tp-on);
  border-color: var(--tp-on);
}

.tp-switch-input:checked + .tp-switch::after {
  /* 38px track - 3px borders - 18px knob - 2px left inset = 15px travel */
  transform: translate(15px, -50%);
}

.tp-switch-input:focus-visible + .tp-switch {
  outline: 2px solid var(--tp-focus);
  outline-offset: 3px;
}

.tp-switch-input:disabled + .tp-switch {
  opacity: 0.5;
}

@media (prefers-reduced-motion: reduce) {
  .tp-switch::after,
  .tp-tab {
    transition: none;
  }
}

/* Site page: the website shows the panel wider than the popup. */
.toolkit-panel.tp-wide{max-width:46rem;margin:0 auto;background:var(--tp-page);border:1px solid #2c2c32;border-radius:16px;padding:14px}
.tp-wide .tp-card{margin-top:12px;background:var(--tp-bg);border-radius:var(--tp-radius)}
.tp-wide .tk-head{display:flex;align-items:center;gap:8px;margin-bottom:10px}
.tp-wide .tp-row .tk-field,.tp-wide .tp-row .tk-btn,.tp-wide .tp-row .tk-num{flex:0 0 auto;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tk-tabnote{margin:0 2px 8px;font-size:12px;color:var(--tp-muted);border-left:2px solid var(--tp-on);padding-left:8px}
.tk-listv{font-size:12px}
