/* Единая тема сайта. Подключается после стилей конкретной страницы. */

html {
  color-scheme: light;
  --theme-toggle-bg: #e0f2ff;
  --theme-toggle-border: rgba(0, 122, 204, 0.24);
  --theme-toggle-color: #15557d;
  --theme-toggle-hover: #cbe7fa;
}

html[data-theme="dark"] {
  color-scheme: dark;
  /* Variables used by the editor stylesheet. Keeping them here prevents
     light editor surfaces from leaking into the dark theme. */
  --bg: #0a0c10;
  --bg-soft: #10151b;
  --card: #12161c;
  --card-soft: #181d24;
  --text: #e8f0f7;
  --text-soft: #a2afbb;
  --line: rgba(218, 231, 241, 0.15);
  --primary: #1678ba;
  --primary-soft: #18384e;
  --primary-strong: #74c5ff;
  --danger: #ff7888;
  --danger-soft: #3a1820;
  --success: #68d39a;
  --success-soft: #173528;
  --primary-color: #62c1ff;
  --primary-light: #202831;
  --primary-lighter: #303b46;
  --text-color: #e8f0f7;
  --text-light: #a9bbca;
  --white: #12161c;
  --gray-light: #1b2027;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  --theme-bg: #0a0c10;
  --theme-surface: #12161c;
  --theme-surface-soft: #181d24;
  --theme-line: rgba(218, 231, 241, 0.15);
  --theme-line-strong: rgba(98, 193, 255, 0.52);
  --theme-hover: #222a33;
  --theme-muted: #a2afbb;
  --theme-toggle-bg: #181d24;
  --theme-toggle-border: rgba(218, 231, 241, 0.18);
  --theme-toggle-color: #dce9f1;
  --theme-toggle-hover: #222a33;
}

