/*
 * CSLIB Theses Facet Styles
 * @version v0.6.7.1 (rebuilt)
 * - Right-aligned facet counts
 * - Toolbar buttons styled to CSLIB palette
 * - Holding/Keywords: label on top, chips wrap under
 * - Dual pagers, See-more button style
 */

/* =============== Cards / Result grid =============== */

.res-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
@media (max-width: 980px) {
  .res-card { grid-template-columns: 1fr; gap: 12px; }
}

/* Call number badge */
.res-card .callno-badge {
  width: 92px;
  border-radius: 8px;
  overflow: hidden;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 14px;
  text-align: center;
  color: #475569;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 4px;
  min-height: 0;
  align-self: start;
}
.res-card .callno-badge.is-empty { height: 72px; }
.res-card .cn-line { word-break: break-all; line-height: 1.1; }

.res-body { flex-grow: 1; }
.res-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--cslib-navy);
}

/* 3-column key/value grid inside the card */
.res-kv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 12px;
}
@media (max-width: 980px) {
  .res-kv-grid { grid-template-columns: 1fr; }
}
.kv-group { display: flex; flex-direction: column; gap: 6px; }

.kv { font-size: 14px; color: #4b5565; }
.kv .k { font-weight: 600; display: block; }
.kv .v { font-weight: 400; display: block; }

/* Pills (holding/keywords) – label on top, chips wrap below */
.kv.pills { display: block; }
.kv.pills .v {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.kv.pills .pill,
.kv-hold.pills .pill,
.kv-keywords.pills .pill {
  padding: 4px 8px;
  background: #eef2ff;
  color: var(--cslib-federal);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

/* =============== Footer grid (if used) =============== */
.res-footer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 12px;
  margin-top: 12px;
}
@media (max-width: 980px) {
  .res-footer-grid { grid-template-columns: 1fr; }
}

/* =============== Layout: sidebar + main =============== */

.cslib-theses-wrap {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}
@media (max-width: 980px) {
  .cslib-theses-wrap { grid-template-columns: 1fr; }
}
.cs-sidebar { display: flex; flex-direction: column; gap: 14px; }
.cs-main     { display: flex; flex-direction: column; gap: 14px; }

.cs-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.cs-card-title {
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--cslib-federal);
}

/* =============== Facets =============== */

.cs-facet { display: flex; flex-direction: column; gap: 8px; }

/* Collapsible containers; .show-all removes the cap */
.cs-facet-collapsible {
  max-height: 250px;
  overflow-y: hidden;
}
.cs-facet-collapsible.show-all { max-height: none; overflow: visible; }

/* Facet item with right-aligned count */
.facet-item {
  display: flex;
  justify-content: space-between;    /* push pill to far right */
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  transition: background .2s, border-color .2s, color .2s;
}
.facet-item:hover { background: var(--hover); }
.facet-item.is-active {
  background: var(--cslib-federal);
  color: #fff;
  border-color: var(--cslib-federal);
}
.facet-item .name {
  flex: 1;                /* take available space */
  text-align: left;
  min-width: 0;           /* allow ellipsis if needed */
}
.facet-item .pill {
  flex-shrink: 0;
  margin-left: auto;      /* guarantees right edge alignment */
  background: #eef2ff;
  color: var(--cslib-federal);
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.facet-item.is-active .pill {
  background: var(--cslib-gold);
  color: var(--cslib-federal);
  border-color: var(--cslib-gold);
}

.facet-empty {
  padding: 8px;
  font-style: italic;
  color: var(--muted);
  text-align: center;
}

/* Year chips */
.year-row { display: flex; align-items: center; gap: 8px; }
.year-row input { flex: 1; min-width: 0; }
.year-row .dash { flex-shrink: 0; color: var(--muted); }
.year-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.year-chips .chip {
  background: #eef2ff;
  color: var(--cslib-federal);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.year-chips .chip:hover { background: #d4e1ff; }

/* See more control (injected after collapsible) */
.cs-facet-more{
  background: transparent;
  border: 1px dashed var(--border-2);
  color: var(--cslib-federal);
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 6px;
}
.cs-facet-more:hover{ background:#eef2ff; }

/* =============== Toolbar =============== */

.cs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.cs-search,
.cs-search-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* wider, responsive input */
.cs-search select#cs-field { min-width: 190px; }
.cs-search input#cs-q {
  flex: 1 1 520px;
  min-width: 220px;
}

/* Inputs/selects look & focus */
.cslib-theses-sidebar input[type="search"],
.cslib-theses-sidebar input[type="number"],
.cs-search input,
.cs-search select,
.cs-search-right select {
  padding: .6rem .8rem;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: #fff;
}
.cs-search input:focus-visible,
.cs-search select:focus-visible,
.cs-search-right select:focus-visible,
.cslib-theses-sidebar input:focus-visible {
  outline: 0;
  border-color: color-mix(in srgb, var(--cslib-federal) 35%, var(--border-2));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cslib-federal) 20%, transparent);
}

/* Buttons – CSLIB palette */
.btn {
  --btn-bg: #fff;
  --btn-fg: var(--cslib-navy);
  --btn-bd: var(--border-2);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: 10px;
  padding: .55rem .9rem;
  font-weight: 600;
  line-height: 1;
  transition: transform .02s ease, background .15s ease, color .15s ease, border-color .15s ease;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cslib-federal) 25%, transparent);
}

