/*
 * Ultraviolet UI primitives
 *
 * This file owns reusable visual behavior across Public, Auth, and Lighthouse.
 * Surface styles may position these components, but must not redefine their
 * color, typography, geometry, or interaction states.
 */

:where(.button, .custom-select) {
  --ui-control-context-tint: color-mix(
    in srgb,
    var(--ui-primary, var(--control-primary-bg, var(--auth-violet, #8b5cf6))) 38%,
    var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))))
  );
  --ui-control-layer: color-mix(in srgb, var(--ui-control-context-tint) 10%, transparent);
  --ui-control-layer-hover: color-mix(in srgb, var(--ui-control-context-tint) 16%, transparent);
}

.button {
  --ui-button-background: var(--ui-control-layer);
  --ui-button-background-hover: var(--ui-control-layer-hover);
  --ui-button-color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
  --ui-button-shadow: var(--ui-control-shadow, var(--control-shadow, none));
  --ui-button-shadow-hover: var(--ui-control-shadow-hover, var(--control-shadow-hover, none));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem)));
  padding-inline: clamp(1rem, 0.9rem + 0.35vw, 1.375rem);
  padding-block: clamp(0.5rem, 0.45rem + 0.15vw, 0.625rem);
  border: 0;
  border-radius: var(--ui-control-radius, var(--control-radius, var(--auth-control-radius, 0.375rem)));
  background: var(--ui-button-background);
  box-shadow: var(--ui-button-shadow);
  color: var(--ui-button-color);
  cursor: pointer;
  font: inherit;
  font-size: clamp(0.8125rem, 0.785rem + 0.08vw, 0.875rem);
  font-weight: 720;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
  white-space: normal;
  transition: background-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease, color 0.14s ease, opacity 0.14s ease;
}

.button:hover {
  background: var(--ui-button-background-hover);
  box-shadow: var(--ui-button-shadow-hover);
}

.button:active {
  background: var(--ui-button-background-hover);
}

