.theme-panel {
  --panel-size: 36px;
  --sheet-width: min(165px, calc(100vw - 28px));
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 100;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 6px;
}

.theme-panel__sheet {
  width: var(--sheet-width);
  max-width: 0;
  padding: 0;
  border: 0 solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: var(--shadow-soft);
  min-height: var(--panel-size);
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width 220ms ease, padding 220ms ease, border-width 220ms ease, opacity 220ms ease, transform 220ms ease;
}

.theme-panel[data-panel-state="open"] .theme-panel__sheet {
  max-width: var(--sheet-width);
  padding: 0 6px;
  border-width: 1px;
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.theme-panel__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--panel-size);
}

.theme-panel__tab:focus-visible,
.theme-toggle:focus-visible,
.theme-print:focus-visible,
.theme-footer-toggle:focus-visible,
.theme-footer-print:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 4px;
}

.theme-panel__tab {
  width: var(--panel-size);
  height: var(--panel-size);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--primary);
  cursor: pointer;
  display: grid;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-panel__tab:hover,
.theme-print:hover,
.theme-footer-print:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-panel__tab-icon {
  grid-area: 1 / 1;
  width: 14px;
  height: 14px;
  color: var(--accent);
  transition: opacity 180ms ease, transform 180ms ease;
}

.theme-panel__tab-icon--open {
  opacity: 0;
  transform: scale(0.85);
}

.theme-panel[data-panel-state="open"] .theme-panel__tab-icon--closed {
  opacity: 0;
  transform: scale(0.85);
}

.theme-panel[data-panel-state="open"] .theme-panel__tab-icon--open {
  opacity: 1;
  transform: scale(1);
}

.theme-toggle {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: calc(var(--panel-size) - 2px);
  padding: 0;
  transition: var(--transition);
}

.theme-toggle:hover {
  color: var(--accent);
}

.theme-toggle__track {
  position: relative;
  width: 64px;
  min-width: 64px;
  height: 24px;
  padding: 3px;
  border-radius: 999px;
  background: var(--toggle-track-bg);
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: center;
  transition: background-color 220ms ease, border-color 220ms ease;
}

.theme-toggle__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc((100% - 6px) / 2);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: var(--toggle-thumb-bg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  z-index: 0;
  transition: transform 220ms ease, background-color 220ms ease;
}

[data-theme-preference="dark"] .theme-toggle__thumb {
  transform: translateX(100%);
}

.theme-toggle__icon {
  font-size: 11px;
  color: var(--toggle-icon-inactive);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.82;
  position: relative;
  z-index: 1;
  transition: color 220ms ease, opacity 220ms ease;
}

.theme-toggle__icon svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.1;
}

[data-theme-preference="light"] .theme-toggle__icon--light,
[data-theme-preference="dark"] .theme-toggle__icon--dark {
  color: var(--toggle-icon-active);
  opacity: 1;
}

.theme-toggle__value {
  font-size: 9px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
  white-space: nowrap;
}

.theme-print {
  width: 30px;
  min-width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--bg);
  color: var(--secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.theme-print svg,
.theme-footer-print svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.1;
}

.theme-footer-actions {
  display: none;
}

@media (max-width: 768px) {
  .theme-panel {
    display: none;
  }

  .theme-footer-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 18px auto 0;
  }

  .theme-footer-toggle,
  .theme-footer-print {
    position: static;
    height: 38px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--bg);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 12px;
    box-shadow: var(--shadow-soft);
  }

  .theme-footer-print {
    min-width: 38px;
    padding: 0;
  }

  .theme-footer-print svg {
    width: 15px;
    height: 15px;
  }

  .theme-footer-toggle__icons {
    position: relative;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .theme-footer-toggle__icon {
    position: absolute;
    width: 16px;
    height: 16px;
    color: var(--secondary);
    opacity: 0;
    transition: opacity 180ms ease;
  }

  .theme-footer-toggle__icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.1;
  }

  [data-theme-preference="light"] .theme-footer-toggle__icon--light,
  [data-theme-preference="dark"] .theme-footer-toggle__icon--dark {
    opacity: 1;
    color: var(--accent);
  }

  .theme-footer-toggle__label {
    font-size: 10px;
    line-height: 1;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }
}

@media (max-width: 580px) {
  .theme-footer-actions {
    gap: 6px;
    margin-top: 14px;
  }

  .theme-footer-toggle,
  .theme-footer-print {
    height: 36px;
  }

  .theme-footer-toggle {
    min-width: 112px;
    gap: 6px;
  }

  .theme-footer-print {
    min-width: 36px;
  }
}
