:root {
  --product-image-bg: #edf0f6;
  --catalog-photo-bg: #000;
}

.header-preferences {
  --header-control-size: 37px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.header-preferences :is(.language-toggle, .theme-toggle, .admin-logout) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--header-control-size);
  height: var(--header-control-size);
  min-height: var(--header-control-size);
  padding: 0;
  flex: 0 0 var(--header-control-size);
}

:is(.theme-toggle, .admin-logout) {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

:is(.theme-toggle, .admin-logout):hover {
  background: var(--surface-muted);
}

:is(.theme-toggle, .admin-logout):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

:is(.theme-toggle, .admin-logout) svg {
  flex: 0 0 auto;
}

:root[data-theme="light"] .theme-icon-sun,
:root[data-theme="dark"] .theme-icon-moon {
  display: none;
}

@media (max-width: 800px), (pointer: coarse) {
  .header-preferences {
    --header-control-size: 44px;
  }
}

@media screen {
  /* Match the shared canvas selector so resize and overscroll follow the theme. */
  html:root[data-theme="light"] {
    color-scheme: light;
    background-color: #f6f7fb;
  }

  :root[data-theme="light"] body {
    color-scheme: light;
    --bg: #f6f7fb;
    --surface: #fff;
    --catalog-photo-bg: var(--surface);
    --surface-muted: #edf0f6;
    --text: #1c2333;
    --muted: #596579;
    --border: #d2d9e5;
    --accent: #7329bd;
    --accent-strong: #592091;
    --danger: #b42338;
    --shadow: 0 8px 28px rgba(28, 35, 51, 0.07);
    --home-bg: var(--bg);
    --home-panel: var(--surface);
    --home-cyan: #08766f;
    --home-purple: var(--accent);
    --home-green: #23713b;
    --home-text: var(--text);
    --home-muted: var(--muted);
    background: var(--bg);
    color: var(--text);
  }

  html:root[data-theme="dark"] {
    color-scheme: dark;
    background-color: #050209;
  }

  /* Admin pages use the shared palette; apply their dark appearance explicitly. */
  :root[data-theme="dark"] body:not(.home-page):not(.shop-theme) {
    color-scheme: dark;
    --bg: #10121b;
    --surface: #1a1e2b;
    --surface-muted: #252b3b;
    --text: #f5f7fb;
    --muted: #a9b5c7;
    --border: #3e485e;
    --accent: #9d18ff;
    --accent-strong: #7b13d1;
    --danger: #ff5a76;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  }

  :root[data-theme="dark"] body:not(.home-page):not(.shop-theme) :is(input, select, textarea) {
    background: var(--surface);
    color: var(--text);
  }

  :root[data-theme="dark"] body:not(.home-page):not(.shop-theme) :is(.action-icon-button:not(.danger),
    .table-sort-button, .discount-scroll-link, .discount-page-up) img {
    filter: invert(1);
  }

  :root[data-theme="dark"] body .privacy-overdue {
    color: var(--danger);
  }

  :root[data-theme="light"] body :is(.site-header, .admin-header, .home-header) {
    background: rgba(255, 255, 255, 0.96);
    border-bottom-color: var(--border);
  }

  :root[data-theme="light"] body :is(.page-title, .home-brand, .home-contact-link, .home-phone-main,
    .home-benefits strong, .home-inquiry-cta h2, .home-footer h2, .home-promo-card span, .home-promo-card em) {
    color: var(--text);
  }

  :root[data-theme="light"] body :is(.nav a, .home-nav a, .home-admin-link):hover:not(.has-items, .has-new-orders, .has-new-inquiries, .has-new-privacy-requests) {
    color: var(--accent);
  }

  :root[data-theme="light"] body :is(.language-toggle, .theme-toggle, .admin-logout, .header-icon-link,
    .home-icon-link, .home-social-link, .button.secondary) {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
  }

  :root[data-theme="light"] body :is(.language-toggle:hover, .theme-toggle:hover, .admin-logout:hover, .header-icon-link:hover,
    .home-icon-link:hover, .home-social-link:hover, .button.secondary:hover) {
    border-color: var(--accent);
    background: var(--surface-muted);
  }

  :root[data-theme="light"] body :is(.panel, .product-card, .admin-table-shell, .cart-row,
    .account-card, .account-order, .empty-state, .shop-modal, .product-inquiry-modal,
    .home-benefits, .home-category-card, .home-product-card, .home-promo-card, .home-inquiry-cta) {
    border-color: var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  :root[data-theme="light"] body :is(.account-card, .account-order, .empty-state) {
    background: var(--surface-muted);
    box-shadow: none;
  }

  :root[data-theme="light"] body :is(input, select, textarea) {
    border-color: var(--border);
    background-color: var(--surface);
    color: var(--text);
  }

  :root[data-theme="light"] body :is(input, select, textarea):focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(115, 41, 189, 0.12);
  }

  :root[data-theme="light"] body :is(.catalog-search-field, .category-search-field, .home-search):focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(115, 41, 189, 0.12);
  }

  :root[data-theme="light"] body :is(.catalog-search-field, .category-search-field, .home-search) input {
    background: transparent;
    box-shadow: none;
  }

  :root[data-theme="light"] body input::placeholder,
  :root[data-theme="light"] body textarea::placeholder {
    color: var(--muted);
    opacity: 1;
  }

  :root[data-theme="light"] body .home-search {
    border-color: var(--home-cyan);
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  :root[data-theme="light"] body .home-search-below-hero button {
    color: #fff;
  }

  :root[data-theme="light"] body .home-search-below-hero button:hover {
    background: #065d58;
  }

  :root[data-theme="light"] body .home-search-below-hero button:focus-visible {
    outline-color: var(--accent);
  }

  :root[data-theme="light"] body :is(.home-category-card:hover, .home-product-card:hover, .home-promo-card:hover) {
    border-color: var(--accent);
    box-shadow: 0 8px 28px rgba(115, 41, 189, 0.12);
  }

  /* A light photo surface hides white cutout fringes without altering product colours. */
  body :is(.home-product-card__image, .product-image-row > img) {
    background: var(--product-image-bg);
    color: #596579;
  }

  body :is(.product-card__image, .product-detail__image, .product-detail__image-button,
    .product-detail__image-button:hover, .product-detail__thumbs button,
    .product-gallery-lightbox, .product-gallery-lightbox__inner img) {
    background: var(--catalog-photo-bg);
    color: var(--muted);
  }

  :root[data-theme="light"] body .home-category-card__image {
    background: var(--surface-muted);
  }

  :root[data-theme="light"] body .home-category-card__art {
    text-shadow: none;
  }

  :root[data-theme="light"] body .home-card-arrow img {
    filter: invert(1);
  }

  :root[data-theme="light"] body :is(.home-cta, .home-promo-card) .home-arrow-icon {
    filter: none;
  }

  :root[data-theme="light"] body .home-social-link img[src$="icon_location.svg"] {
    filter: brightness(0) saturate(100%);
  }

  :root[data-theme="light"] body .category-option__icon {
    filter: invert(1);
  }

  :root[data-theme="light"] body .account-icon-button:not(.danger) img {
    filter: invert(1);
  }

  :root[data-theme="light"] body :is(.home-benefits article, .home-brand-strip) {
    border-color: var(--border);
  }

  :root[data-theme="light"] body .home-cta {
    color: var(--text);
    box-shadow: none;
  }

  :root[data-theme="light"] body .home-cta:hover {
    background: var(--surface-muted);
  }

  :root[data-theme="light"] body .home-inquiry-cta button {
    border-color: var(--accent);
  }

  :root[data-theme="light"] body .home-inquiry-cta button:hover,
  :root[data-theme="light"] body .home-product-card__button:hover {
    background: var(--accent-strong);
    box-shadow: none;
  }

  :root[data-theme="light"] body :is(.product-detail__stock, .stock-label).is-available,
  :root[data-theme="light"] body .privacy-controls [data-state="success"] {
    color: #23713b;
  }

  :root[data-theme="light"] body .home-product-card .is-empty {
    color: var(--danger);
  }

  :root[data-theme="light"] body :is(.product-gallery-lightbox__close, .product-gallery-lightbox__nav,
    .product-gallery-lightbox__count) {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
  }

  :root[data-theme="light"] body :is(.product-gallery-lightbox__close, .product-gallery-lightbox__nav):hover {
    background: var(--surface-muted);
    border-color: var(--accent);
  }
}
