/* NISearch base: font, reset, typography, shared controls.
   Colors, radii, spacing, type sizes and motion come from tokens.css only. */

@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable-Italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--nis-surface);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--nis-surface);
  color: var(--nis-text);
  font-family: var(--nis-font-family);
  font-size: var(--nis-font-lg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  position: relative;
  flex: 1 0 auto;
  width: 100%;
  min-width: 0;
}

a {
  color: var(--nis-link);
  text-decoration: none;
}

@media (hover: hover) {
  a:hover {
    text-decoration: underline;
  }
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.25;
  color: var(--nis-text);
}

p {
  margin: 0 0 var(--nis-space-3);
}

ul, ol {
  margin: 0;
  padding-left: 1.25em;
}

kbd {
  font-family: var(--nis-font-mono);
  font-size: var(--nis-font-xs);
  padding: 1px var(--nis-space-1);
  border: 1px solid var(--nis-border-strong);
  border-bottom-width: 2px;
  border-radius: var(--nis-radius-xs);
  background: var(--nis-surface-raised);
  color: var(--nis-text);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

:focus-visible {
  outline: 2px solid var(--nis-focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* The core script swaps html.no-js for html.js on load. */
.no-js .hide_if_nojs {
  display: none !important;
}

.js .show_if_nojs {
  display: none !important;
}

/* Upstream toggles .invisible on collapsed blocks, dialogs and the close links. */
.invisible {
  display: none !important;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Icon catalog (icons.html). Icons take the current text color. */
.ionicon {
  display: inline-block;
  flex: none;
  fill: currentColor;
  vertical-align: middle;
}

.sxng-icon-set-big {
  width: 20px;
  height: 20px;
}

.sxng-icon-set {
  width: 16px;
  height: 16px;
}

.sxng-icon-set-small {
  width: 14px;
  height: 14px;
}

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--nis-space-2);
  color: var(--nis-text);
  text-decoration: none;
  white-space: nowrap;
}

@media (hover: hover) {
  .brand:hover {
    text-decoration: none;
  }
}

.logo_mark {
  display: block;
  width: 24px;
  height: 24px;
  flex: none;
  color: var(--nis-text);
}

.logo_word {
  font-size: var(--nis-font-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--nis-space-2);
  min-height: 36px;
  padding: 0 var(--nis-space-4);
  border: 1px solid var(--nis-border-strong);
  border-radius: var(--nis-radius-md);
  background: var(--nis-surface-raised);
  color: var(--nis-text);
  font-size: var(--nis-font-md);
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  user-select: none;
  transition: background-color var(--nis-motion-fast) var(--nis-motion-easing),
              border-color var(--nis-motion-fast) var(--nis-motion-easing);
}

.btn:active {
  background: var(--nis-surface-active);
}

@media (hover: hover) {
  .btn:hover {
    background: var(--nis-surface-hover);
    text-decoration: none;
  }
}

.btn-primary {
  border-color: var(--nis-accent);
  background: var(--nis-accent);
  color: var(--nis-accent-fg);
}

.btn-primary:active {
  background: var(--nis-accent-hover);
}

@media (hover: hover) {
  .btn-primary:hover {
    border-color: var(--nis-accent-hover);
    background: var(--nis-accent-hover);
  }
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.icon_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--nis-radius-md);
  color: var(--nis-text-muted);
  text-decoration: none;
  transition: background-color var(--nis-motion-fast) var(--nis-motion-easing),
              color var(--nis-motion-fast) var(--nis-motion-easing);
}

.icon_button:active {
  background: var(--nis-surface-active);
}

@media (hover: hover) {
  .icon_button:hover {
    background: var(--nis-surface-hover);
    color: var(--nis-text);
    text-decoration: none;
  }
}

/* Theme toggle: only the icon of the current mode is shown. */
.theme_icon {
  display: none;
  width: 20px;
  height: 20px;
}

.theme_toggle[data-theme-value="auto"] .theme_icon_auto,
.theme_toggle[data-theme-value="light"] .theme_icon_light,
.theme_toggle[data-theme-value="dark"] .theme_icon_dark {
  display: block;
}

/* Form controls */
input[type="checkbox"] {
  accent-color: var(--nis-accent);
  width: 16px;
  height: 16px;
  margin: 0;
}

/* On/off switch. Markup comes from macros.html checkbox_onoff(). */
input[type="checkbox"].checkbox-onoff {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  margin: 0;
  border-radius: var(--nis-radius-full);
  background: var(--nis-text-subtle);
  cursor: pointer;
  transition: background-color var(--nis-motion-normal) var(--nis-motion-easing);
}

input[type="checkbox"].checkbox-onoff::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--nis-surface-raised);
  box-shadow: var(--nis-shadow-card);
  transition: transform var(--nis-motion-normal) var(--nis-motion-easing);
}

input[type="checkbox"].checkbox-onoff:checked {
  background: var(--nis-accent);
}

input[type="checkbox"].checkbox-onoff:checked::before {
  transform: translateX(16px);
}

