/* ==========================================================================
   Components: header, buttons, chips, code blocks, dialogs, palette, toasts
   ========================================================================== */

/* ------------------------------------------------------------------ header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  min-height: 60px;
  padding-block: var(--sp-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: var(--fs-md);
  flex: none;
}
.brand__mark { width: 26px; height: 26px; }
.brand__mark .bm-a { fill: var(--accent); }
.brand__mark .bm-b { fill: var(--teal); }
.brand__mark .bm-w { stroke: var(--border-strong); stroke-width: 1.6; fill: none; }
.brand__accent { color: var(--accent); }
.brand:hover .bm-w { stroke: var(--accent); }

.site-nav { flex: 1 1 auto; min-width: 0; }
.site-nav ul {
  display: flex;
  gap: var(--sp-1);
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav ul::-webkit-scrollbar { display: none; }
.site-nav li + li { margin-top: 0; }
.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.site-nav a:hover { background: var(--surface-2); color: var(--text); }
.site-nav a[aria-current='true'] {
  background: var(--accent-quiet);
  color: var(--accent);
}
.nav-count {
  display: inline-grid;
  place-items: center;
  min-width: 1.35em;
  height: 1.35em;
  padding-inline: 0.3em;
  border-radius: var(--radius-pill);
  background: var(--accent-solid);
  color: var(--on-accent);
  font-size: var(--fs-3xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.site-header__tools { display: flex; align-items: center; gap: var(--sp-2); flex: none; }

.btn--palette {
  gap: 0.5rem;
  color: var(--text-2);
  border-color: var(--border);
}
.btn--palette .kbd-hint {
  display: inline-flex;
  gap: 0.25em;
  font-family: var(--font-mono);
  font-size: var(--fs-3xs);
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}

.theme-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
}
.theme-switch button {
  display: grid;
  place-items: center;
  width: 30px; height: 26px;
  min-height: 24px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 60rem) {
  .btn--palette span:not(.visually-hidden) { display: none; }
  .btn--palette .kbd-hint { display: none; }
}
@media (max-width: 44rem) {
  .site-header__inner { flex-wrap: wrap; min-height: 0; row-gap: var(--sp-2); }
  .site-nav { order: 3; flex-basis: 100%; }
  .site-nav ul { padding-bottom: 2px; }
  .skip-link:nth-of-type(2) { left: var(--sp-2); top: 3.4rem; }
}

/* ----------------------------------------------------------------- buttons */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--btn-border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-instant) var(--ease-out);
}
.btn:hover { --btn-bg: var(--surface-3); --btn-border: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  --btn-bg: var(--accent-solid);
  --btn-fg: var(--on-accent);
  --btn-border: transparent;
}
.btn--primary:hover { --btn-bg: var(--accent-solid-hover); --btn-border: transparent; }

.btn--ghost { --btn-bg: transparent; --btn-fg: var(--text-2); --btn-border: var(--border); }
.btn--ghost:hover { --btn-bg: var(--surface-2); --btn-fg: var(--text); }

.btn--sm { padding: 0.32rem 0.6rem; font-size: var(--fs-xs); min-height: 24px; }
.btn--icon { padding: 0.45rem; width: 2.15rem; height: 2.15rem; }
.btn--wide { width: 100%; }

