/*
 * Journal Policy Finder — visual design
 *
 * Concept: a library card catalog. Every result renders as an index card:
 * a serif masthead for the journal title, a monospaced "call number" for
 * the ISSN, a dashed rule standing in for the line under a catalog card's
 * heading, and a punched corner notch. The TA badge reads as a librarian's
 * ink stamp; the "not yet curated" flag reads as a handwritten margin note
 * in a different ink, so curated vs. fallback are distinguishable at a
 * glance, not just by reading the text.
 *
 * Palette is Northwestern's own purple (#4E2A84) rather than a generic
 * accent, since this is a Northwestern Libraries tool. Type is system
 * fonts only (no CDN): a serif stack for display, a sans stack for UI,
 * a monospace stack for identifiers.
 */

:root {
  --purple: #4e2a84;
  --purple-ink: #2c1655;
  --purple-tint: #efe9f7;
  --ink: #201d26;
  --muted: #625c6d;
  --paper: #faf8f4;
  --card: #fffdfa;
  --line: #ddd3c4;
  --line-strong: #b9ac95;
  --stamp: #a9631a;
  --stamp-tint: #fbeed9;
  --flag: #a13d2a;
  --flag-tint: #fbece6;
  --focus: #1063c9;

  --font-display: Iowan Old Style, Palatino Linotype, Palatino, Georgia, "Noto Serif", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --purple: #b79ce0;
    --purple-ink: #ded0f2;
    --purple-tint: #362a48;
    --ink: #ece8f0;
    --muted: #b3aac0;
    --paper: #17151c;
    --card: #211e29;
    --line: #3c3646;
    --line-strong: #554e63;
    --stamp: #e0a34f;
    --stamp-tint: #3a2c14;
    --flag: #e08a72;
    --flag-tint: #3a1f18;
    --focus: #7db4ff;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

.wrap {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

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

.skip-links a {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  background: var(--purple);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 0.4rem 0;
}

.skip-links a:focus {
  left: 0;
}

a {
  color: var(--purple);
}

a:hover {
  color: var(--purple-ink);
}

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

/* ---------- Header ---------- */

.site-header {
  background: var(--purple);
  color: #f4effa;
  padding: 2.5rem 0 2.25rem;
  border-bottom: 6px double rgba(255, 255, 255, 0.35);
}

.site-header .eyebrow {
  margin: 0 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d8c7ee;
}

.site-header h1 {
  margin: 0 0 0.9rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.35rem;
  letter-spacing: 0.01em;
}

.site-header .lede {
  max-width: 40rem;
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
  color: #ede6f7;
}

.site-header .lede-secondary {
  font-size: 0.95rem;
  color: #d8c7ee;
}

.site-header a {
  color: #fff;
  text-decoration-color: rgba(255, 255, 255, 0.5);
}

.site-header a:hover {
  color: #fff;
  text-decoration-color: #fff;
}

/* ---------- Panels ---------- */

main {
  padding: 2rem 0 3rem;
}

.panel {
  margin-bottom: 2rem;
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0 0 0.75rem;
  color: var(--purple-ink);
}

.hint {
  margin: -0.4rem 0 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ---------- Search ---------- */

.search-form {
  display: flex;
  gap: 0.6rem;
}

.search-form input {
  flex: 1;
  font-size: 1.15rem;
  font-family: var(--font-body);
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--line-strong);
  border-radius: 0.4rem;
  background: var(--card);
  color: var(--ink);
}

.search-form input:focus {
  border-color: var(--purple);
}

.search-form button,
#browse {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1.3rem;
  border: 2px solid var(--purple);
  border-radius: 0.4rem;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
}

.search-form button:hover,
#browse:hover {
  background: var(--purple-ink);
  border-color: var(--purple-ink);
}

/* ---------- Browse / tags ---------- */

.browse-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.ta-only-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.ta-only-toggle input {
  accent-color: var(--stamp);
}

/* ---------- Results: cards ---------- */

#results p {
  color: var(--muted);
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 1.5rem 1.6rem 1.4rem;
  box-shadow: 0 1px 0 var(--line), 0 8px 20px -14px rgba(32, 29, 38, 0.35);
}