input[type="checkbox"].checkbox-onoff:focus-visible {
  outline: 2px solid var(--nis-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  input[type="checkbox"].checkbox-onoff,
  input[type="checkbox"].checkbox-onoff::before {
    transition: none;
  }
}

/* Select: native list, custom arrow drawn from select-light/dark.svg. */
select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  max-width: 100%;
  padding: 0 var(--nis-space-8) 0 var(--nis-space-3);
  border: 1px solid var(--nis-border-strong);
  border-radius: var(--nis-radius-md);
  background-color: var(--nis-surface-raised);
  background-image: url("../img/select-light.svg");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  color: var(--nis-text);
  font-size: var(--nis-font-md);
  cursor: pointer;
}

html.theme-dark select {
  background-image: url("../img/select-dark.svg");
}

@media (prefers-color-scheme: dark) {
  html.theme-auto select {
    background-image: url("../img/select-dark.svg");
  }
}

/* Messages and dialogs */
.dialog-error {
  position: relative;
  max-width: 720px;
  margin: var(--nis-space-4) auto;
  padding: var(--nis-space-3) var(--nis-space-10) var(--nis-space-3) var(--nis-space-4);
  border: 1px solid var(--nis-danger);
  border-radius: var(--nis-radius-lg);
  background: var(--nis-danger-subtle);
  color: var(--nis-text);
  font-size: var(--nis-font-md);
}

.dialog-error ul {
  margin: 0;
  padding-left: 1.2em;
}

.dialog-error .close {
  position: absolute;
  top: var(--nis-space-2);
  right: var(--nis-space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--nis-radius-sm);
  color: var(--nis-text-muted);
  font-size: var(--nis-font-xl);
  line-height: 1;
  text-decoration: none;
}

/* Keyboard help: upstream builds .dialog-modal with a.close, h3 and a table. */
.dialog-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1000;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 32px));
  max-height: 80vh;
  overflow: auto;
  padding: var(--nis-space-6);
  border-radius: var(--nis-radius-xl);
  background: var(--nis-surface-raised);
  box-shadow: var(--nis-shadow-popover);
  color: var(--nis-text);
  font-size: var(--nis-font-md);
}

.dialog-modal .close {
  position: absolute;
  top: var(--nis-space-3);
  right: var(--nis-space-3);
  color: var(--nis-text-muted);
  font-size: var(--nis-font-xl);
  line-height: 1;
  text-decoration: none;
}

.dialog-modal h3 {
  margin-bottom: var(--nis-space-4);
}

.dialog-modal table {
  width: 100%;
  border-collapse: collapse;
}

.dialog-modal td {
  vertical-align: top;
  padding: 0 var(--nis-space-4) var(--nis-space-4) 0;
}

.dialog-modal h4 {
  margin-bottom: var(--nis-space-2);
  font-size: var(--nis-font-md);
}

.dialog-modal ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dialog-modal li {
  margin-bottom: var(--nis-space-1);
  font-size: var(--nis-font-sm);
  color: var(--nis-text-muted);
}

/* Empty states: 404, no results. */
.empty_state {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--nis-space-10) var(--nis-space-4);
}

.empty_state h1,
.empty_state h2 {
  margin-bottom: var(--nis-space-3);
  font-size: var(--nis-font-xl);
}

.empty_state ul {
  margin-top: var(--nis-space-2);
  color: var(--nis-text-muted);
}

.empty_state li {
  margin-bottom: var(--nis-space-1);
}

.message {
  color: var(--nis-text-muted);
  font-size: var(--nis-font-md);
}

/* Top-right utility links (about, donate, settings, theme) on pages without the results header. */
#links_on_top {
  position: absolute;
  top: var(--nis-space-3);
  right: var(--nis-space-4);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--nis-space-1);
}

#links_on_top .icon_link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--nis-space-2);
  border-radius: var(--nis-radius-md);
  color: var(--nis-text-muted);
  font-size: var(--nis-font-md);
  text-decoration: none;
  transition: background-color var(--nis-motion-fast) var(--nis-motion-easing),
              color var(--nis-motion-fast) var(--nis-motion-easing);
}

#links_on_top .icon_link:active {
  background: var(--nis-surface-active);
}

@media (hover: hover) {
  #links_on_top .icon_link:hover {
    background: var(--nis-surface-hover);
    color: var(--nis-text);
    text-decoration: none;
  }
}

.page_header {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: var(--nis-space-3) var(--nis-space-4);
}

/* Back to top: shown by the upstream scroll handler (#results.scrolling). */
#backToTop {
  position: fixed;
  right: var(--nis-space-4);
  bottom: var(--nis-space-4);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity var(--nis-motion-normal) var(--nis-motion-easing),
              transform var(--nis-motion-normal) var(--nis-motion-easing),
              visibility 0s linear var(--nis-motion-normal);
}

#results.scrolling > #backToTop {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

#backToTop a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--nis-radius-full);
  background: var(--nis-surface-raised);
  box-shadow: var(--nis-shadow-popover);
  color: var(--nis-text);
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  #backToTop {
    transition: none;
  }
}

/* Footer */
footer {
  padding: var(--nis-space-6) var(--nis-space-4) var(--nis-space-8);
  text-align: center;
}

.footer_links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--nis-space-2) var(--nis-space-5);
  font-size: var(--nis-font-sm);
}

.footer_links a {
  color: var(--nis-text-muted);
}

.footer_meta {
  margin: var(--nis-space-4) 0 0;
  font-size: var(--nis-font-xs);
  color: var(--nis-text-subtle);
}

.footer_meta a {
  color: var(--nis-text-muted);
}