/* ------------------------------------------------------------------- chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.16rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.005em;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip--mono { font-family: var(--font-mono); font-weight: 500; font-size: var(--fs-3xs); }
.chip--tier-reference { background: var(--violet-quiet); color: var(--violet); border-color: color-mix(in srgb, var(--violet) 30%, transparent); }
.chip--tier-vendor { background: var(--teal-quiet); color: var(--teal); border-color: color-mix(in srgb, var(--teal) 30%, transparent); }
.chip--tier-community { background: var(--amber-quiet); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.chip--mat-stable { color: var(--green); background: var(--green-quiet); border-color: color-mix(in srgb, var(--green) 28%, transparent); }
.chip--mat-beta { color: var(--amber); background: var(--amber-quiet); border-color: color-mix(in srgb, var(--amber) 28%, transparent); }
.chip--mat-experimental { color: var(--rose); background: var(--rose-quiet); border-color: color-mix(in srgb, var(--rose) 28%, transparent); }
.chip--mat-deprecated { color: var(--danger); background: var(--danger-quiet); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.chip--remote { color: var(--accent); background: var(--accent-quiet); border-color: var(--accent-line); }

/* -------------------------------------------------------------- code blocks */
.code {
  margin: 0;
  padding: var(--sp-4);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: var(--fs-xs);
  line-height: 1.62;
  color: var(--text);
  tab-size: 2;
  scrollbar-width: thin;
}
.code code { display: block; white-space: pre; }
.code::-webkit-scrollbar { height: 9px; }
.code::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 9px; }

.codeblock { position: relative; }
.codeblock__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0.4rem 0.4rem 0.4rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.codeblock__name {
  font-family: var(--font-mono);
  font-size: var(--fs-3xs);
  color: var(--text-2);
  text-transform: none;
}
.codeblock .code { border-radius: 0 0 var(--radius) var(--radius); }

/* copy feedback */
.btn[data-copied='true'] {
  --btn-bg: var(--green-quiet);
  --btn-fg: var(--green);
  --btn-border: color-mix(in srgb, var(--green) 35%, transparent);
}

