/* WebPilot - shared styles for all pages.
   Mobile-first; breakpoints at 600px and 900px. Colors come from tokens so the
   light and dark themes stay in sync. */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-display: clamp(2.5rem, 8vw, 3.75rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-pill: 999px;

  --content-width: 680px;
  --page-gutter: var(--space-4);

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f4f6fb;
  --border: #dfe3ec;
  --border-strong: #c3c9d6;
  --text: #1b1f29;
  --text-muted: #5b6375;
  --text-subtle: #7a8294;

  --brand: #2f5bea;
  --brand-strong: #1f44c4;
  --brand-soft: #e8eeff;
  --brand-gradient: linear-gradient(135deg, #2f5bea 0%, #7b4dff 55%, #e2489b 100%);

  --link: #1a3fbf;
  --link-visited: #6b3fb0;
  --url: #1e7a5a;
  --highlight-text: #1b1f29;

  --danger: #c2372f;
  --danger-soft: #fdecea;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 2px 6px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-focus: 0 0 0 3px rgba(47, 91, 234, 0.28);

  --skeleton-base: #eceff5;
  --skeleton-shine: #f7f8fb;

  --transition-fast: 120ms ease;
  --transition: 200ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-muted: #1d222c;
    --border: #2a303c;
    --border-strong: #3a4250;
    --text: #e7eaf0;
    --text-muted: #a3abba;
    --text-subtle: #8a92a2;

    --brand: #7c9bff;
    --brand-strong: #a3b8ff;
    --brand-soft: #1f2a4a;
    --brand-gradient: linear-gradient(135deg, #7c9bff 0%, #a98bff 55%, #ff7ab8 100%);

    --link: #9db4ff;
    --link-visited: #c4a5ff;
    --url: #6fd3a8;
    --highlight-text: #ffffff;

    --danger: #ff8a80;
    --danger-soft: #3a1f1f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.45);
    --shadow-focus: 0 0 0 3px rgba(124, 155, 255, 0.35);

    --skeleton-base: #1f242e;
    --skeleton-shine: #2a303c;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
  transition: transform var(--transition-fast);
}

.skip-link:focus {
  transform: translateY(0);
  text-decoration: none;
}

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  flex: none;
  width: 32px;
  height: 32px;
}

.brand-name {
  font-size: var(--fs-lg);
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand--hero {
  flex-direction: column;
  gap: var(--space-3);
}

.brand--hero .brand-mark {
  width: 72px;
  height: 72px;
}

.brand--hero .brand-name {
  font-size: var(--fs-display);
  line-height: 1.05;
}

/* ---------- Search box ---------- */
.search-form {
  width: 100%;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-2) 0 var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.search-box:hover {
  box-shadow: var(--shadow-md);
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-md), var(--shadow-focus);
}

.search-icon {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--text-subtle);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 var(--space-3);
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-md);
}

.search-input::placeholder {
  color: var(--text-subtle);
}

/* Hide the browser's own clear control; we render a consistent one */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.icon-button {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.icon-button:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.search-clear[hidden] {
  display: none;
}

.search-submit {
  color: var(--brand);
}

.kbd-hint {
  display: none;
  flex: none;
  margin-right: var(--space-2);
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

.search-box:focus-within .kbd-hint {
  display: none;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast),
    box-shadow var(--transition-fast), color var(--transition-fast);
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-strong);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
  .btn-primary {
    color: #0f1218;
  }
}

/* ---------- Home page ---------- */
.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-7) var(--page-gutter);
  text-align: center;
}

.home-main .search-form {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
}

.tagline {
  margin: calc(-1 * var(--space-3)) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-md);
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

/* ---------- Results header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-3) var(--page-gutter);
}

.site-header .brand {
  flex: none;
  white-space: nowrap;
}

.site-header .brand-mark {
  width: 28px;
  height: 28px;
}

.site-header .search-form {
  max-width: var(--content-width);
}

/* ---------- Results ---------- */
.results-main {
  flex: 1;
  width: 100%;
  padding: var(--space-4) var(--page-gutter) var(--space-7);
}

.results-column {
  max-width: var(--content-width);
}

.result-stats {
  margin: 0 0 var(--space-4);
  min-height: 1.5em;
  color: var(--text-subtle);
  font-size: var(--fs-sm);
}