.btn-primary {
  --btn-bg: var(--cslib-federal);
  --btn-fg: #fff;
  --btn-bd: var(--cslib-federal);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-color: var(--btn-bd);
}
.btn-primary:hover { filter: brightness(0.95); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-ghost {
  --btn-bg: transparent;
  --btn-fg: var(--cslib-federal);
  --btn-bd: var(--border-2);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-color: var(--btn-bd);
}
.btn-ghost:hover {
  background: #eef2ff;
  border-color: color-mix(in srgb, var(--cslib-federal) 25%, var(--border-2));
}

/* Make the Search button primary */
.cs-search #cs-go { background: var(--cslib-federal); color:#fff; border-color: var(--cslib-federal); }

/* =============== Active filter chips =============== */

.cs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.cs-chips .chip {
  background: var(--cslib-federal);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cs-chips .chip .x {
  background: none;
  border: none;
  color: #fff;
  opacity: 0.8;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

/* =============== Pager =============== */

.cs-pager { display: flex; gap: 8px; justify-content: center; }
.cs-pager .btn { padding: .5rem .75rem; border-radius: 8px; }
.cs-pager .btn.btn-primary { background: var(--cslib-federal); color: #fff; border-color: var(--cslib-federal); }
.cs-pager .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* Institute breakdown (right-align counts like facets) */
.lvl-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lvl-row {
  display: flex;
  justify-content: space-between;     /* push pill to the far right */
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  transition: background .2s, border-color .2s, color .2s;
}

.lvl-row:hover { background: var(--hover); }

.lvl-row .lvl-name {
  flex: 1;
  text-align: left;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lvl-row .pill {
  flex-shrink: 0;
  margin-left: auto;                  /* guarantees right alignment */
  background: #eef2ff;
  color: var(--cslib-federal);
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.lvl-row.is-active {
  background: var(--cslib-federal);
  color: #fff;
  border-color: var(--cslib-federal);
}
.lvl-row.is-active .pill {
  background: var(--cslib-gold);
  color: var(--cslib-federal);
  border-color: var(--cslib-gold);
}

/* Faculty filter: make search input full-width inside facet card */
#cs-faculty-card .cs-search,
#cs-adv-card .cs-search {
  display: block;        /* stack as block container */
  width: 100%;
}

#cs-faculty-card .cs-search input[type="search"],
#cs-adv-card .cs-search input[type="search"] {
  width: 100%;           /* span whole card */
  box-sizing: border-box;
  display: block;
}

/* ============= Faculty accordion ============= */
.fac-acc { border: 1px solid var(--border-2); border-radius: 10px; overflow: hidden; background:#fff; }
.fac-acc + .fac-acc { margin-top: 8px; }

/* Head row: looks like a facet item, with right-aligned count */
.fac-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;   /* pushes pill to right */
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}
.fac-head:hover { background: var(--hover); }
.fac-head.is-active {
  background: var(--cslib-federal);
  color: #fff;
}
.fac-head .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fac-head .pill {
  flex-shrink: 0;
  margin-left: auto;
  background: #eef2ff;
  color: var(--cslib-federal);
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.fac-head.is-active .pill {
  background: var(--cslib-gold);
  color: var(--cslib-federal);
  border-color: var(--cslib-gold);
}
.fac-head .chev { margin-left: 6px; opacity: .7; }

/* Detail panel: compact table, non-wrapping, contained */
.fac-detail { padding: 8px 12px 12px; border-top: 1px solid var(--border-2); background:#fafbff; }
.fac-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;      /* prevents overflow */
}
.fac-table th, .fac-table td {
  padding: 6px 8px;
  border: 1px solid var(--border-2);
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}
.fac-table thead th:first-child,
.fac-table tbody th { text-align: left; width: 50%; }
.fac-table thead th { background: #f6f8ff; }

/* Faculty filter input: full width in card */
#cs-faculty-card .cs-search { display:block; width:100%; }
#cs-faculty-card .cs-search input[type="search"] { width:100%; box-sizing:border-box; display:block; }

/* See-more stays visible outside collapsible */
#cs-faculty-card .cs-facet-collapsible.show-all { max-height:none; overflow:visible; }

/* Faculty table: compact spacing */
.fac-table th, .fac-table td { padding: 6px 6px; font-size: 13px; }

/* Faculty table: role left, counts centered */
.fac-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.fac-table th,
.fac-table td {
  padding: 6px 6px;
  font-size: 13px;
  border: 1px solid var(--border-2);
  vertical-align: middle;
  white-space: nowrap;
}

/* Header row */
.fac-table thead th {
  background: #f6f8ff;
  font-weight: 600;
  text-align: center;   /* center BS/MS/PhD headers */
}

/* Role column (first col) stays left */
.fac-table thead th:first-child,
.fac-table tbody th {
  text-align: left;
  width: 40%;
}

/* Number cells stay centered */
.fac-table tbody td {
  text-align: center;
}

/* Year facet: align inputs with facet UI */
#cs-year-card .year-row {
  display: grid;
  grid-template-columns: 1fr 28px 1fr 76px; /* min | to | max | Go */
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

/* Make inputs match other controls */
#cs-year-card .year-row input[type="number"] {
  padding: .6rem .8rem;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: #fff;
  line-height: 1;
  width: 100%;
  box-sizing: border-box;
}

/* Focus state consistent with search/selects */
#cs-year-card .year-row input[type="number"]:focus-visible {
  outline: 0;
  border-color: color-mix(in srgb, var(--cslib-federal) 35%, var(--border-2));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cslib-federal) 20%, transparent);
}

/* Subtle placeholder + remove spinners */
#cs-year-card .year-row input::placeholder { color: #94a3b8; }
#cs-year-card .year-row input[type="number"]::-webkit-outer-spin-button,
#cs-year-card .year-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#cs-year-card .year-row input[type="number"] { -moz-appearance: textfield; }

/* "to" separator */
#cs-year-card .year-row .dash {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

/* Make Go button match primary action */
#cs-year-card .year-row #cs-year-apply.btn {
  background: var(--cslib-federal);
  color: #fff;
  border-color: var(--cslib-federal);
  padding: .6rem 1rem;
  border-radius: 10px;
}

/* Responsive: stack nicely on narrow screens */
@media (max-width: 520px) {
  #cs-year-card .year-row {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: auto;
  }
  #cs-year-card .year-row input[type="number"]:first-child { grid-column: 1 / span 1; }
  #cs-year-card .year-row .dash { display: none; }
  #cs-year-card .year-row input[type="number"]:nth-of-type(2) { grid-column: 2 / span 1; }
  #cs-year-card .year-row #cs-year-apply { grid-column: 1 / span 2; }
}

.callno-badge.cn-ug  { background:#14532d; color:#FFD60A; border-color:#14532d; }
.callno-badge.cn-ms  { background:#800000; color:#FFD60A; border-color:#800000; }
.callno-badge.cn-phd { background:#4b0000; color:#FFD60A; border-color:#4b0000; }

/* Force label-on-top layout for pills blocks */
.res-kv-grid .kv.pills {
  display: block !important;      /* override earlier flex */
}
.res-kv-grid .kv.pills .k {
  display: block;
  margin-bottom: 6px;             /* spacing between label and chips */
}
.res-kv-grid .kv.pills .v {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

