/*
  Gener8 library (/library) — layout on top of the shared style kit.

  The panel fills the whole browser window (7 Oct 2026: it used to float as a window
  on the reach line). Inside: title, search and count; the Type buttons; then a left
  rail of System and Region buttons beside the cards, which scroll.

  Sizes are in --u and text in --tu (kit/css/tokens.css), so it scales with the screen
  and ?ui= like the viewers. Cards match the staff page's cards: a 16:10 picture,
  title, a line about it, and its systems. Touch only: pressed states, no hover.
*/

/* ---- The panel ---------------------------------------------------------------------- */
.lib {
  position: fixed; inset: 0; z-index: 5;
  padding: calc(var(--u) * 2.4) calc(var(--u) * 3); border: 0; border-radius: 0; box-shadow: none;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: calc(var(--u) * 1.2);
}

/* ---- Top: title, search, count ---------------------------------------------------------- */
.lib-top { display: flex; align-items: center; gap: calc(var(--u) * 2); }
.lib-top .title { flex: none; }
.lib-search {
  flex: 1; max-width: calc(var(--u) * 80); display: flex; align-items: center; gap: calc(var(--u) * .8);
  min-height: calc(var(--u) * 5.8); padding: 0 calc(var(--u) * .4) 0 calc(var(--u) * 1.3);
  border-radius: var(--r); background: var(--well); border: 1px solid var(--line); color: var(--muted);
}
.lib-search input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font: inherit; font-size: calc(var(--tu) * 1.6); color: var(--ink);
  user-select: text; -webkit-user-select: text;
}
.lib-search input::-webkit-search-cancel-button { display: none; }
.lib-count { margin-left: auto; white-space: nowrap; }

/* ---- Type buttons ------------------------------------------------------------------------ */
.lib-types { grid-auto-columns: auto; justify-content: start; }
.lib-types button { padding: 0 calc(var(--u) * 1.6); display: flex; align-items: center; gap: calc(var(--u) * .6); white-space: nowrap; }
.lib-types button .num { font-size: calc(var(--tu) * 1.2); }
.lib-types button[data-empty] { opacity: .45; }

/* ---- Body: rail and results ------------------------------------------------------------------ */
.lib-body { display: grid; grid-template-columns: calc(var(--u) * 42) minmax(0, 1fr); gap: calc(var(--u) * 1.8); min-height: 0; }
.lib-rail {
  display: flex; flex-direction: column; gap: calc(var(--u) * .3); min-height: 0;
  overflow: auto; overscroll-behavior: contain; padding-right: calc(var(--u) * .4);
}
.lib-rail .kicker { padding: calc(var(--u) * 1) calc(var(--u) * .6) calc(var(--u) * .3); }
.lib-rail .kicker:first-child { padding-top: 0; }
/* Two columns, so every system and region fits on the panel without scrolling */
.lib-list { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--u) * .2) calc(var(--u) * .4); }