/* ---------------------------------------------------------------- switches */
.switch { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  width: 34px; height: 20px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  padding: 2px;
  display: block;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.switch__thumb {
  display: block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--dur-base) var(--ease-spring), background var(--dur-fast) var(--ease-out);
}
.switch input:checked + .switch__track { background: var(--accent-quiet); border-color: var(--accent-line); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(14px); background: var(--accent); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch:hover .switch__thumb { background: var(--text-2); }

/* ------------------------------------------------------------------ selects */
select {
  appearance: none;
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 49%, currentColor 50%),
                    linear-gradient(-45deg, transparent 49%, currentColor 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.3rem 1.75rem 0.3rem 0.55rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

/* ------------------------------------------------------------------ dialogs */
dialog {
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  max-width: none;
  max-height: none;
}
dialog::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
/* The component classes below set `display`, which would otherwise beat the
   user-agent `dialog:not([open]) { display: none }` rule and leave a closed
   dialog sitting invisibly on top of the page swallowing clicks. */
dialog:not([open]) { display: none !important; }

.sheet {
  position: fixed;
  inset: auto 0 0 auto;
  width: min(56rem, 100%);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet[open] { animation: sheet-in var(--dur-base) var(--ease-out); }
@keyframes sheet-in {
  from { transform: translateX(3%); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}
.sheet--compare { width: min(80rem, 100%); }

.sheet__chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}
.sheet__chrome h2 { font-size: var(--fs-lg); font-family: var(--font-sans); font-weight: 650; }
.sheet__chrome-actions { display: flex; align-items: center; gap: var(--sp-2); }
.sheet__crumbs {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: var(--fs-2xs);
  color: var(--text-2);
  min-width: 0;
  flex-wrap: wrap;
}
.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-5) var(--sp-5) var(--sp-8);
  flex: 1 1 auto;
}
.sheet__body:focus-visible { outline-offset: -3px; }

@media (max-width: 40rem) {
  .sheet { width: 100%; border-left: 0; }
  .sheet__body { padding-inline: var(--sp-4); }
}

/* ------------------------------------------------------------ command palette */
.palette {
  position: fixed;
  inset: 0;
  margin: min(12vh, 6rem) auto auto;
  width: min(40rem, calc(100% - 2rem));
  height: fit-content;
  max-height: min(70vh, 34rem);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.palette[open] { animation: palette-in var(--dur-base) var(--ease-out); }
@keyframes palette-in {
  from { transform: translateY(-8px) scale(0.985); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.palette__field {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.palette__field-label {
  font-size: var(--fs-3xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-2);
  flex: none;
}
.palette__field .icon { color: var(--text-2); font-size: 1rem; }
.palette__field input {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: var(--fs-md);
  min-width: 0;
}
.palette__field:has(input:focus) { outline: 3px solid var(--focus); outline-offset: -2px; }
.palette__field input:focus { outline: none; }
.palette__field input::placeholder { color: var(--text-3); }
.palette__field kbd {
  font-size: var(--fs-3xs);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  background: var(--surface-2);
}
.palette__help {
  font-size: var(--fs-3xs);
  color: var(--text-2);
  padding: 0.4rem 1rem 0;
}
.palette__list {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}
.palette__list li + li { margin-top: 1px; }
.palette__opt {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  scroll-margin: 0.5rem;
}
.palette__opt[aria-selected='true'] { background: var(--accent-quiet); }
.palette__opt-kind {
  font-size: var(--fs-3xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
  min-width: 5.5rem;
}
.palette__opt[aria-selected='true'] .palette__opt-kind { color: var(--accent); }
.palette__opt-label { font-size: var(--fs-sm); font-weight: 600; }
.palette__opt-meta {
  margin-left: auto;
  font-size: var(--fs-2xs);
  color: var(--text-2);
  white-space: nowrap;
}
.palette__empty { padding: var(--sp-5); text-align: center; color: var(--text-2); font-size: var(--fs-sm); }
.palette__group {
  padding: 0.5rem 0.65rem 0.2rem;
  font-size: var(--fs-3xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}
.palette__status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ------------------------------------------------------------------- toasts */
.toaster {
  position: fixed;
  bottom: var(--sp-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in var(--dur-base) var(--ease-spring);
  display: flex;
  align-items: center;
  gap: 0.5em;
}
.toast--ok { border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.toast--warn { border-color: color-mix(in srgb, var(--amber) 45%, transparent); }
.toast[data-leaving='true'] { animation: toast-out var(--dur-fast) var(--ease-in) forwards; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(6px); opacity: 0; } }

/* ------------------------------------------------------------------- footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-block: var(--sp-8) var(--sp-6);
}
.footer__grid {
  display: grid;
  grid-template-columns: 1.15fr 1.15fr 0.7fr;
  gap: var(--sp-7);
  align-items: start;
}
@media (max-width: 62rem) { .footer__grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 44rem) { .footer__grid { grid-template-columns: 1fr; gap: var(--sp-6); } }

.site-footer h2 {
  font-family: var(--font-sans);
  font-size: var(--fs-lg);
  font-weight: 650;
  margin-bottom: var(--sp-3);
}
.site-footer h3 {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  margin: var(--sp-5) 0 var(--sp-2);
}
.site-footer p { color: var(--text-2); font-size: var(--fs-sm); margin-bottom: var(--sp-3); max-width: 34rem; }

.footer__contact {
  padding: var(--sp-5);
  margin-block: calc(var(--sp-5) * -1);
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--accent-solid) calc(var(--glow) * 14%), transparent),
    transparent 65%);
  border: 1px solid var(--accent-line);
}
@media (min-width: 62rem) {
  .footer__contact { margin-inline: calc(var(--sp-5) * -1); }
}
.footer__mail { margin-block: var(--sp-4); }
.maillink {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: clamp(1.05rem, 0.9rem + 1vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.maillink:hover { color: var(--accent); border-color: var(--text); }
.footer__reasons {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.footer__reasons li { margin: 0; }
.footer__reasons a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  font-size: var(--fs-2xs);
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  text-decoration: none;
}
.footer__reasons a:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-quiet); }

.footer__sources, .footer__nav ul {
  list-style: none;
  padding: 0;
  font-size: var(--fs-xs);
}
.footer__sources li, .footer__nav li { margin-top: 0.35em; }
.footer__nav a { color: var(--text-2); text-decoration: none; }
.footer__nav a:hover { color: var(--accent); text-decoration: underline; }
.footer__sources a { color: var(--text-2); }

.footer__legal {
  margin-top: var(--sp-7);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-2xs);
  color: var(--text-2);
  max-width: 62rem;
}