/* punched corner notch, catalog-card style */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 22px 22px 0;
  border-color: transparent var(--paper) transparent transparent;
  filter: drop-shadow(-1px 1px 0 var(--line));
}

.card h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 0.15rem;
  padding-right: 1.5rem;
  color: var(--ink);
}

.card .issn {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.9rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px dashed var(--line-strong);
}

.card .publisher {
  margin: 0 0 0.6rem;
}

.card .policy-links {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.card .policy-links li:empty,
.card .policy-links li:has(> :only-child:empty) {
  display: none;
}

.card .policy-links a {
  font-weight: 600;
}

.card .note {
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.card .verified {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.6rem;
}

/* TA badge: reads like a librarian's ink stamp */
.ta-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--stamp);
  background: var(--stamp-tint);
  border: 2px solid var(--stamp);
  border-radius: 0.3rem;
  padding: 0.5rem 0.75rem;
  margin: 0 0 0.9rem;
  transform: rotate(-0.6deg);
}

.ta-badge a {
  color: inherit;
  text-decoration-thickness: 2px;
}

/* fallback flag: a handwritten margin note in a different ink */
.card.fallback .flag {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.98rem;
  color: var(--flag);
  background: var(--flag-tint);
  border-left: 3px solid var(--flag);
  padding: 0.5rem 0.8rem;
  margin: 0.8rem 0;
}

.card.fallback::before {
  border-color: transparent var(--flag-tint) transparent transparent;
}

/* ---------- Disambiguation & list results ---------- */

.disambig-list,
.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.disambig-list li,
.result-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.15rem;
}

button.disambig,
button.result {
  flex: 1;
  text-align: left;
  background: none;
  border: 0;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  font-family: var(--font-body);
  color: var(--ink);
  cursor: pointer;
  border-radius: 0.25rem;
}

button.disambig:hover,
button.result:hover {
  background: var(--purple-tint);
  color: var(--purple-ink);
}

.result-list .pub {
  font-size: 0.85rem;
  color: var(--muted);
  padding-right: 0.85rem;
  white-space: nowrap;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0 2.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0 0 0.5rem;
}