/* One system or region: colour dot, name, count */
.lib-chip {
  display: flex; align-items: center; gap: calc(var(--u) * .9);
  min-height: calc(var(--u) * 4.8); padding: 0 calc(var(--u) * .8); border-radius: var(--r); min-width: 0;
  text-align: left; font-size: calc(var(--tu) * 1.35);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lib-chip:active { background: var(--press); }
.lib-chip i { width: calc(var(--u) * 1.6); height: calc(var(--u) * 1.6); border-radius: 50%; flex: none; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.lib-chip span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.lib-chip[aria-pressed="true"] .num { color: var(--accent); }
.lib-chip[data-empty] { opacity: .4; }

.lib-results { display: flex; flex-direction: column; gap: calc(var(--u) * 1); min-height: 0; }
.lib-tools { display: flex; align-items: center; gap: calc(var(--u) * 1.2); flex-wrap: wrap; }
.lib-group { display: flex; align-items: center; gap: calc(var(--u) * .8); }
.lib-group .seg { grid-auto-columns: auto; }
.lib-group .seg button { padding: 0 calc(var(--u) * 1.4); }
.lib-tools .pill { margin-left: auto; }
.lib-status .seg { grid-auto-columns: auto; }
.lib-status .seg button { padding: 0 calc(var(--u) * 1.4); }
.lib-tools .pill + .pill { margin-left: 0; }
/* Size control (kit/js/size.js) sits in the tools row like Group by */
.lib-tools .g8-size { display: flex; align-items: center; gap: calc(var(--u) * .8); }
.lib-tools .g8-size .range-head { font-size: calc(var(--tu) * 1.2); color: var(--muted); }
.lib-tools .g8-size .seg { grid-auto-columns: auto; }
.lib-tools .g8-size .seg button { padding: 0 calc(var(--u) * 1.4); }
.lib-grid { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-right: calc(var(--u) * .4); }
.lib-empty { margin: calc(var(--u) * 6) auto; text-align: center; color: var(--muted); font-size: calc(var(--tu) * 1.5); }

/* A group of cards (grouped by system or region) */
.lib-sec + .lib-sec { margin-top: calc(var(--u) * 2.4); }
.lib-h {
  display: flex; align-items: center; gap: calc(var(--u) * .8); margin: 0 0 calc(var(--u) * 1);
  font-size: calc(var(--tu) * 1.8); font-weight: 700;
}
.lib-h i { width: calc(var(--u) * 1.6); height: calc(var(--u) * 1.6); border-radius: 50%; background: var(--c); }
.lib-h i.none { display: none; }
.lib-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--u) * 30), 1fr)); gap: calc(var(--u) * 1.4); }

