/* css/search.css
   Program search view (#/programs). Uses ONLY the palette custom
   properties defined in css/admin.css (--bg, --surface, --surface2,
   --outline, --navy, --muted, --dim, --text, --accent, --accent-bright,
   --green, --amber, --red, --blue, and the *-tint alpha variants). Any
   additional token this view needs (grey/purple tint, focus glow, radii)
   is derived locally under .search-view so it never leaks into other
   views that also load admin.css.

   Two modes, switched by a modifier class on .search-view (see
   js/search.js render()):
     .search-view--grid   — 260px filter rail + a responsive tile grid.
                             No detail pane shown up front (per user
                             feedback: filters + tiles first, detail on
                             click).
     .search-view--detail — a single full-width, centered (~900px)
                             column showing one program's full record,
                             with a "Back to results" button. The rail is
                             hidden in this mode — see js/search.js's
                             buildDetailPage() comment for why.
*/

.search-view {
  --sv-gray-tint: rgba(100, 116, 139, 0.13);
  --sv-purple: #A78BFA;
  --sv-purple-tint: rgba(167, 139, 250, 0.13);
  --sv-glow: 0 0 0 3px rgba(20, 184, 166, 0.18);
  --sv-radius: 12px;
  --sv-radius-sm: 8px;

  display: grid;
  align-items: stretch;
  min-height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  overflow: hidden;
}

.search-view--grid {
  grid-template-columns: 260px 1fr;
}

.search-view--detail {
  grid-template-columns: 1fr;
}

.search-view * {
  box-sizing: border-box;
}

.search-view ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.search-view ::-webkit-scrollbar-thumb {
  background: var(--outline);
  border-radius: 8px;
}
.search-view {
  scrollbar-width: thin;
  scrollbar-color: var(--outline) transparent;
}

/* ---------------------------------------------------------------- */
/* Filter rail                                                       */
/* ---------------------------------------------------------------- */

.search-rail {
  min-width: 0;
  border-right: 1px solid var(--outline);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.search-rail__search-wrap {
  flex: none;
}

.search-rail__search-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius-sm);
  background: var(--surface);
  color: var(--text);
  font: 400 13px Inter, sans-serif;
  outline: none;
}
.search-rail__search-input::placeholder {
  color: var(--dim);
}
.search-rail__search-input:focus {
  border-color: var(--accent);
  box-shadow: var(--sv-glow);
}

.search-rail__chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.search-rail__chips--empty {
  display: none;
}

.search-rail__clear-all {
  font: 500 11.5px Inter, sans-serif;
  color: var(--dim);
  cursor: pointer;
}
.search-rail__clear-all:hover {
  color: var(--text);
}

.search-rail__group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-rail__group-title {
  font: 600 10.5px Inter, sans-serif;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.search-rail__group-title--amber {
  color: var(--amber);
}

.search-rail__option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  font: 400 12.5px Inter, sans-serif;
  color: var(--muted);
  cursor: pointer;
}
.search-rail__option:hover {
  color: var(--text);
}

.search-rail__native-checkbox {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.search-rail__box {
  position: relative;
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 4px;
  border: 1.5px solid var(--outline);
  box-sizing: border-box;
  background: transparent;
}
.search-rail__box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid #fff;
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg);
  opacity: 0;
}
.search-rail__native-checkbox:checked + .search-rail__box {
  background: var(--accent);
  border-color: var(--accent);
}
.search-rail__native-checkbox:checked + .search-rail__box::after {
  opacity: 1;
}
.search-rail__native-checkbox:focus-visible + .search-rail__box {
  box-shadow: var(--sv-glow);
}
.search-rail__native-checkbox:checked ~ .search-rail__option-label {
  color: var(--text);
}

.search-rail__option-label--green {
  color: var(--green);
}
.search-rail__option-label--amber {
  color: var(--amber);
}

.search-rail__option-count {
  margin-left: auto;
  color: var(--dim);
  font-size: 11.5px;
  flex: none;
}

.search-rail__more {
  font: 500 11.5px Inter, sans-serif;
  color: var(--accent-bright);
  cursor: pointer;
}
.search-rail__more:hover {
  text-decoration: underline;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--dim);
}
.status-dot--green {
  background: var(--green);
}
.status-dot--amber {
  background: var(--amber);
}
.status-dot--gray {
  background: var(--dim);
}

/* ---------------------------------------------------------------- */
/* Results column                                                    */
/* ---------------------------------------------------------------- */

.search-results {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.search-results__header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--outline);
}

.search-results__count {
  font: 700 14px "Plus Jakarta Sans", sans-serif;
}

