/*! Tailwind CSS v4 preflight baseline scoped to SD Design layer */
@use '@style/theme/index.scss' as *;
@use '@components/scrollbar/style/token.scss' as sb;

/* stylelint-disable-next-line layer-name-pattern */
@layer #{$prefix}-design {
  *,
  ::after,
  ::before,
  ::backdrop,
  ::file-selector-button {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0 solid;
  }

  html,
  :host {
    font-family:
      ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
      'Segoe UI Symbol', 'Noto Color Emoji';
    line-height: 1.5;
    tab-size: 4;
    text-size-adjust: 100%;
    font-feature-settings: normal;
    font-variation-settings: normal;
    -webkit-tap-highlight-color: transparent;
  }

  hr {
    height: 0;
    color: inherit;
    border-top-width: 1px;
  }

  abbr:where([title]) {
    text-decoration: underline dotted;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-weight: inherit;
    font-size: inherit;
  }

  a {
    color: inherit;
    text-decoration: inherit;
  }

  b,
  strong {
    font-weight: bolder;
  }

  code,
  kbd,
  samp,
  pre {
    font-size: 1em;
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
      monospace;
    font-feature-settings: normal;
    font-variation-settings: normal;
  }

  small {
    font-size: 80%;
  }

  sub,
  sup {
    position: relative;
    font-size: 75%;
    line-height: 0;
    vertical-align: baseline;
  }

  sub {
    bottom: -0.25em;
  }

  sup {
    top: -0.5em;
  }

  table {
    text-indent: 0;
    border-color: inherit;
    border-collapse: collapse;
  }

  :-moz-focusring {
    outline: auto;
  }

  progress {
    vertical-align: baseline;
  }

  summary {
    display: list-item;
  }

  ol,
  ul,
  menu {
    list-style: none;
  }

  img,
  svg,
  video,
  canvas,
  audio,
  iframe,
  embed,
  object {
    display: block;
    vertical-align: middle;
  }

  img,
  video {
    max-width: 100%;
    height: auto;
  }

  button,
  input,
  select,
  optgroup,
  textarea,
  ::file-selector-button {
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    background-color: transparent;
    border-radius: 0;
    opacity: 1;
    font-feature-settings: inherit;
    font-variation-settings: inherit;
  }

  :where(select:is([multiple], [size])) optgroup {
    font-weight: bolder;
  }

  :where(select:is([multiple], [size])) optgroup option {
    padding-inline-start: 20px;
  }

  ::file-selector-button {
    margin-inline-end: 4px;
  }

  ::placeholder {
    opacity: 1;
  }

  @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
    ::placeholder {
      color: color-mix(in oklab, currentcolor 50%, transparent);
    }
  }

  textarea {
    resize: vertical;
  }

  ::-webkit-search-decoration {
    appearance: none;
  }

  ::-webkit-date-and-time-value {
    min-height: 1lh;
    text-align: inherit;
  }

  ::-webkit-datetime-edit {
    display: inline-flex;
  }

  ::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
  }

  ::-webkit-datetime-edit,
  ::-webkit-datetime-edit-year-field,
  ::-webkit-datetime-edit-month-field,
  ::-webkit-datetime-edit-day-field,
  ::-webkit-datetime-edit-hour-field,
  ::-webkit-datetime-edit-minute-field,
  ::-webkit-datetime-edit-second-field,
  ::-webkit-datetime-edit-millisecond-field,
  ::-webkit-datetime-edit-meridiem-field {
    padding-block: 0;
  }

  ::-webkit-calendar-picker-indicator {
    line-height: 1;
  }

  :-moz-ui-invalid {
    box-shadow: none;
  }

  button,
  input:where([type='button'], [type='reset'], [type='submit']),
  ::file-selector-button {
    appearance: button;
  }

  ::-webkit-inner-spin-button,
  ::-webkit-outer-spin-button {
    height: auto;
  }

  [hidden]:where(:not([hidden='until-found'])) {
    display: none !important;
  }

  /* Native scrollbar baseline — mirrors the <Scrollbar> embed theme
     (transparent track, neutral thumb; shares --sd-scrollbar-* with the <Scrollbar> component).
     Opt-in: only applies within an element carrying the design-system
     class (`.sd-design` by default; follows $prefix), e.g.
     <html class="sd-design-system-scrollbar">. Standard scrollbar-* properties are
     primary; ::-webkit-scrollbar*
     is the fallback for browsers without standard support. Where the
     standard properties apply they override the webkit rules, so the
     rounded corners and hover/active states only render in webkit-only
     browsers. */
  @supports (scrollbar-color: auto) {
    .#{$prefix}-design-system-scrollbar {
      &,
      & * {
        scrollbar-width: thin;
        scrollbar-color: var(
            #{$sd-cssvars-prefix}-scrollbar-thumb-color,
            #{sb.$scrollbar-thumb-bar-bg_color}
          )
          transparent;
      }
    }
  }

  @supports selector(::-webkit-scrollbar) {
    .#{$prefix}-design-system-scrollbar {
      &::-webkit-scrollbar,
      & *::-webkit-scrollbar {
        width: var(#{$sd-cssvars-prefix}-scrollbar-size, #{sb.$scrollbar-thumb-bar-size});
        height: var(#{$sd-cssvars-prefix}-scrollbar-size, #{sb.$scrollbar-thumb-bar-size});
      }

      &::-webkit-scrollbar-track,
      & *::-webkit-scrollbar-track {
        background: transparent;
      }

      &::-webkit-scrollbar-thumb,
      & *::-webkit-scrollbar-thumb {
        background: var(
          #{$sd-cssvars-prefix}-scrollbar-thumb-color,
          #{sb.$scrollbar-thumb-bar-bg_color}
        );
        border-radius: var(
          #{$sd-cssvars-prefix}-scrollbar-thumb-radius,
          #{sb.$scrollbar-thumb-bar-border_radius}
        );
      }

      &::-webkit-scrollbar-thumb:hover,
      & *::-webkit-scrollbar-thumb:hover {
        background: var(
          #{$sd-cssvars-prefix}-scrollbar-thumb-color-hover,
          #{sb.$scrollbar-thumb-bar-bg_color_hover}
        );
      }

      &::-webkit-scrollbar-thumb:active,
      & *::-webkit-scrollbar-thumb:active {
        background: var(
          #{$sd-cssvars-prefix}-scrollbar-thumb-color-active,
          #{sb.$scrollbar-thumb-bar-bg_color_active}
        );
      }
    }
  }
}