/* ---- A card --------------------------------------------------------------------------------- */
.lcard {
  display: flex; flex-direction: column; text-align: left; overflow: hidden;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  transition: transform var(--dur) var(--ease);
}
.lcard:active { transform: scale(.98); }
.lc-pic { position: relative; display: block; aspect-ratio: 16 / 10; background: linear-gradient(160deg, #e9e6df, #cfcbc2); overflow: hidden; }
:root[data-theme="dark"] .lc-pic { background: linear-gradient(160deg, #2a2824, #1c1b18); }
.lc-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* No picture yet: the first system's colour */
.lc-ph {
  position: absolute; inset: 0;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 30%, #f6f2ea), color-mix(in srgb, var(--c) 80%, #2b241c));
}
.nolink .lc-pic { filter: saturate(.55); }

/* Staff labels on the picture */
.lc-badges { position: absolute; left: calc(var(--u) * .8); top: calc(var(--u) * .8); display: flex; gap: calc(var(--u) * .5); flex-wrap: wrap; }
.lc-badge { padding: calc(var(--u) * .25) calc(var(--u) * .9); border-radius: 99px; font-size: calc(var(--tu) * 1.2); background: var(--panel); color: var(--ink); }
.lc-badge.s-planned { background: #ece7dc; color: #5d574d; }
.lc-badge.s-building { background: #fff1d6; color: #8a5a00; }
.lc-badge.s-built { background: #e3e8ff; color: #2a3bd1; }
.lc-badge.s-reviewed { background: #dff2e6; color: #1f6b3a; }
.lc-badge.off { background: rgba(23, 21, 15, .75); color: #fff; }

.lc-body { display: flex; flex-direction: column; gap: calc(var(--u) * .35); padding: calc(var(--u) * 1) calc(var(--u) * 1.2) calc(var(--u) * 1.2); flex: 1; }
.lc-kick { font-size: calc(var(--tu) * 1.2); color: var(--muted); }
.lc-title { font-size: calc(var(--tu) * 1.6); font-weight: 700; line-height: 1.2; }
.lc-sum { font-size: calc(var(--tu) * 1.25); color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-tags { display: flex; flex-wrap: wrap; gap: calc(var(--u) * .4) calc(var(--u) * 1); margin-top: auto; padding-top: calc(var(--u) * .5); }
.lc-sys { display: inline-flex; align-items: center; gap: calc(var(--u) * .45); font-size: calc(var(--tu) * 1.2); color: var(--muted); }
.lc-sys i { width: calc(var(--u) * 1.1); height: calc(var(--u) * 1.1); border-radius: 50%; background: var(--c); }

/* Narrow screens (a phone, or a small Web Browser asset): rail above the cards */
@media (max-aspect-ratio: 1 / 1) {
  .lib-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .lib-rail { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; max-height: none; }
  .lib-rail .kicker { display: none; }
  .lib-list { display: flex; flex-direction: row; }
  .lib-chip { white-space: nowrap; }
  .lib-types { overflow-x: auto; }
}

/* ---- Staff: requests (js/request-dialog.js) -------------------------------------------- */
.lib-add { width: auto; flex: none; padding: 0 calc(var(--u) * 2); }
.lib-sub { grid-column: 1 / -1; padding: calc(var(--u) * .6) calc(var(--u) * .8) 0; font-size: calc(var(--tu) * 1.2); color: var(--faint); }

/* A card with its Requests strip underneath (staff) */
.lc-wrap { display: flex; flex-direction: column; }
.lc-wrap .lcard { flex: 1; }
.lc-wrap:has(.lc-req) .lcard { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.lc-req {
  min-height: calc(var(--u) * 4.4); padding: 0 calc(var(--u) * 1.2); text-align: left;
  border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--r) var(--r);
  background: var(--well); color: var(--muted); font-size: calc(var(--tu) * 1.25);
}
.lc-req:active { background: var(--press); }
.lc-asked { font-size: calc(var(--tu) * 1.2); color: var(--accent); line-height: 1.3; }

/* The dialog: wider than the kit's Save view dialog, centred on the full window */
.reqdlg { position: fixed; top: 50%; width: min(94vw, calc(var(--u) * 84)); max-height: 94vh; z-index: 9; }
.reqdlg > div:first-child { display: flex; align-items: baseline; gap: calc(var(--u) * 1.2); flex-wrap: wrap; }
.reqdlg #rqOpen { margin-left: auto; display: inline-flex; align-items: center; text-decoration: none; }
.reqdlg .seg { grid-auto-columns: auto; justify-content: start; }
.reqdlg .seg button { padding: 0 calc(var(--u) * 1.4); }
.rq-matches, .rq-chips { display: flex; flex-wrap: wrap; gap: calc(var(--u) * .6); align-items: center; }
.rq-matches .kicker { width: 100%; font-size: calc(var(--tu) * 1.25); }
.rq-chips .pill { display: inline-flex; align-items: center; gap: calc(var(--u) * .6); }
.rq-chips .pill i { width: calc(var(--u) * 1.3); height: calc(var(--u) * 1.3); border-radius: 50%; background: var(--c); }
.rq-new { display: flex; flex-direction: column; gap: calc(var(--u) * .7); }
.rq-list { list-style: none; margin: calc(var(--u) * .4) 0 0; padding: 0; display: flex; flex-direction: column; gap: calc(var(--u) * .6); }
.rq-list li { display: flex; justify-content: space-between; align-items: flex-start; gap: calc(var(--u) * 1); padding: calc(var(--u) * .9) calc(var(--u) * 1.1); border-radius: var(--r); background: var(--well); }
.rq-list li p { margin: calc(var(--u) * .3) 0 0; color: var(--muted); font-size: calc(var(--tu) * 1.3); }
.rq-list li.none { color: var(--muted); }

/* Deadlines (staff) */
.lc-badge.due { background: #ece7dc; color: #5d574d; }
.lc-badge.due.soon { background: #fff1d6; color: #8a5a00; }
.lc-badge.due.late { background: #fde3e0; color: #a3261a; }
.rq-list .due { font-size: calc(var(--tu) * 1.2); padding: 0 calc(var(--u) * .7); border-radius: 99px; background: #ece7dc; color: #5d574d; }
.rq-list .due.soon { background: #fff1d6; color: #8a5a00; }
.rq-list .due.late { background: #fde3e0; color: #a3261a; }
.rq-list .by { font-size: calc(var(--tu) * 1.2); color: var(--faint); }
.reqdlg input[type=date] { font: inherit; font-size: calc(var(--tu) * 1.5); color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: var(--r); padding: calc(var(--u) * 1) calc(var(--u) * 1.2); }
