/* ═══════════════════════════════════════════════════════════
   RIBsONLY Knowledge Finder — Stylesheet
   ═══════════════════════════════════════════════════════════ */

:root {
  --color-bg:          #fafafa;
  --color-surface:     #ffffff;
  --color-border:      #e8e8e8;
  --color-text:        #1a1a1a;
  --color-text-muted:  #6b7280;
  --color-text-light:  #9ca3af;
  --color-accent:      #0f4c81;
  --color-accent-dark: #0a3660;
  --color-accent-pale: #e8f0f9;
  --color-mark:        #fef3c7;
  --color-chip-bg:     #f0f4f8;
  --color-chip-hover:  #dce9f5;

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-pill: 999px;

  --shadow-card:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,.12);
  --shadow-input:      0 0 0 3px rgba(15,76,129,.15);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  40px;
  --space-2xl: 64px;

  --max-width:        640px;
  --pillar-height:    52px;
  --footer-height:    48px;
  --bottom-clearance: calc(var(--pillar-height) + var(--footer-height));
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100dvh;
  padding-bottom: var(--bottom-clearance);
  overflow-y: scroll;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  background: var(--color-accent);
  color: #fff;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 1000;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-sm);
}

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

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  align-items: center;
}

.brand-link {
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--color-accent);
}

.brand-dot,
.brand-tld {
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.brand-link:hover .brand-name {
  color: var(--color-accent-dark);
}

/* ── Main ───────────────────────────────────────────────── */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* ── Search Section ─────────────────────────────────────── */
.search-section {
  padding-top: var(--space-xl);
  padding-bottom: var(--space-lg);
}

.finder-heading {
  font-size: clamp(1.4rem, 5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
  line-height: 1.25;
}

.finder-subheading {
  font-size: .95rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-lg);
}

/* ── Search Form ────────────────────────────────────────── */
.search-form {
  position: relative;
}

.search-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 56px;
  padding: 0 96px 0 var(--space-md);
  font-size: 1.05rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.search-input:focus {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-input);
}

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

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 0 calc(var(--radius-md) - 2px) calc(var(--radius-md) - 2px) 0;
  cursor: pointer;
  transition: background .15s ease;
}

.search-btn:hover {
  background: var(--color-accent-dark);
}

.clear-btn {
  position: absolute;
  right: 56px;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 var(--space-md);
  min-width: 48px;
  min-height: 48px;
  transition: color .15s ease;
}

.clear-btn:hover {
  color: var(--color-text);
}

/* ── Autocomplete ───────────────────────────────────────── */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  list-style: none;
  z-index: 200;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.autocomplete-list[hidden] {
  display: none;
}

.autocomplete-item button {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 14px var(--space-md);
  background: none;
  border: none;
  font-size: 1rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  transition: background .1s ease;
}

.autocomplete-item button:hover,
.autocomplete-item button[aria-selected="true"] {
  background: var(--color-accent-pale);
  color: var(--color-accent);
}

.autocomplete-item:not(:last-child) button {
  border-bottom: 1px solid var(--color-border);
}

.autocomplete-icon {
  color: var(--color-text-light);
  flex-shrink: 0;
}

.autocomplete-match {
  font-weight: 700;
  color: var(--color-accent);
}

/* ── Brand Chips ────────────────────────────────────────── */
.brand-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 2px solid var(--color-accent);
}

.chips-label {
  font-size: 1rem;
  color: var(--color-accent);
  font-weight: 700;
  letter-spacing: -.01em;
  width: 100%;
  margin-bottom: var(--space-xs);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--color-chip-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: .875rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  min-height: 44px;
  text-decoration: none;
}

.chip:hover,
.chip:focus-visible {
  background: var(--color-chip-hover);
  border-color: var(--color-accent);
  color: var(--color-accent);
  outline: none;
  text-decoration: none;
}

/* ── Results Region ─────────────────────────────────────── */
.results-region {
  padding-bottom: var(--space-xl);
}

.results-region:empty {
  display: none;
}

/* ── Loading ────────────────────────────────────────────── */
.results-loading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-lg) 0;
  color: var(--color-text-muted);
  font-size: .9rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

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

/* ── Results Header ─────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md) 0 var(--space-sm);
  border-bottom: 2px solid var(--color-accent);
  margin-bottom: var(--space-md);
}

.results-brand-heading {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.01em;
}

.results-count {
  font-size: .8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ── Results List ───────────────────────────────────────── */
.results-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* ── Result Card ────────────────────────────────────────── */
.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: box-shadow .2s ease, border-color .2s ease;
  animation: fadeIn .2s ease both;
}