.search-results__sort {
  margin-left: auto;
}
.search-results__sort-select {
  appearance: none;
  font: 500 12px Inter, sans-serif;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius-sm);
  padding: 6px 26px 6px 10px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) center, calc(100% - 10px) center;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.search-results__sort-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--sv-glow);
}

.search-results__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- */
/* Tile grid                                                          */
/* ---------------------------------------------------------------- */

.search-tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 16px;
}
@media (min-width: 1000px) {
  .search-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1400px) {
  .search-tiles {
    grid-template-columns: repeat(3, 1fr);
  }
}

.program-tile {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.program-tile:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}
.program-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.program-tile--skeleton {
  cursor: default;
  gap: 10px;
}
.program-tile--skeleton:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--outline);
}

.program-tile__row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.program-tile__amount {
  margin-left: auto;
  font: 600 12px Inter, sans-serif;
  color: var(--text);
  white-space: nowrap;
}

.program-tile__name {
  font: 700 15px "Plus Jakarta Sans", sans-serif;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.program-tile__sub {
  font: 400 11.5px Inter, sans-serif;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.program-tile__requires {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.program-tile__requires-label {
  font: 600 10px Inter, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.program-tile__requires-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.program-tile__requires-chips .chip,
.program-tile__footer .chip {
  padding: 2px 8px;
  font-size: 10.5px;
}

.program-tile__footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--outline);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.program-tile__verified {
  margin-left: auto;
  font: 500 10.5px Inter, sans-serif;
  color: var(--dim);
  white-space: nowrap;
}
.program-tile__verified.is-stale {
  color: var(--red);
}

.search-results__empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--dim);
  font: 400 12.5px Inter, sans-serif;
}

.search-detail__no-comments {
  color: var(--dim);
  font: 400 12.5px Inter, sans-serif;
}

.search-results__load-more-wrap {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-results__load-more {
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius-sm);
  background: transparent;
  color: var(--muted);
  font: 500 12px Inter, sans-serif;
  cursor: pointer;
}
.search-results__load-more:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}
.search-results__load-more:disabled {
  cursor: default;
  opacity: 0.6;
}

/* ---------------------------------------------------------------- */
/* Detail page (.search-view--detail mode)                           */
/* ---------------------------------------------------------------- */

.search-detail-page {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.search-detail-page__back {
  align-self: flex-start;
  flex: none;
  height: 34px;
  margin-bottom: 12px;
  padding: 0 14px;
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius-sm);
  background: transparent;
  color: var(--muted);
  font: 600 12.5px Inter, sans-serif;
  cursor: pointer;
}
.search-detail-page__back:hover {
  border-color: var(--accent);
  color: var(--text);
}

.search-detail-page__inner {
  width: 100%;
  max-width: 900px;
}

/* .search-detail was designed for a fixed-height 1fr column with its own
   internal scroll (min-height:0 + overflow-y:auto on __body). In the
   full-page layout .search-detail-page above is the single scroll
   container instead, so let the card grow to its natural content height,
   and give it a card treatment (background/border) since it now sits
   centered on the page background rather than flush against the rail. */
.search-detail-page__inner .search-detail {
  overflow: visible;
  min-height: auto;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius);
}
.search-detail-page__inner .search-detail__header {
  border-radius: var(--sv-radius) var(--sv-radius) 0 0;
}
.search-detail-page__inner .search-detail__body {
  overflow-y: visible;
  flex: none;
}

.search-detail {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.search-detail__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  font: 500 13px Inter, sans-serif;
}