@media (max-width: 32rem) {
  .site-header h1 {
    font-size: 1.8rem;
  }

  .search-form {
    flex-direction: column;
  }

  .disambig-list li,
  .result-list li {
    flex-direction: column;
    align-items: stretch;
  }

  .result-list .pub {
    padding: 0 0.85rem 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---- Grouped discipline chips -------------------------------------------
   Chips are grouped under their Google Scholar area because 41 subcategory
   labels are duplicated across areas; the heading is what tells two identical
   "Public Health" chips apart. Chips with no journals are never rendered. */

/* ---- Status / loading / error messages ---------------------------------- */
.status {
  margin: 0;
  padding: 0.9rem 1rem;
  border-radius: 8px;
  background: var(--surface-2, #f4f1ea);
  color: var(--muted, #6b6558);
}

.status.loading::after {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 0.5em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -0.05em;
}

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

@media (prefers-reduced-motion: reduce) {
  .status.loading::after { animation: none; }
}

.status.error {
  background: #fdeeee;
  color: #8a1f1f;
  border: 1px solid #e8b4b4;
}

.result-count {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  color: var(--muted, #6b6558);
}

.disambig-list .meta {
  display: block;
  font-size: 0.84rem;
  color: var(--muted, #6b6558);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ==========================================================================
   Search panel: mode toggle + swapping field + TA filter
   One block at the top so results stay on screen. The previous layout put a
   172-checkbox grid between the search box and the results.
   ========================================================================== */
.search-panel { position: relative; z-index: 20; }

.search-form { display: flex; flex-direction: column; gap: 0.85rem; }

.mode-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--rule, #d8d4cc);
  border-radius: 999px;
  padding: 3px;
  margin: 0;
  align-self: flex-start;
  max-width: 100%;
  flex-wrap: wrap;
}

.mode-option { position: relative; }

.mode-option input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}

.mode-option span {
  display: block;
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--muted, #6b6558);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.mode-option input:checked + span {
  background: var(--accent, #4e2a84);
  color: #fff;
}

.mode-option input:focus-visible + span {
  outline: 2px solid var(--accent, #4e2a84);
  outline-offset: 2px;
}

.search-row { display: flex; gap: 0.6rem; align-items: flex-start; }
.search-field { flex: 1 1 auto; min-width: 0; }
.search-row > button { flex: 0 0 auto; }

.ta-only-toggle {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--muted, #6b6558);
  cursor: pointer;
}
.ta-only-toggle input { margin-top: 0.2rem; flex: 0 0 auto; }

/* ---- Discipline picker --------------------------------------------------- */
.picker { position: relative; }

.picker-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--rule, #d8d4cc);
  border-radius: 8px;
  background: var(--surface, #fff);
}
.picker-control:focus-within {
  border-color: var(--accent, #4e2a84);
  box-shadow: 0 0 0 3px rgba(78, 42, 132, 0.14);
}

.picker-open {
  flex: 1 1 8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: 0;
  padding: 0.3rem 0.2rem;
  font: inherit;
  color: var(--muted, #6b6558);
  cursor: pointer;
  text-align: left;
}
.picker-control.has-pills .picker-open { flex-basis: 6rem; }
.picker-caret { opacity: 0.6; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--accent, #4e2a84);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.4;
}
.pill-x {
  border: 0;
  background: rgba(255, 255, 255, 0.22);
  color: inherit;
  width: 1.15rem; height: 1.15rem;
  border-radius: 50%;
  line-height: 1;
  cursor: pointer;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
}
.pill-x:hover { background: rgba(255, 255, 255, 0.4); }

.picker-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 30;
  max-height: 19rem;
  overflow-y: auto;
  background: var(--surface, #fff);
  border: 1px solid var(--rule, #d8d4cc);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}

.picker-list { list-style: none; margin: 0; padding: 0.25rem; }

.picker-area,
.picker-topic {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: 0;
  border-radius: 6px;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.picker-area { justify-content: space-between; }
.picker-area:hover,
.picker-topic:hover,
.picker-area:focus-visible,
.picker-topic:focus-within { background: var(--surface-2, #f4f1ea); }

.picker-topic span:first-of-type { flex: 1 1 auto; }
.picker-topic.is-disabled { opacity: 0.45; cursor: not-allowed; }

.picker-meta {
  font-size: 0.82rem;
  color: var(--muted, #6b6558);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.picker-crumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--rule, #d8d4cc);
  position: sticky;
  top: 0;
  background: var(--surface, #fff);
}
.picker-back {
  border: 0; background: none; padding: 0.15rem 0.3rem;
  font: inherit; color: var(--accent, #4e2a84); cursor: pointer; border-radius: 4px;
}
.picker-back:hover { text-decoration: underline; }
.picker-crumb-area { font-weight: 600; font-size: 0.9rem; }

.picker-hint {
  min-height: 1.15em;
  margin: 0.3rem 0 0;
  font-size: 0.86rem;
  color: var(--accent, #4e2a84);
}

.status.intro { background: none; padding: 0.4rem 0; }

@media (max-width: 34rem) {
  .search-row { flex-direction: column; align-items: stretch; }
  .search-row > button { width: 100%; }
  .mode-toggle { display: flex; width: 100%; }
  .mode-option { flex: 1 1 0; }
  .mode-option span { text-align: center; padding-inline: 0.5rem; }
}

@media (prefers-color-scheme: dark) {
  .picker-panel, .picker-crumb { background: var(--surface, #1e1c19); }
}

/* Pills sit directly in the control's flex flow rather than in a nested box. */
.picker-pills { display: contents; }

.picker-open-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Agreement marker on result rows: purple disc, white check. Paired with the
   TA-first sort in filter.js, so the checked rows cluster at the top. */
.ta-check {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--accent, #4e2a84);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

@media (prefers-contrast: more) {
  .ta-check { outline: 1px solid #fff; outline-offset: -2px; }
}

.result-list li > .ta-check { margin-left: 0.35rem; }

.ta-note { color: var(--accent, #4e2a84); }