.result-card:hover {
  box-shadow: var(--shadow-card-hover);
  border-color: #d1dce8;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-link {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  text-decoration: none;
  color: inherit;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-meta {
  margin-bottom: var(--space-xs);
}

.card-type {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: var(--color-accent-pale);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
  line-height: 1.4;
  letter-spacing: -.01em;
}

.card-title mark {
  background: var(--color-mark);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.card-excerpt {
  font-size: .875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin-bottom: var(--space-sm);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-cta {
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-accent);
  letter-spacing: .01em;
}

.card-link:hover .card-cta {
  text-decoration: underline;
}

.card-thumb {
  flex-shrink: 0;
  width: 80px;
  align-self: flex-start;
}

.card-thumb img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
}

/* ── No Results ─────────────────────────────────────────── */
.no-results {
  padding: var(--space-xl) 0 var(--space-lg);
  text-align: center;
}

.no-results-heading {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

.no-results-heading strong {
  color: var(--color-text);
}

.no-results-suggest {
  font-size: .9rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-lg);
}

.suggest-link {
  background: none;
  border: none;
  font-family: var(--font-sans);
  font-size: inherit;
  font-weight: 600;
  color: var(--color-accent);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.no-results-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 12px 20px;
  background: var(--color-chip-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: .9rem;
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  transition: background .15s ease;
  min-height: 48px;
}

.btn-secondary:hover {
  background: var(--color-chip-hover);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ── Show More ──────────────────────────────────────────── */
.show-more-wrap {
  display: none;
  justify-content: center;
  padding: var(--space-lg) 0 var(--space-xl);
}

.show-more-wrap.visible {
  display: flex;
}

.show-more-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 14px 28px;
  background: var(--color-surface);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-pill);
  font-size: .95rem;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--color-accent);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  min-height: 48px;
}

.show-more-btn:hover {
  background: var(--color-accent);
  color: #fff;
}

.show-more-count {
  font-size: .8rem;
  font-weight: 400;
  opacity: .75;
}

/* ── Pillar Bar ─────────────────────────────────────────── */
.pillar-bar {
  position: fixed;
  bottom: var(--footer-height);
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--color-accent-pale);
  border-top: 1px solid #c5d8ef;
}

.pillar-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  height: var(--pillar-height);
  text-decoration: none;
  max-width: var(--max-width);
  margin: 0 auto;
}

.pillar-icon {
  color: var(--color-accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.pillar-text {
  font-size: .85rem;
  color: var(--color-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pillar-text strong {
  color: var(--color-accent);
}

.pillar-arrow {
  color: var(--color-accent);
  font-weight: 700;
  flex-shrink: 0;
}

.pillar-link:hover .pillar-text strong {
  text-decoration: underline;
}

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  height: var(--footer-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.footer-copy {
  font-size: .72rem;
  color: var(--color-text-light);
  text-align: center;
  padding: 0 var(--space-md);
}

.footer-site-link {
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
}

.footer-site-link:hover {
  color: var(--color-accent);
}

/* ── Desktop Enhancement ────────────────────────────────── */
@media (min-width: 640px) {
  .search-section {
    padding-top: var(--space-2xl);
  }

  .search-input {
    height: 60px;
    font-size: 1.1rem;
    padding-left: var(--space-lg);
  }

  .search-btn {
    width: 60px;
  }

  .clear-btn {
    right: 60px;
  }

  .card-thumb {
    width: 100px;
  }

  .card-thumb img {
    width: 100px;
    height: 75px;
  }

  .pillar-text {
    white-space: normal;
  }

  .no-results-actions {
    flex-direction: row;
    justify-content: center;
  }
}

/* ── Reduced Motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ── Dark Mode ──────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:          #111827;
    --color-surface:     #1f2937;
    --color-border:      #374151;
    --color-text:        #f9fafb;
    --color-text-muted:  #9ca3af;
    --color-text-light:  #6b7280;
    --color-accent:      #60a5fa;
    --color-accent-dark: #93c5fd;
    --color-accent-pale: #1e3a5f;
    --color-mark:        #451a03;
    --color-chip-bg:     #374151;
    --color-chip-hover:  #1e3a5f;
  }

  .search-btn {
    background: var(--color-accent);
    color: #111827;
  }

  .search-btn:hover {
    background: var(--color-accent-dark);
  }

  .show-more-btn {
    background: transparent;
  }

  .show-more-btn:hover {
    background: var(--color-accent);
    color: #111827;
  }
}

/* ── Print ──────────────────────────────────────────────── */
@media print {
  .pillar-bar,
  .site-footer,
  .search-form,
  .brand-chips,
  .show-more-wrap {
    display: none;
  }

  body {
    padding-bottom: 0;
  }
}