/* Shared theme switch and the few component corrections that cannot be
   expressed through semantic tokens alone. Loaded after each surface CSS. */

.theme-toggle {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-sm);
  background: rgb(var(--surface));
  color: rgb(var(--text-secondary));
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.theme-toggle:hover {
  border-color: rgb(var(--border-strong));
  background: rgb(var(--surface-subtle));
  color: rgb(var(--text-primary));
}

.theme-toggle:focus-visible {
  outline: 2px solid rgb(var(--focus-ring));
  outline-offset: 2px;
}

.theme-toggle__icons {
  position: relative;
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  place-items: center;
}

.theme-toggle__icons > svg,
.theme-toggle__icons > i {
  position: absolute;
  width: 16px;
  height: 16px;
  transition:
    opacity var(--motion-base) var(--ease-out),
    transform var(--motion-base) var(--ease-emphasis);
}

.theme-toggle__sun { opacity: 1; transform: rotate(0) scale(1); }
.theme-toggle__moon { opacity: 0; transform: rotate(-18deg) scale(.72); }
[data-theme="dark"] .theme-toggle__sun { opacity: 0; transform: rotate(18deg) scale(.72); }
[data-theme="dark"] .theme-toggle__moon { opacity: 1; transform: rotate(0) scale(1); }

.theme-segmented-toggle {
  display: grid;
  width: 100%;
  min-height: 42px;
  grid-template-columns: 1fr 52px 1fr;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: rgb(var(--text-muted));
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
}
.theme-segmented-toggle:focus-visible { outline: 2px solid rgb(var(--focus-ring)); outline-offset: 2px; border-radius: 8px; }
.theme-segmented-toggle__label { transition: color var(--motion-fast) var(--ease-out); }
.theme-segmented-toggle__label--light { color: rgb(var(--text-primary)); text-align: right; }
.theme-segmented-toggle__label--dark { text-align: left; }
.theme-segmented-toggle__track { position: relative; display: block; width: 52px; height: 28px; padding: 3px; border-radius: 999px; background: rgb(var(--action)); box-shadow: inset 0 0 0 1px rgb(var(--action) / .12); }
.theme-segmented-toggle__thumb { display: block; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgb(15 32 51 / .24); transform: translateX(0); transition: transform var(--motion-base) var(--ease-emphasis); }
[data-theme="dark"] .theme-segmented-toggle__thumb { transform: translateX(24px); }
[data-theme="dark"] .theme-segmented-toggle__label--light { color: rgb(var(--text-muted)); }
[data-theme="dark"] .theme-segmented-toggle__label--dark { color: rgb(var(--text-primary)); }

/* The device identifiers are scanning-critical data, so light mode keeps them
   on solid semantic colors instead of reducing their contrast with opacity. */
:root:not([data-theme="dark"]) .inventory-table__asset-id,
:root:not([data-theme="dark"]) .inventory-table__serial { color: rgb(var(--text-secondary)) !important; }
:root:not([data-theme="dark"]) .inventory-table__device-name { color: rgb(var(--text-primary)); font-weight: 600; }
:root:not([data-theme="dark"]) .inventory-table__device-meta { color: rgb(var(--text-secondary)); }

.theme-toggle--floating {
  position: fixed;
  z-index: 50;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  box-shadow: var(--shadow-xs);
}

.page-header-actions__theme { display: flex; }
.mobile-appbar__account { display: flex; align-items: center; gap: 2px; }
.public-topbar .theme-toggle { margin-left: auto; flex: 0 0 auto; }

.account-popover__theme .theme-toggle {
  width: 100%;
  min-height: 40px;
  justify-content: flex-start;
  padding: 8px 9px;
  border-color: transparent;
  background: transparent;
  color: rgb(var(--text-primary));
  font-size: 13px;
  font-weight: 500;
}

.account-popover__theme .theme-toggle:hover {
  border-color: transparent;
  background: rgb(var(--surface-subtle));
}

[data-theme="dark"] .mobile-appbar__brand { color: rgb(var(--text-primary)); }
[data-theme="dark"] .inventory-filter-bar .inventory-filter-bar__search .input {
  box-shadow: 0 1px 2px rgb(0 0 0 / .28), inset 0 1px 0 rgb(255 255 255 / .035);
}
[data-theme="dark"] .public-signature-canvas,
[data-theme="dark"] .public-signature-preview { color-scheme: light; }

@media (max-width: 899px) {
  .page-header-actions__theme { display: none; }
  .mobile-appbar { grid-template-columns: 88px minmax(0, 1fr) 88px; }
  .mobile-appbar__menu { justify-self: start; }
  .mobile-appbar__account .theme-toggle {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-color: transparent;
    background: transparent;
  }
  .mobile-appbar__account .theme-toggle__label { display: none; }
}

body > header:not(.mobile-appbar) .theme-toggle {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}
body > header:not(.mobile-appbar) .theme-toggle__label { display: none; }

@media (max-width: 480px) {
  .public-topbar .theme-toggle {
    width: 40px;
    min-width: 40px;
    padding-inline: 0;
  }
  .public-topbar .theme-toggle__label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle__icons > svg,
  .theme-toggle__icons > i,
  .theme-segmented-toggle__label,
  .theme-segmented-toggle__thumb { transition: none; }
}