.search-detail__header {
  flex: none;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--outline);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-detail__top {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.search-detail__title-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.search-detail__title {
  margin: 0;
  font: 700 20px "Plus Jakarta Sans", sans-serif;
}

.search-detail__subtitle {
  font: 400 12.5px Inter, sans-serif;
  color: var(--muted);
}

.search-detail__chips {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.chip-divider {
  width: 1px;
  height: 14px;
  background: var(--outline);
  flex: none;
}

.search-detail__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-detail__meta {
  font: 400 12px Inter, sans-serif;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.search-detail__meta-dot {
  color: var(--dim);
}

.search-detail__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-detail__card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.search-detail__card-title {
  font: 600 12.5px "Plus Jakarta Sans", sans-serif;
  color: var(--accent-bright);
}

.search-detail__text {
  margin: 0;
  font: 400 12.5px/1.55 Inter, sans-serif;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.search-detail__text b {
  color: var(--text);
  font-weight: 600;
}

.search-detail__criteria-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font: 400 12.5px/1.5 Inter, sans-serif;
  color: var(--muted);
}

.search-detail__flag {
  color: var(--amber);
  font-weight: 600;
}

.search-detail__link {
  color: var(--accent-bright);
  text-decoration: none;
}
.search-detail__link:hover {
  text-decoration: underline;
}

.search-detail__links-row {
  font: 500 12.5px/1.7 Inter, sans-serif;
  color: var(--muted);
}

.search-detail__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 1100px) {
  .search-detail__grid {
    grid-template-columns: 1fr;
  }
}

.search-detail__comments {
  gap: 10px;
}

.search-detail__signin-note {
  color: var(--dim);
  font: 400 12.5px Inter, sans-serif;
}

.search-detail__comment {
  display: flex;
  gap: 10px;
}
.search-detail__comment-avatar {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 10.5px Inter, sans-serif;
  color: var(--muted);
}
.search-detail__comment-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.search-detail__comment-body {
  font: 400 12.5px/1.5 Inter, sans-serif;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.search-detail__comment-meta {
  font: 400 11px Inter, sans-serif;
  color: var(--dim);
}

.search-detail__comment-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.search-detail__comment-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  padding: 8px 12px;
  border: 1px solid var(--outline);
  border-radius: var(--sv-radius-sm);
  background: var(--bg);
  color: var(--text);
  font: 400 12.5px/1.4 Inter, sans-serif;
  outline: none;
  resize: vertical;
}
.search-detail__comment-input::placeholder {
  color: var(--dim);
}
.search-detail__comment-input:focus {
  border-color: var(--accent);
  box-shadow: var(--sv-glow);
}

/* ---------------------------------------------------------------- */
/* Shared: chips, buttons, skeletons, errors                         */
/* ---------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font: 500 11px Inter, sans-serif;
  white-space: nowrap;
}
.chip--strong {
  font-weight: 600;
}
.chip--blue {
  background: var(--blue-tint);
  color: var(--blue);
}
.chip--green {
  background: var(--green-tint);
  color: var(--green);
}
.chip--amber {
  background: var(--amber-tint);
  color: var(--amber);
}
.chip--red {
  background: var(--red-tint);
  color: var(--red);
}
.chip--gray {
  background: var(--sv-gray-tint);
  color: var(--muted);
}
.chip--purple {
  background: var(--sv-purple-tint);
  color: var(--sv-purple);
}
.chip--accent {
  background: var(--accent-tint);
  color: var(--accent-bright);
  padding-right: 6px;
}

.chip__x {
  cursor: pointer;
  font-weight: 600;
  line-height: 1;
}
.chip__x:hover {
  color: var(--text);
}

.text-red {
  color: var(--red);
}
.text-amber {
  color: var(--amber);
}
.text-green {
  color: var(--green);
}

.sv-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--sv-radius-sm);
  font: 500 13px Inter, sans-serif;
  cursor: pointer;
  border: 1px solid var(--outline);
  background: transparent;
  color: var(--text);
}
.sv-btn--primary {
  height: 36px;
  padding: 0 16px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sv-btn--primary:hover {
  background: #0d9488;
}
.sv-btn--outline:hover {
  border-color: var(--accent);
}
.sv-btn--active-green {
  border-color: var(--green);
  color: var(--green);
}
.sv-btn--active-amber {
  border-color: var(--amber);
  color: var(--amber);
}

.sv-inline-error {
  color: var(--red);
  font: 500 11.5px Inter, sans-serif;
  align-self: center;
}

.sv-error {
  margin: 16px;
  padding: 14px 16px;
  border: 1px solid var(--red);
  border-radius: var(--sv-radius);
  background: var(--red-tint);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sv-error__text {
  color: var(--red);
  font: 500 12.5px Inter, sans-serif;
}
.sv-error__retry {
  margin-left: auto;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--red);
  border-radius: var(--sv-radius-sm);
  background: transparent;
  color: var(--red);
  font: 600 12px Inter, sans-serif;
  cursor: pointer;
  flex: none;
}
.sv-error__retry:hover {
  background: var(--red);
  color: #fff;
}

@keyframes sv-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 0.75;
  }
}
.sv-skel {
  background: var(--surface2);
  border-radius: 6px;
  animation: sv-pulse 1.4s ease-in-out infinite;
}
.sv-skel--row {
  height: 14px;
  width: 100%;
}
.sv-skel--title {
  height: 15px;
  width: 70%;
  margin-bottom: 6px;
}
.sv-skel--sub {
  height: 11px;
  width: 40%;
  margin-bottom: 8px;
}
.sv-skel--chips {
  height: 18px;
  width: 90%;
}
.sv-skel--detail-title {
  height: 24px;
  width: 45%;
  margin: 22px 22px 8px;
}
.sv-skel--detail-sub {
  height: 12px;
  width: 30%;
  margin: 0 22px 18px;
}
.sv-skel--card {
  height: 72px;
  margin: 0 22px 12px;
  border-radius: var(--sv-radius);
}

@media (max-width: 1180px) {
  .search-view--grid {
    grid-template-columns: 240px 1fr;
  }
}
