/**
 * Theme / appearance offcanvas — layout, typography, hierarchy (design tokens).
 * Self-contained segmented control (guests do not load admin-settings.css).
 */

.tv-theme-offcanvas {
  --tv-oc-pad: 1rem;
  --tv-oc-width: min(100vw - 0.75rem, 26rem);
  --tv-oc-radius: var(--tv-radius-xl, 1rem);
  --tv-oc-radius-sm: var(--tv-radius-md, 0.5rem);
  width: var(--tv-oc-width);
  max-width: 100%;
  color: var(--tv-text, #1a1e2a);
  border-inline-start: 1px solid var(--tv-border, #e2e8f0);
  background: var(--tv-surface-base, #f8fafc);
  box-shadow: -16px 0 48px rgba(15, 23, 42, 0.12);
}

html[data-theme="dark"] .tv-theme-offcanvas {
  border-inline-start-color: var(--tv-border, #30363d);
  background: var(--tv-surface-base, #0d1117);
  color: var(--tv-text, #e6eaf0);
  box-shadow: -16px 0 56px rgba(0, 0, 0, 0.55);
}

/* ── Masthead ───────────────────────────────────────────────────────── */
.tv-theme-offcanvas__masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem var(--tv-oc-pad) 1rem;
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--tv-color-primary, #0d9488) 8%, var(--tv-surface-elevated, #fff)) 0%,
    var(--tv-surface-elevated, #ffffff) 42%,
    var(--tv-surface-elevated, #ffffff) 100%
  );
  border-block-end: 1px solid var(--tv-border-subtle, #f1f5f9);
}

html[data-theme="dark"] .tv-theme-offcanvas__masthead {
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--tv-color-primary, #2dd4bf) 10%, var(--tv-surface-elevated, #161b22)) 0%,
    var(--tv-surface-elevated, #161b22) 48%,
    var(--tv-surface-elevated, #161b22) 100%
  );
  border-block-end-color: var(--tv-border, #30363d);
}

.tv-theme-offcanvas__masthead-text {
  min-width: 0;
}

.tv-theme-offcanvas__eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tv-text-muted, #64748b);
  line-height: 1.2;
}

.tv-theme-offcanvas__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--tv-text, #0f172a);
}

.tv-theme-offcanvas__lede {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--tv-text-secondary, #475569);
  max-width: 32ch;
}

.tv-theme-offcanvas__dismiss {
  flex-shrink: 0;
  margin-block-start: 0.125rem;
  opacity: 0.72;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.tv-theme-offcanvas__dismiss:hover {
  opacity: 1;
}

.tv-theme-offcanvas__dismiss:focus-visible {
  opacity: 1;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tv-color-primary, #0d9488) 35%, transparent);
}

/* Bootstrap .btn-close is tuned for light surfaces; invert on dark masthead */
html[data-theme="dark"] .tv-theme-offcanvas .btn-close {
  filter: invert(1) grayscale(100%) brightness(1.85);
  opacity: 0.82;
}

html[data-theme="dark"] .tv-theme-offcanvas .btn-close:hover {
  opacity: 1;
}

/* ── Body stack ─────────────────────────────────────────────────────── */
.tv-theme-offcanvas__body {
  padding: 0;
  background: var(--tv-surface-base, #f8fafc);
}

html[data-theme="dark"] .tv-theme-offcanvas__body {
  background: var(--tv-surface-base, #0d1117);
}

.tv-theme-offcanvas__stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem var(--tv-oc-pad) calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

/* ── Cards ─────────────────────────────────────────────────────────── */
.tv-theme-offcanvas__card {
  border-radius: var(--tv-oc-radius);
  border: 1px solid var(--tv-border, #e2e8f0);
  background: var(--tv-surface-elevated, #ffffff);
  box-shadow: var(--tv-card-shadow, 0 1px 2px rgba(15, 23, 42, 0.06));
  overflow: hidden;
}

html[data-theme="dark"] .tv-theme-offcanvas__card {
  border-color: var(--tv-border, #30363d);
  background: var(--tv-surface-elevated, #161b22);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

.tv-theme-offcanvas__card--accent {
  border-color: color-mix(in srgb, var(--tv-color-primary, #0d9488) 22%, var(--tv-border, #e2e8f0));
}

html[data-theme="dark"] .tv-theme-offcanvas__card--accent {
  border-color: color-mix(in srgb, var(--tv-color-primary, #2dd4bf) 28%, var(--tv-border, #30363d));
}

.tv-theme-offcanvas__card-head {
  padding: 1rem 1rem 0.75rem;
  border-block-end: 1px solid var(--tv-border-subtle, #f1f5f9);
}

html[data-theme="dark"] .tv-theme-offcanvas__card-head {
  border-block-end-color: rgba(255, 255, 255, 0.06);
}

.tv-theme-offcanvas__card-kicker {
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tv-color-primary, #0d9488);
  margin-bottom: 0.35rem;
}

.tv-theme-offcanvas__card-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--tv-text, #0f172a);
}

.tv-theme-offcanvas__card-desc {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--tv-text-secondary, #64748b);
}

.tv-theme-offcanvas__card-body {
  padding: 1rem;
}

.tv-theme-offcanvas__card-body--flush {
  padding: 0;
}

/* ── Color mode row (segmented + flip) ─────────────────────────────── */
.tv-theme-offcanvas__mode-row {
  display: flex;
  align-items: stretch;
  gap: 0.625rem;
}

.tv-oc-segmented {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--tv-oc-radius-sm);
  background: var(--tv-surface-muted, #f1f5f9);
  border: 1px solid var(--tv-border, #e2e8f0);
}

html[data-theme="dark"] .tv-oc-segmented {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--tv-border, #30363d);
}

.tv-oc-segmented--stretch {
  width: 100%;
}

.tv-oc-segmented__item {
  flex: 1;
  margin: 0;
  cursor: pointer;
  border-radius: calc(var(--tv-oc-radius-sm) - 2px);
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}

.tv-oc-segmented__item:hover {
  background: color-mix(in srgb, var(--tv-surface-elevated, #fff) 50%, transparent);
}

html[data-theme="dark"] .tv-oc-segmented__item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.tv-oc-segmented__item:has(.tv-oc-segmented__input:checked) {
  background: var(--tv-surface-elevated, #ffffff);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

html[data-theme="dark"] .tv-oc-segmented__item:has(.tv-oc-segmented__input:checked) {
  background: #21262d;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.tv-oc-segmented__input:focus-visible + .tv-oc-segmented__content {
  outline: 2px solid var(--tv-color-primary, #0d9488);
  outline-offset: 2px;
  border-radius: calc(var(--tv-oc-radius-sm) - 2px);
}

.tv-oc-segmented__content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 0.5rem;
  color: var(--tv-text, #0f172a);
}

.tv-oc-segmented__icon,
.tv-oc-segmented__content svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: 0.88;
}

.tv-oc-segmented__label {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--tv-text, #0f172a);
  text-align: center;
}

@media (max-width: 22rem) {
  .tv-oc-segmented__label {
    font-size: 0.75rem;
  }
}

.tv-theme-offcanvas__flip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  min-height: 2.75rem;
  margin-inline-start: auto;
  padding: 0;
  border-radius: var(--tv-oc-radius-sm);
  border: 1px solid var(--tv-border, #e2e8f0);
  background: var(--tv-surface-elevated, #fff);
  color: var(--tv-text-secondary, #64748b);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.tv-theme-offcanvas__flip:hover {
  background: var(--tv-surface-muted, #f1f5f9);
  color: var(--tv-text, #0f172a);
  border-color: var(--tv-border, #cbd5e1);
}

.tv-theme-offcanvas__flip:active {
  transform: scale(0.96);
}

html[data-theme="dark"] .tv-theme-offcanvas__flip {
  background: #21262d;
  border-color: var(--tv-border, #30363d);
  color: var(--tv-text-secondary, #94a3b8);
}

html[data-theme="dark"] .tv-theme-offcanvas__flip:hover {
  background: #30363d;
  color: var(--tv-text, #e6eaf0);
}

.tv-theme-offcanvas__flip:focus-visible {
  outline: 2px solid var(--tv-color-primary, #0d9488);
  outline-offset: 2px;
}

.tv-theme-offcanvas__flip-icon {
  width: 1.125rem;
  height: 1.125rem;
}

/* ── Nested system setting rows (narrow rail) ─────────────────────── */
.tv-theme-offcanvas__settings-stack .tv-setting-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 1rem 1rem;
  border-block-end: 1px solid var(--tv-border-subtle, #f1f5f9);
}

html[data-theme="dark"] .tv-theme-offcanvas__settings-stack .tv-setting-row {
  border-block-end-color: rgba(255, 255, 255, 0.06);
}

.tv-theme-offcanvas__settings-stack .tv-setting-row:last-child {
  border-block-end: none;
}

.tv-theme-offcanvas__settings-stack .tv-setting-row__label {
  font-size: 0.8125rem;
}

.tv-theme-offcanvas__settings-stack .tv-setting-row__helper {
  font-size: 0.75rem;
}

.tv-theme-offcanvas__settings-stack .tv-swatch-select {
  max-width: 100%;
}

/* Allow swatch popovers to escape the card */
.tv-theme-offcanvas__card:has(.tv-swatch-select.is-open) {
  overflow: visible;
  z-index: 20;
  position: relative;
}

/* ── Sticky action strip ────────────────────────────────────────────── */
.tv-theme-offcanvas__actions {
  position: sticky;
  bottom: 0;
  padding: 1rem;
  margin: 0;
  border-block-start: 1px solid var(--tv-border-subtle, #f1f5f9);
  background: linear-gradient(
    to top,
    var(--tv-surface-elevated, #ffffff) 72%,
    color-mix(in srgb, var(--tv-surface-elevated, #ffffff) 0%, transparent) 100%
  );
}

html[data-theme="dark"] .tv-theme-offcanvas__actions {
  border-block-start-color: rgba(255, 255, 255, 0.08);
  background: linear-gradient(
    to top,
    var(--tv-surface-elevated, #161b22) 72%,
    transparent 100%
  );
}

@media (max-width: 20rem) {
  .tv-theme-offcanvas__mode-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tv-theme-offcanvas__flip {
    width: 100%;
    margin-inline-start: 0;
  }
}