.button[aria-expanded="true"] {
  --ui-button-background: var(--ui-primary-surface, color-mix(in srgb, var(--ui-primary, var(--control-primary-bg, var(--auth-violet, #8b5cf6))) 82%, #160b33));
  --ui-button-background-hover: var(--ui-primary-surface-hover, color-mix(in srgb, var(--ui-primary-hover, var(--control-primary-bg-hover, var(--auth-violet-strong, #9a6cff))) 82%, #160b33));
  --ui-button-color: var(--ui-on-primary, #fff);
}

.button.primary {
  --ui-button-background: var(--ui-primary-surface, color-mix(in srgb, var(--ui-primary, var(--control-primary-bg, var(--auth-violet, #8b5cf6))) 82%, #160b33));
  --ui-button-background-hover: var(--ui-primary-surface-hover, color-mix(in srgb, var(--ui-primary-hover, var(--control-primary-bg-hover, var(--auth-violet-strong, #9a6cff))) 82%, #160b33));
  --ui-button-color: var(--ui-on-primary, #fff);
  --ui-button-shadow: var(--ui-control-shadow-active, var(--control-shadow-active, none));
  --ui-button-shadow-hover: var(--ui-control-shadow-active, var(--control-shadow-active, none));
}

.button.ghost {
  --ui-button-background: transparent;
  --ui-button-background-hover: color-mix(in srgb, var(--ui-primary, var(--control-primary-bg, var(--auth-violet, #8b5cf6))) 10%, transparent);
  --ui-button-shadow: none;
  --ui-button-shadow-hover: none;
}

.button.header-link {
  --ui-button-background: transparent;
  --ui-button-background-hover: transparent;
  --ui-button-color: var(--ui-muted, var(--portal-muted, var(--auth-muted, var(--muted, #b6b0c8))));
  --ui-button-shadow: none;
  --ui-button-shadow-hover: none;
}

.button.header-link:hover,
.button.header-link:active,
.button.header-link[aria-expanded="true"] {
  --ui-button-background: transparent;
  --ui-button-background-hover: transparent;
  --ui-button-color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
}

.button.compact {
  padding-inline: clamp(0.75rem, 0.7rem + 0.2vw, 1rem);
}

.button.drawer-option {
  --ui-button-background: var(--ui-control-surface, var(--control-surface-bg, #181827));
  --ui-button-background-hover: var(--ui-control-surface-hover, var(--control-surface-hover, #232236));
  justify-content: flex-start;
  width: 100%;
}

.button.drawer-option[aria-current="page"] {
  --ui-button-background: var(--ui-selected, var(--control-selected-bg, #6d4de5));
  --ui-button-background-hover: var(--ui-primary-hover, var(--control-primary-bg-hover, #7c5cff));
  --ui-button-color: var(--ui-on-primary, #fff);
}

.drawer-close {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  inline-size: var(--ui-drawer-control-size, var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem))));
  block-size: var(--ui-drawer-control-size, var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem))));
  min-inline-size: var(--ui-drawer-control-size, var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem))));
  min-block-size: var(--ui-drawer-control-size, var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem))));
  padding: 0;
  border: 0;
  border-radius: var(--ui-control-radius, var(--control-radius, var(--auth-control-radius, 0.375rem)));
  background: transparent;
  color: var(--ui-muted, var(--portal-muted, var(--auth-muted, var(--muted, #b6b0c8))));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.drawer-close > span {
  position: relative;
  display: block;
  inline-size: 1.125rem;
  block-size: 1.125rem;
  flex: 0 0 auto;
}

.drawer-close > span::before,
.drawer-close > span::after {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: 0;
  inline-size: 1.125rem;
  block-size: 0.125rem;
  border-radius: 999rem;
  background: currentColor;
  content: "";
}

.drawer-close > span::before {
  transform: translateY(-50%) rotate(45deg);
}

.drawer-close > span::after {
  transform: translateY(-50%) rotate(-45deg);
}

.drawer-close:hover,
.drawer-close:focus-visible {
  background: transparent;
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
}

.drawer-close:focus-visible {
  outline: none;
}

.drawer-close:focus-visible > span {
  border-radius: 0.1875rem;
  outline: 0.125rem solid color-mix(in srgb, var(--ui-focus, var(--violet, var(--auth-violet, #8b5cf6))) 62%, transparent);
  outline-offset: 0.1875rem;
}

.button.danger {
  --ui-button-background: color-mix(in srgb, var(--ui-danger, var(--danger, #ef6b6b)) 14%, var(--ui-control-layer));
  --ui-button-background-hover: color-mix(in srgb, var(--ui-danger, var(--danger, #ef6b6b)) 22%, var(--ui-control-layer-hover));
  --ui-button-color: var(--ui-danger-text, #ffe8e8);
  --ui-button-shadow: inset 0 0 0 0.0625rem color-mix(in srgb, var(--ui-danger, var(--danger, #ef6b6b)) 44%, transparent);
  --ui-button-shadow-hover: inset 0 0 0 0.0625rem color-mix(in srgb, var(--ui-danger, var(--danger, #ef6b6b)) 62%, transparent);
}

html[data-theme="light"] .button.danger {
  --ui-button-color: color-mix(in srgb, var(--ui-danger, var(--danger, #b83b48)) 82%, #16060a);
}

.button:disabled,
.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.62;
}

.button:disabled:hover,
.button[aria-disabled="true"]:hover {
  background: var(--ui-button-background);
  box-shadow: var(--ui-button-shadow);
}

.button:focus-visible {
  outline: 0.125rem solid color-mix(in srgb, var(--ui-focus, var(--violet, var(--auth-violet, #8b5cf6))) 62%, transparent);
  outline-offset: 0.1875rem;
}

.custom-select {
  position: relative;
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
}

.custom-select-native {
  position: absolute;
  width: 0.0625rem;
  height: 0.0625rem;
  min-width: 0;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.custom-select-button {
  position: relative;
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  min-height: var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem)));
  align-items: center;
  justify-content: space-between;
  gap: 0.85em;
  padding-inline: clamp(1rem, 0.9rem + 0.25vw, 1.25rem) clamp(2.5rem, 2.35rem + 0.35vw, 2.75rem);
  border: 0;
  border-radius: var(--ui-control-radius, var(--control-radius, var(--auth-control-radius, 0.375rem)));
  background: var(--ui-control-layer);
  box-shadow: var(--ui-control-shadow, var(--control-shadow, none));
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
  cursor: pointer;
  font: inherit;
  font-size: clamp(0.8125rem, 0.785rem + 0.08vw, 0.875rem);
  font-weight: 650;
  line-height: 1.15;
  text-align: left;
  transition: background-color 0.14s ease, box-shadow 0.14s ease, color 0.14s ease;
}

:is(.language-custom-select, .mobile-language-custom-select, .theme-custom-select, .mobile-theme-custom-select) > .custom-select-button {
  min-height: max(var(--preference-control-block, 0rem), var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem))));
  padding-inline: var(--preference-control-pad-start, 0.75em) var(--preference-control-pad-end, 2.25em);
  border-radius: var(--preference-control-radius, 0.45em);
  background: transparent;
  box-shadow: none;
  color: var(--ui-muted, var(--portal-muted, var(--auth-muted, var(--muted, #b6b0c8))));
}

.contact-custom-select > .custom-select-button {
  height: auto;
  min-height: var(--field-min-height, var(--ui-control-min, 2.875rem));
  padding-block: 0.5rem;
  padding-left: var(--field-pad-x, clamp(1rem, 0.9rem + 0.25vw, 1.25rem));
  background: var(--ui-field-surface, var(--field-bg, var(--ui-control-surface, #181827)));
}

.custom-select-button::after {
  position: absolute;
  top: 50%;
  right: var(--preference-arrow-end, 0.875rem);
  width: var(--preference-arrow-width, 0.7em);
  height: var(--preference-arrow-height, 0.55em);
  background: currentColor;
  clip-path: polygon(50% 78%, 10% 28%, 90% 28%);
  content: "";
  opacity: 0.68;
  transform: translateY(-50%);
  transform-origin: 50% 50%;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.custom-select.open .custom-select-button::after {
  opacity: 0.95;
  transform: translateY(-50%) rotate(180deg);
}

.custom-select-button:hover,
.custom-select.open .custom-select-button {
  background: var(--ui-control-layer-hover);
  box-shadow: var(--ui-control-shadow-hover, var(--control-shadow-hover, none));
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
}

:is(.language-custom-select, .mobile-language-custom-select, .theme-custom-select, .mobile-theme-custom-select) > .custom-select-button:hover,
:is(.language-custom-select, .mobile-language-custom-select, .theme-custom-select, .mobile-theme-custom-select).open > .custom-select-button {
  background: transparent;
  box-shadow: none;
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
}

.custom-select-button:focus-visible {
  outline: 0.125rem solid color-mix(in srgb, var(--ui-focus, var(--violet, var(--auth-violet, #8b5cf6))) 62%, transparent);
  outline-offset: 0.1875rem;
}

.custom-select-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-custom-select .custom-select-label {
  overflow: visible;
  line-height: 1.22;
  text-overflow: clip;
  white-space: normal;
}

.custom-select-list {
  position: absolute;
  top: calc(100% + var(--preference-menu-offset, 0.625rem));
  right: 0;
  z-index: 220;
  display: none;
  width: max-content;
  min-width: 100%;
  max-width: min(20rem, calc(100vw - 1.5rem));
  max-height: min(17.5rem, calc(100vh - 8rem));
  overflow-y: auto;
  padding: var(--preference-menu-padding, 0.5rem);
  border: 0;
  border-radius: var(--preference-menu-radius, 0.6em);
  background: var(--ui-menu-surface, var(--control-menu-bg, #09090f));
  box-shadow: var(--ui-menu-shadow, none);
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
  font: inherit;
  font-size: clamp(0.8125rem, 0.785rem + 0.08vw, 0.875rem);
  scrollbar-color: color-mix(in srgb, currentColor 32%, transparent) color-mix(in srgb, currentColor 6%, transparent);
}

.contact-custom-select > .custom-select-list {
  right: 0;
  left: 0;
  width: auto;
  max-width: none;
}

.custom-select.open .custom-select-list {
  display: grid;
  gap: var(--preference-menu-gap, 0.3em);
}

.custom-select-option {
  display: flex;
  width: 100%;
  min-height: var(--preference-option-block, var(--ui-control-min, 2.875rem));
  align-items: center;
  padding-inline: var(--preference-option-pad, 1em);
  border: 0;
  border-radius: var(--preference-option-radius, 0.45em);
  background: transparent;
  box-shadow: none;
  color: var(--ui-muted, var(--portal-muted, var(--auth-muted, var(--muted, #b6b0c8))));
  cursor: pointer;
  font: inherit;
  font-size: clamp(0.8125rem, 0.785rem + 0.08vw, 0.875rem);
  font-weight: 650;
  line-height: 1.15;
  text-align: left;
  white-space: nowrap;
}

.custom-select-option:hover,
.custom-select-option:focus-visible {
  background: var(--ui-control-layer-hover);
  color: var(--ui-text, var(--portal-text, var(--auth-text, var(--text, #f5f3ff))));
  outline: none;
}

.custom-select-option[aria-selected="true"],
.custom-select-option[aria-selected="true"]:hover,
.custom-select-option[aria-selected="true"]:focus-visible {
  background: color-mix(in srgb, var(--ui-selected, var(--control-selected-bg, var(--auth-violet, #6d4de5))) 82%, #160b33);
  box-shadow: var(--ui-control-shadow-active, var(--control-shadow-active, none));
  color: var(--ui-on-primary, #fff);
}

.custom-select-option:disabled {
  cursor: default;
  opacity: 0.46;
}

.status-indicator {
  --status-color: var(--ui-status-neutral, var(--portal-status-neutral, var(--auth-muted, var(--muted, #b6b0c8))));
  --status-surface: var(--ui-status-surface, var(--portal-surface-strong, var(--auth-surface-control, var(--surface-2, #171724))));
  --status-font-size: clamp(0.6875rem, 0.655rem + 0.13vw, 0.8125rem);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  min-height: clamp(1.75rem, 1.68rem + 0.2vw, 2rem);
  gap: 0.6em;
  padding: 0.45em 0.75em;
  border: 0;
  border-radius: 999rem;
  background: color-mix(in srgb, var(--status-color) 11%, var(--status-surface));
  box-shadow: inset 0 0 0 0.0625rem color-mix(in srgb, var(--status-color) 30%, transparent);
  color: var(--status-color);
  font: inherit;
  font-size: var(--status-font-size);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  overflow-wrap: anywhere;
  white-space: normal;
}

.status-indicator::before {
  flex: 0 0 auto;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0.1em color-mix(in srgb, currentColor 20%, transparent);
  content: "";
}

.status-indicator[data-tone="loading"] {
  --status-color: var(--ui-status-loading, var(--portal-status-loading, var(--violet, var(--auth-violet, #a78bfa))));
}

.status-indicator[data-tone="loading"]::before {
  animation: status-indicator-pulse 1.4s ease-in-out infinite;
}

.status-indicator[data-tone="ready"] {
  --status-color: var(--ui-status-ready, var(--portal-status-ready, var(--auth-green, var(--green, #5ed69b))));
}

.status-indicator[data-tone="watch"] {
  --status-color: var(--ui-status-watch, var(--portal-status-watch, var(--auth-amber, var(--amber, #f3ba61))));
}

.status-indicator[data-tone="error"] {
  --status-color: var(--ui-status-error, var(--portal-status-error, var(--danger, #ef6b6b)));
}

.status-indicator[data-tone="neutral"] {
  --status-color: var(--ui-status-neutral, var(--portal-status-neutral, var(--auth-muted, var(--muted, #b6b0c8))));
}

.status-indicator.status-indicator-action {
  cursor: pointer;
  min-height: var(--ui-control-min, var(--control-min, var(--auth-control-min, 2.875rem)));
  transition: background-color 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}

.status-indicator.status-indicator-action:hover {
  background: color-mix(in srgb, var(--status-color) 17%, var(--status-surface));
  box-shadow: inset 0 0 0 0.0625rem color-mix(in srgb, var(--status-color) 48%, transparent);
}

.status-indicator.status-indicator-action[aria-pressed="true"] {
  background: color-mix(in srgb, var(--status-color) 20%, var(--status-surface));
  box-shadow: inset 0 0 0 0.125rem color-mix(in srgb, var(--status-color) 68%, transparent);
}

.status-indicator.status-indicator-action:disabled {
  cursor: default;
  opacity: 0.48;
}

.status-indicator.status-indicator-action:focus-visible {
  outline: 0.125rem solid color-mix(in srgb, var(--status-color) 62%, transparent);
  outline-offset: 0.1875rem;
}

@keyframes status-indicator-pulse {
  50% { opacity: 0.35; }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme]) .button.danger {
    --ui-button-color: color-mix(in srgb, var(--ui-danger, var(--danger, #b83b48)) 82%, #16060a);
  }
}

.drawer-settings :is(.theme-custom-select, .language-custom-select) > .custom-select-button {
  min-height: var(--ui-control-min, 2.875rem);
  justify-content: flex-start;
  padding-inline: 0.75em 2.25em;
  background: var(--ui-control-surface, var(--control-surface-bg, #181827));
}

.drawer-settings :is(.theme-custom-select, .language-custom-select) > .custom-select-button:hover,
.drawer-settings :is(.theme-custom-select, .language-custom-select).open > .custom-select-button {
  background: var(--ui-control-surface-hover, var(--control-surface-hover, var(--ui-field-surface, #232236)));
}

@media (prefers-reduced-motion: reduce) {
  .status-indicator[data-tone="loading"]::before {
    animation: none;
  }
}