html[data-theme="dark"],
html[data-theme="dark"] body {
  background: var(--theme-bg) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .background-gradient,
html[data-theme="dark"] .editor-background {
  background:
    radial-gradient(circle at 4% 0%, rgba(47, 116, 165, 0.16), transparent 28%),
    radial-gradient(circle at 96% 100%, rgba(33, 79, 111, 0.1), transparent 26%),
    linear-gradient(145deg, #0a0c10 0%, #0e1116 54%, #090b0e 100%) !important;
}

html[data-theme="dark"] header {
  background: linear-gradient(135deg, #141a21, #0d1015) !important;
  color: #edf7ff !important;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3) !important;
}

html[data-theme="dark"] .header-wave {
  background-image: none !important;
  background-color: #0d1015 !important;
  opacity: 1;
}

html[data-theme="dark"] .week-selector,
html[data-theme="dark"] .schedule-meta,
html[data-theme="dark"] .version-buttons,
html[data-theme="dark"] .selector-container,
html[data-theme="dark"] .students-container,
html[data-theme="dark"] .app-presentation,
html[data-theme="dark"] .error-content,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .calendar-modal-content,
html[data-theme="dark"] .list-modal-content,
html[data-theme="dark"] .editor-card {
  background: var(--theme-surface) !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
  box-shadow: var(--shadow) !important;
}

html[data-theme="dark"] .week-selector:hover,
html[data-theme="dark"] .selector-container:hover {
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.4) !important;
}

html[data-theme="dark"] .week-arrow,
html[data-theme="dark"] .calendar-button,
html[data-theme="dark"] .calendar-nav,
html[data-theme="dark"] .back-link,
html[data-theme="dark"] .calendar-today-btn,
html[data-theme="dark"] .selector-button,
html[data-theme="dark"] .date-input,
html[data-theme="dark"] .calendar-input {
  background: var(--theme-surface-soft) !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .week-arrow:hover,
html[data-theme="dark"] .calendar-button:hover,
html[data-theme="dark"] .calendar-nav:hover,
html[data-theme="dark"] .back-link:hover,
html[data-theme="dark"] .selector-button:hover {
  background: var(--theme-hover) !important;
  color: #f2f9ff !important;
}

html[data-theme="dark"] .week-day,
html[data-theme="dark"] .version-buttons button,
html[data-theme="dark"] .month-item,
html[data-theme="dark"] .calendar-day,
html[data-theme="dark"] .list-item {
  background: var(--theme-surface-soft) !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .week-day:hover,
html[data-theme="dark"] .version-buttons button:hover,
html[data-theme="dark"] .month-item:hover,
html[data-theme="dark"] .calendar-day:hover:not(.disabled):not(.empty),
html[data-theme="dark"] .list-item:hover {
  background: var(--theme-hover) !important;
}

html[data-theme="dark"] .week-day.active,
html[data-theme="dark"] .week-day.future.active,
html[data-theme="dark"] .version-buttons button.active,
html[data-theme="dark"] .month-item.active,
html[data-theme="dark"] .calendar-day.selected,
html[data-theme="dark"] .list-item.selected,
html[data-theme="dark"] .editor-week-day.active,
html[data-theme="dark"] .editor-day.active {
  background: #1678ba !important;
  border-color: #55b8ff !important;
  color: #ffffff !important;
  box-shadow: 0 8px 22px rgba(21, 120, 186, 0.28) !important;
}

html[data-theme="dark"] .week-day.future,
html[data-theme="dark"] .week-day.future:not(.active),
html[data-theme="dark"] .month-item.has-schedule,
html[data-theme="dark"] .calendar-day.available {
  color: #74c5ff !important;
  border-color: var(--theme-line-strong) !important;
}

html[data-theme="dark"] .schedule-table,
html[data-theme="dark"] .students-table table,
html[data-theme="dark"] .editor-table,
html[data-theme="dark"] .editor-teachers-table {
  background: var(--theme-surface) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .schedule-table th,
html[data-theme="dark"] .students-table th,
html[data-theme="dark"] .editor-table th,
html[data-theme="dark"] .editor-teachers-table th {
  background: #19435f !important;
  color: #eff8ff !important;
}

html[data-theme="dark"] .schedule-table td,
html[data-theme="dark"] .students-table td,
html[data-theme="dark"] .editor-table td,
html[data-theme="dark"] .editor-teachers-table td {
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .schedule-table tr:hover td,
html[data-theme="dark"] .students-table tbody tr:hover,
html[data-theme="dark"] .pair-row:hover,
html[data-theme="dark"] .pair-row.active-pair {
  background: var(--theme-hover) !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .editor-date-button,
html[data-theme="dark"] .editor-table input,
html[data-theme="dark"] .editor-teachers-table input {
  background: #0d1823 !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #7f96a8 !important;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] button:focus-visible,
html[data-theme="dark"] a:focus-visible {
  outline-color: #67c4ff !important;
  border-color: #55b8ff !important;
  box-shadow: 0 0 0 3px rgba(85, 184, 255, 0.2) !important;
}

html[data-theme="dark"] .primary-button,
html[data-theme="dark"] .show-button,
html[data-theme="dark"] .primary-btn,
html[data-theme="dark"] .download-btn {
  background: #1678ba !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .primary-button:hover,
html[data-theme="dark"] .show-button:hover,
html[data-theme="dark"] .primary-btn:hover,
html[data-theme="dark"] .download-btn:hover {
  background: #2390d7 !important;
}

html[data-theme="dark"] .secondary-button,
html[data-theme="dark"] .secondary-btn,
html[data-theme="dark"] .ghost-link {
  background: var(--theme-surface-soft) !important;
  border-color: var(--theme-line) !important;
  color: #d9efff !important;
}

html[data-theme="dark"] .danger-button,
html[data-theme="dark"] .danger-btn,
html[data-theme="dark"] .error-message,
html[data-theme="dark"] .editor-alert.error {
  background: #3a1820 !important;
  border-color: rgba(255, 112, 128, 0.34) !important;
  color: #ffb8c0 !important;
}

html[data-theme="dark"] .editor-background {
  background:
    radial-gradient(circle at top left, rgba(69, 169, 234, 0.1), transparent 27%),
    radial-gradient(circle at bottom right, rgba(39, 110, 155, 0.08), transparent 25%),
    linear-gradient(160deg, #0a0c10, #0e1116) !important;
}

html[data-theme="dark"] .editor-week-day.has-data,
html[data-theme="dark"] .version-item,
html[data-theme="dark"] .teacher-stat,
html[data-theme="dark"] .teacher-filter-control,
html[data-theme="dark"] .editor-confirm-dialog {
  background: var(--theme-surface-soft) !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .editor-week-day.no-data {
  background: #0c151f !important;
  color: var(--theme-muted) !important;
}

html[data-theme="dark"] .version-item.active {
  background: #19435f !important;
  border-color: #55b8ff !important;
  box-shadow: 0 0 0 2px rgba(85, 184, 255, 0.2), 0 14px 30px rgba(0, 0, 0, 0.26) !important;
}

/* Editor-specific states. These selectors deliberately mirror the light
   editor's hierarchy so day/version selection stays equally obvious. */
html[data-theme="dark"] .editor-week-day {
  background: #181d24 !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  color: #e8f0f7 !important;
}

html[data-theme="dark"] .editor-week-day.has-data {
  background: #152b3c !important;
  border-color: rgba(98, 193, 255, 0.42) !important;
  color: #dff3ff !important;
}

html[data-theme="dark"] .editor-week-day.no-data {
  background: #11161c !important;
  border-color: rgba(218, 231, 241, 0.22) !important;
  color: #a2afbb !important;
}

html[data-theme="dark"] .editor-week-day.active {
  background: #1678ba !important;
  border-color: #74c5ff !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2px rgba(116, 197, 255, 0.2), 0 8px 22px rgba(21, 120, 186, 0.32) !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item {
  background: linear-gradient(145deg, #181d24, #141a21) !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  color: #e8f0f7 !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item:hover,
html[data-theme="dark"] .editor-versions-panel .version-item:focus-visible {
  border-color: rgba(98, 193, 255, 0.56) !important;
  background: #1c2731 !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item.active {
  background: #1678ba !important;
  border-color: #74c5ff !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(116, 197, 255, 0.22), 0 12px 26px rgba(0, 0, 0, 0.32) !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item.active:hover,
html[data-theme="dark"] .editor-versions-panel .version-item.active:focus-visible {
  background: #1678ba !important;
  border-color: #74c5ff !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item-metadata,
html[data-theme="dark"] .editor-versions-panel .version-item small {
  color: #a9c8dc !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item.active .version-item-metadata,
html[data-theme="dark"] .editor-versions-panel .version-item.active small {
  color: rgba(255, 255, 255, 0.9) !important;
}

html[data-theme="dark"] .editor-versions-panel .version-tag {
  background: #20384c !important;
  color: #b9e3ff !important;
}

html[data-theme="dark"] .editor-versions-panel .version-item.active .version-tag,
html[data-theme="dark"] .editor-versions-panel .version-item.active .version-item-actions .secondary-button {
  background: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
  border-color: transparent !important;
}

/* The teacher registry is rendered as cards on desktop. The base editor
   stylesheet has a white gradient fallback, so replace it explicitly. */
html[data-theme="dark"] .editor-teachers-panel .editor-teachers-table tr {
  background: linear-gradient(145deg, #181d24, #111820) !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  color: #e8f0f7 !important;
}

html[data-theme="dark"] .editor-teachers-panel .editor-teachers-table tr:hover {
  border-color: rgba(98, 193, 255, 0.42) !important;
  background: linear-gradient(145deg, #1c2731, #141c24) !important;
}

html[data-theme="dark"] .editor-teachers-panel .editor-teachers-table td::before,
html[data-theme="dark"] .editor-teachers-panel .teacher-usage-cell,
html[data-theme="dark"] .editor-teachers-panel .teacher-filter-text,
html[data-theme="dark"] .editor-teachers-panel .editor-kicker,
html[data-theme="dark"] .editor-teachers-panel .editor-muted {
  color: #a2afbb !important;
}

html[data-theme="dark"] .editor-teachers-panel .teacher-id-cell,
html[data-theme="dark"] .editor-teachers-panel .teacher-stat strong {
  color: #74c5ff !important;
}

html[data-theme="dark"] .editor-teachers-panel .teacher-stat,
html[data-theme="dark"] .editor-teachers-panel .teacher-filter-control {
  background: #181d24 !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  color: #e8f0f7 !important;
}

html[data-theme="dark"] .editor-teachers-panel input,
html[data-theme="dark"] .editor-teacher-search input,
html[data-theme="dark"] .editor-main input,
html[data-theme="dark"] .editor-sidebar input,
html[data-theme="dark"] .editor-date-button {
  background: #0d1823 !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  color: #e8f0f7 !important;
}

html[data-theme="dark"] .editor-teachers-panel input::placeholder,
html[data-theme="dark"] .editor-teacher-search input::placeholder {
  color: #7f96a8 !important;
}

html[data-theme="dark"] .editor-teachers-panel .row-delete-button {
  background: transparent !important;
  color: #ff8794 !important;
  border-color: rgba(255, 120, 136, 0.3) !important;
}

/* The calendar uses older page-level colors, so give it an explicit dark
   palette instead of letting the bright legacy blue leak through. */
html[data-theme="dark"] .calendar-modal-content {
  background: #12161c !important;
  border-color: rgba(218, 231, 241, 0.17) !important;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.46) !important;
}

html[data-theme="dark"] .calendar-months-sidebar,
html[data-theme="dark"] .months-scroll-container {
  background: #10161c !important;
  border-color: rgba(218, 231, 241, 0.14) !important;
  scrollbar-color: #367a9e #10161c !important;
}

html[data-theme="dark"] .month-item {
  background: #181d24 !important;
  border: 1px solid rgba(218, 231, 241, 0.16) !important;
  color: #dce9f1 !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .month-item:hover {
  background: #1d2933 !important;
  border-color: rgba(98, 193, 255, 0.42) !important;
  transform: none !important;
}

html[data-theme="dark"] .month-item.active {
  background: #24516c !important;
  border-color: #62c1ff !important;
  color: #ffffff !important;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22) !important;
  transform: none !important;
}

html[data-theme="dark"] .month-item.no-schedule {
  background: #12181f !important;
  color: #718391 !important;
  border-color: rgba(218, 231, 241, 0.1) !important;
}

html[data-theme="dark"] .calendar-header {
  background: #1b4058 !important;
  color: #f0f8fd !important;
}

html[data-theme="dark"] .calendar-nav {
  background: #263b49 !important;
  border: 1px solid rgba(218, 231, 241, 0.18) !important;
  color: #e7f5fc !important;
}

html[data-theme="dark"] .calendar-nav:hover {
  background: #315469 !important;
}

html[data-theme="dark"] .calendar-days-header {
  background: #121a22 !important;
  border-bottom-color: rgba(218, 231, 241, 0.14) !important;
  color: #a9bac6 !important;
}

html[data-theme="dark"] .calendar-days-header div {
  color: #a9bac6 !important;
}

html[data-theme="dark"] .calendar-day {
  background: transparent !important;
  border-color: transparent !important;
  color: #dce9f1 !important;
}

html[data-theme="dark"] .calendar-day:hover:not(.disabled):not(.empty) {
  background: #1d2b35 !important;
  border-color: rgba(98, 193, 255, 0.3) !important;
}

html[data-theme="dark"] .calendar-day.available {
  color: #dce9f1 !important;
  border-color: rgba(98, 193, 255, 0.28) !important;
}

html[data-theme="dark"] .calendar-day.available:hover {
  background: #24516c !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .calendar-day.selected {
  background: #267fb8 !important;
  border-color: #74c5ff !important;
  color: #ffffff !important;
  box-shadow: 0 5px 14px rgba(38, 127, 184, 0.25) !important;
}

html[data-theme="dark"] .calendar-day.today {
  box-shadow: inset 0 0 0 1px #62c1ff !important;
  color: #dcefff !important;
}

html[data-theme="dark"] .calendar-day.unavailable,
html[data-theme="dark"] .calendar-day.other-month,
html[data-theme="dark"] .calendar-day.empty {
  color: #596c79 !important;
}

html[data-theme="dark"] .calendar-footer {
  background: #12161c !important;
  border-top-color: rgba(218, 231, 241, 0.14) !important;
}

html[data-theme="dark"] .calendar-today-btn {
  background: #1c2a34 !important;
  color: #dce9f1 !important;
  border: 1px solid rgba(218, 231, 241, 0.14) !important;
}

html[data-theme="dark"] .calendar-today-btn:hover {
  background: #2a4a5d !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .calendar-modal,
html[data-theme="dark"] .modal {
  background: rgba(1, 6, 11, 0.78) !important;
}

html[data-theme="dark"] .calendar-months-sidebar {
  background: #10161c !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .calendar-main-area {
  background: #12161c !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .calendar-days-header {
  background: #121a22 !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .calendar-footer {
  background: #12161c !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .calendar-day.today {
  border-color: #62c1ff !important;
  color: #dcefff !important;
}

html[data-theme="dark"] .calendar-day.unavailable,
html[data-theme="dark"] .calendar-day.other-month,
html[data-theme="dark"] .calendar-day.empty {
  color: #596c79 !important;
}

html[data-theme="dark"] .footer-container,
html[data-theme="dark"] footer {
  background: #090c10 !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .footer-link,
html[data-theme="dark"] .tg-button {
  background: #10161c !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

html[data-theme="dark"] .footer-link:hover,
html[data-theme="dark"] .tg-button:hover {
  background: #18222b !important;
  color: #ffffff !important;
}

/* Все иконки футера используют один спокойный серый стиль. */
.footer-link .link-icon,
.tg-link .link-icon {
  width: 48px !important;
  height: 48px !important;
  flex: 0 0 48px !important;
  border-radius: 50% !important;
  background: rgba(122, 137, 151, 0.24) !important;
  color: #c8d1d8 !important;
}

.footer-link .link-icon svg,
.tg-link .tg-icon {
  width: 24px !important;
  height: 24px !important;
  color: #c8d1d8 !important;
  filter: none !important;
  transform: none !important;
}

.footer-link:hover .link-icon {
  background: rgba(164, 178, 190, 0.32) !important;
  color: #f0f4f6 !important;
}

.footer-link:hover .link-icon svg,
.tg-link:hover .tg-icon {
  color: #f0f4f6 !important;
  transform: none !important;
}

.tg-button .tg-icon {
  width: 24px !important;
  height: 24px !important;
  color: #c8d1d8 !important;
  filter: none !important;
}

/* Самолётик сохраняет исходную форму, но визуально заполняет значок так же, как соседние пиктограммы. */
.tg-icon path {
  transform: scale(1.24);
  transform-box: fill-box;
  transform-origin: center;
}

html[data-theme="dark"] .footer-link small,
html[data-theme="dark"] .footer-content p,
html[data-theme="dark"] .link-text small,
html[data-theme="dark"] .start-date,
html[data-theme="dark"] #last-updated,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .editor-muted,
html[data-theme="dark"] .editor-meta,
html[data-theme="dark"] label span {
  color: var(--theme-muted) !important;
}

html[data-theme="dark"] #schedule-title,
html[data-theme="dark"] #total-pairs,
html[data-theme="dark"] .student-number,
html[data-theme="dark"] .error-content h2,
html[data-theme="dark"] .selector-hint,
html[data-theme="dark"] .primary-color {
  color: #74c5ff !important;
}

/* На страницах с футером переключатель живёт в отдельной правой позиции. */
footer {
  position: relative;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

footer .footer-container,
footer .footer-content,
footer .footer-links {
  box-sizing: border-box !important;
}

footer .theme-toggle {
  position: absolute !important;
  top: calc(50% + 10px) !important;
  right: max(18px, env(safe-area-inset-right)) !important;
  bottom: auto !important;
  width: 82px !important;
  height: 82px !important;
  min-width: 82px !important;
  min-height: 82px !important;
  transform: translateY(-50%) !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  color: #d5dde3 !important;
  box-shadow: none !important;
  border-radius: 12px !important;
}

footer .theme-toggle:hover {
  transform: translateY(calc(-50% - 1px)) !important;
  background: rgba(255, 255, 255, 0.2) !important;
}

footer .theme-toggle:active {
  transform: translateY(-50%) scale(0.96) !important;
}

footer .theme-toggle-icon {
  font-size: 1.18rem;
}

/* На страницах без футера кнопка остаётся плавающей и не меняет разметку. */
.theme-toggle {
  position: fixed !important;
  top: auto !important;
  left: auto !important;
  right: max(18px, env(safe-area-inset-right)) !important;
  bottom: calc(var(--theme-toggle-bottom, 18px) + env(safe-area-inset-bottom)) !important;
  z-index: 2000 !important;
  width: 52px !important;
  height: 52px !important;
  min-width: 52px !important;
  min-height: 52px !important;
  margin: 0 !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center !important;
  border: 1px solid rgba(0, 122, 204, 0.24) !important;
  border-radius: 12px !important;
  background: rgba(255, 255, 255, 0.95) !important;
  color: #15557d !important;
  box-shadow: 0 12px 28px rgba(8, 32, 51, 0.2) !important;
  cursor: pointer !important;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease !important;
}

.theme-toggle:hover {
  transform: translateY(-2px) !important;
}

.theme-toggle:active {
  transform: translateY(0) scale(0.96) !important;
}

.theme-toggle-icon {
  font-size: 1.42rem;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
  line-height: 1;
  user-select: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
}

.theme-toggle-icon svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle-icon.is-switching {
  animation: theme-icon-swap 0.32s ease both;
}

@keyframes theme-icon-swap {
  0% { opacity: 0; transform: rotate(-22deg) scale(0.62); }
  65% { opacity: 1; transform: rotate(5deg) scale(1.08); }
  100% { opacity: 1; transform: rotate(0) scale(1); }
}

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

html[data-theme="dark"] .theme-toggle {
  background: #132535 !important;
  border-color: rgba(104, 194, 255, 0.42) !important;
  color: #c7d9e5 !important;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42) !important;
}

html[data-theme="dark"] footer .theme-toggle {
  background: #10161c !important;
  border-color: var(--theme-line) !important;
  color: #d5dde3 !important;
  box-shadow: none !important;
}

@media (max-width: 480px) {
  .theme-toggle {
    right: max(14px, env(safe-area-inset-right)) !important;
    bottom: calc(var(--theme-toggle-bottom, 14px) + env(safe-area-inset-bottom)) !important;
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
  }

  footer .theme-toggle {
    top: 8px !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    transform: none !important;
    border-radius: 10px !important;
  }

  footer .theme-toggle-icon {
    font-size: 1.05rem;
  }

  footer .theme-toggle:hover {
    transform: translateY(-1px) !important;
  }

  footer .theme-toggle:active {
    transform: scale(0.96) !important;
  }
}

@media (min-width: 769px) and (max-width: 1400px) {
  footer {
    padding-bottom: 92px !important;
  }

  footer .theme-toggle {
    top: auto !important;
    right: max(18px, env(safe-area-inset-right)) !important;
    bottom: 18px !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    transform: none !important;
    border-radius: 10px !important;
  }

  footer .theme-toggle:hover {
    transform: translateY(-1px) !important;
  }

  footer .theme-toggle:active {
    transform: scale(0.96) !important;
  }
}

@media (max-width: 768px) {
  footer {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
  }

  footer .footer-links {
    padding-right: 0;
  }

  footer .footer-link {
    width: 100% !important;
    max-width: none !important;
    flex: none !important;
  }

  footer .theme-toggle {
    top: auto !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
    width: 52px !important;
    height: 52px !important;
    min-width: 52px !important;
    min-height: 52px !important;
    transform: none !important;
    border-radius: 12px !important;
  }

  footer .theme-toggle:hover {
    transform: translateY(-1px) !important;
  }

  footer .theme-toggle:active {
    transform: scale(0.96) !important;
  }
}

/* Final responsive footer layout. The switcher is a real footer item now,
   so it cannot overlap cards or jump above the footer on narrow screens. */
html,
body {
  min-height: 100% !important;
}

body {
  display: flex !important;
  flex-direction: column !important;
  min-height: 100vh !important;
}

body > main {
  flex: 1 0 auto !important;
}

/* These screens already have their own internal centering; the page itself
   must still leave room for the footer below it. */
body > main.editor-login-wrap,
body > main.download-container {
  min-height: 0 !important;
}

footer {
  width: 100% !important;
  max-width: none !important;
  margin-top: auto !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  border-radius: 0 !important;
}

footer .footer-links {
  display: flex !important;
  align-items: stretch !important;
  justify-content: center !important;
  flex-wrap: wrap !important;
  gap: 16px !important;
}

footer .footer-links > .footer-link {
  flex: 1 1 clamp(220px, 24vw, 340px) !important;
  width: auto !important;
  min-width: min(220px, 100%) !important;
  max-width: none !important;
}

footer .footer-links > .theme-toggle,
footer > .theme-toggle {
  position: static !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
    flex: 0 1 82px !important;
  width: 82px !important;
  height: 82px !important;
  min-width: 82px !important;
  min-height: 82px !important;
  margin: 0 0 0 auto !important;
  padding: 0 !important;
  border-radius: 12px !important;
}

footer .theme-toggle,
footer.theme-footer .theme-toggle {
  background: var(--theme-toggle-bg) !important;
  border-color: var(--theme-toggle-border) !important;
  color: var(--theme-toggle-color) !important;
  box-shadow: 0 8px 20px rgba(8, 32, 51, 0.12) !important;
}

/* In the full footer the switcher uses exactly the same tile treatment as
   the footer links. */
footer:has(.footer-container) .theme-toggle {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
  box-shadow: none !important;
}

/* Старое правило тёмного футера было более специфичным и перекрывало
   общую палитру. Оставляем единый фон и для обычного, и для служебного футера. */
html[data-theme="dark"] footer .theme-toggle,
html[data-theme="dark"] footer.theme-footer .theme-toggle {
  background: var(--theme-toggle-bg) !important;
  border-color: var(--theme-toggle-border) !important;
  color: var(--theme-toggle-color) !important;
}

html[data-theme="dark"] footer:has(.footer-container) .theme-toggle {
  background: #10161c !important;
  border-color: var(--theme-line) !important;
  color: var(--text-color) !important;
}

footer .theme-toggle:hover,
footer.theme-footer .theme-toggle:hover {
  background: var(--theme-toggle-hover) !important;
  transform: translateY(-1px) !important;
}

footer.theme-footer {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  min-height: 114px !important;
  padding: 16px 18px !important;
  margin-top: auto !important;
  background: transparent !important;
  box-shadow: none !important;
}

@media (min-width: 769px) {
  footer:has(.footer-container) {
    padding-bottom: 0 !important;
  }
}

/* Keep the switcher against the footer's right wall while there is enough
   room for the four regular links. It becomes a normal final item below the
   breakpoint, so wrapping remains natural. */
@media (min-width: 1400px) {
  footer .footer-links {
    padding-right: 110px !important;
  }

  footer .footer-links > .theme-toggle,
  footer > .theme-toggle {
    position: absolute !important;
    top: calc(50% + 10px) !important;
    right: max(18px, env(safe-area-inset-right)) !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    margin: 0 !important;
  }

  footer .theme-toggle:hover {
    transform: translateY(calc(-50% - 1px)) !important;
  }

  footer .theme-toggle:active {
    transform: translateY(-50%) scale(0.96) !important;
  }
}

@media (max-width: 768px) {
  footer:has(.footer-container) {
    padding-bottom: 0 !important;
  }

  footer .footer-links {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    padding-right: 0 !important;
    gap: 12px !important;
  }

  footer .footer-links > .theme-toggle,
  footer > .theme-toggle,
  footer.theme-footer .theme-toggle {
    width: 82px !important;
    height: 82px !important;
    min-width: 82px !important;
    min-height: 82px !important;
    justify-self: end !important;
    margin: 0 0 0 auto !important;
    border-radius: 12px !important;
  }

  footer.theme-footer {
    min-height: 86px !important;
    padding: 12px 16px !important;
  }
}

/* Non-home pages: keep the compact control when the footer fits on one row.
   At narrower widths it becomes the same flexible footer item as the rest,
   so every row is filled evenly without overlap or detached positioning. */
@media (min-width: 1101px) {
  html:not(.home-page) footer .footer-links {
    padding-right: 68px !important;
  }

  html:not(.home-page) footer .footer-links > .theme-toggle,
  html:not(.home-page) footer > .theme-toggle {
    position: absolute !important;
    top: calc(50% + 10px) !important;
    right: max(18px, env(safe-area-inset-right)) !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    flex: 0 0 52px !important;
    width: 52px !important;
    height: 52px !important;
    min-width: 52px !important;
    min-height: 52px !important;
    margin: 0 !important;
  }

  html:not(.home-page) footer .theme-toggle:hover {
    transform: translateY(calc(-50% - 1px)) !important;
  }

  html:not(.home-page) footer .theme-toggle:active {
    transform: translateY(-50%) scale(0.96) !important;
  }
}

@media (min-width: 769px) and (max-width: 1100px) {
  html:not(.home-page) footer .footer-links {
    justify-content: stretch !important;
  }

  html:not(.home-page) footer .footer-links > .theme-toggle {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    flex: 1 1 clamp(220px, 24vw, 340px) !important;
    width: auto !important;
    height: 82px !important;
    min-width: min(220px, 100%) !important;
    min-height: 82px !important;
    margin: 0 !important;
  }

  html:not(.home-page) footer > .theme-toggle {
    position: static !important;
    transform: none !important;
    width: 82px !important;
    height: 82px !important;
    min-width: 82px !important;
    min-height: 82px !important;
    margin: 0 0 0 auto !important;
  }
}

@media (max-width: 768px) {
  html:not(.home-page) footer .footer-links {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    padding-right: 0 !important;
    gap: 12px !important;
  }

  html:not(.home-page) footer .footer-links > .theme-toggle,
  html:not(.home-page) footer > .theme-toggle {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    flex: none !important;
    width: 100% !important;
    height: 72px !important;
    min-width: 0 !important;
    min-height: 72px !important;
    margin: 0 !important;
    border-radius: 12px !important;
  }

  html:not(.home-page) footer .theme-toggle:hover,
  html:not(.home-page) footer .theme-toggle:active {
    transform: none !important;
  }
}

@media (max-width: 480px) {
  html:not(.home-page) footer .footer-links > .theme-toggle,
  html:not(.home-page) footer > .theme-toggle {
    height: 64px !important;
    min-height: 64px !important;
  }
}

/* The homepage keeps its desktop placement, but on a narrow screen the
   switcher must fill the same row width as the other footer cards too. */
@media (max-width: 768px) {
  footer .footer-links > .theme-toggle,
  footer > .theme-toggle,
  footer.theme-footer .theme-toggle {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    flex: none !important;
    width: 100% !important;
    height: 72px !important;
    min-width: 0 !important;
    min-height: 72px !important;
    margin: 0 !important;
    border-radius: 12px !important;
  }

  footer .theme-toggle:hover,
  footer .theme-toggle:active {
    transform: none !important;
  }
}