.result-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.result {
  padding: var(--space-4) 0;
  animation: fade-in 240ms ease both;
}

.result + .result {
  border-top: 1px solid var(--border);
}

.result-source {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  margin-bottom: var(--space-1);
  color: var(--text);
  font-size: var(--fs-sm);
}

.result-source:hover {
  text-decoration: none;
}

.site-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
}

.result-source-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.result-host {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.result-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--url);
  font-size: var(--fs-xs);
}

.result-title {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-lg);
  font-weight: 500;
  line-height: 1.3;
}

.result-title a {
  overflow-wrap: anywhere;
}

.result-title a:visited {
  color: var(--link-visited);
}

.result-snippet {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.result-snippet mark {
  background: transparent;
  color: var(--highlight-text);
  font-weight: 700;
}

.results-footnote {
  margin: var(--space-5) 0 0;
  color: var(--text-subtle);
  font-size: var(--fs-sm);
}

/* ---------- Infinite scroll ---------- */
/* search.js compensates scroll position itself when pages above the viewport change size;
   browser scroll anchoring would apply the same correction a second time. */
html:has(body.page-results),
body.page-results {
  overflow-anchor: none;
}

/* Every page after the first, including placeholders, has the same top border, so a placeholder
   is exactly as tall as the page it replaced. */
.result-pages > * + * {
  border-top: 1px solid var(--border);
}

.result-page-placeholder {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-3);
  overflow: hidden;
}

.result-page-placeholder .results-footnote {
  margin: 0;
}

.result-page-placeholder.is-loading {
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 37%, var(--skeleton-base) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  opacity: 0.6;
  animation: shimmer 1.4s ease infinite;
}

.results-sentinel {
  height: 1px;
}

.results-status--top .results-inline-error {
  margin: 0 0 var(--space-4);
}

.results-inline-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.results-inline-error .results-footnote {
  margin: 0;
}

/* ---------- Skeleton loading ---------- */
.skeleton-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.skeleton {
  padding: var(--space-4) 0;
}

.skeleton + .skeleton {
  border-top: 1px solid var(--border);
}

.skeleton-line {
  height: 12px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 37%, var(--skeleton-base) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-line--url { width: 35%; height: 10px; }
.skeleton-line--title { width: 70%; height: 18px; margin-bottom: var(--space-3); }
.skeleton-line--text { width: 100%; }
.skeleton-line--short { width: 60%; }

/* ---------- Empty and error states ---------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-6) 0;
  animation: fade-in 240ms ease both;
}

.state-icon {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand);
}

.state-icon svg {
  width: 28px;
  height: 28px;
}

.state--error .state-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.state-title {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.state-body {
  margin: 0;
  color: var(--text-muted);
}

.state-tips {
  margin: 0;
  padding-left: var(--space-5);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.state-tips li + li {
  margin-top: var(--space-1);
}

/* ---------- 404 page ---------- */
.notfound-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-7) var(--page-gutter);
  text-align: center;
}

.notfound-main .notfound-code {
  margin: 0;
  font-size: var(--fs-display);
  font-weight: 800;
  line-height: 1;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.notfound-main p {
  margin: 0;
  color: var(--text-muted);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-subtle);
  font-size: var(--fs-sm);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  padding: var(--space-4) var(--page-gutter);
}

.site-footer p {
  margin: 0;
}

/* ---------- Animations ---------- */
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.search-submit .spinner {
  display: none;
}

.search-form.is-loading .search-submit .spinner {
  display: block;
}

.search-form.is-loading .search-submit svg {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Tablet and up ---------- */
@media (min-width: 600px) {
  :root {
    --page-gutter: var(--space-5);
  }

  .site-header-inner {
    flex-direction: row;
    align-items: center;
    gap: var(--space-5);
  }

  .site-header .brand-name {
    display: inline;
  }

  .kbd-hint {
    display: inline-block;
  }

  .result-source-text {
    flex-direction: row;
    align-items: baseline;
    gap: var(--space-2);
  }

  .result-path {
    font-size: var(--fs-sm);
  }
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  :root {
    --page-gutter: var(--space-6);
  }

  /* Align results with the search box, past the logo */
  .results-main {
    padding-left: calc(var(--page-gutter) + 160px);
  }

  .site-header .brand {
    width: 140px;
  }
}
