/* Desk, Readers and Reader page. Uses the tokens and components in styles.css. */

/* ---------- Shared by these screens ---------- */
.print-only { display: none; }

/* Loan buttons are the main thing staff tap here, so give them the full touch size. */
.desk .loan .btn, .student .loan .btn { min-height: var(--tap); }

/* The sky strip beside a page heading (Readers): open sky between the title and its action. */
.page-head.has-sky { flex-wrap: nowrap; align-items: center; gap: var(--space-4) var(--space-6); }
.head-sky { flex: 1 1 auto; min-width: 0; }
.readers .head-sky .sky { height: 104px; }

/* A child's Houston in the corner of their tile or card (the picture is hidden from screen
   readers; the stage is in the tile's text). Its frame is .hawk-pic, in nest.css. */
.reader-head { display: flex; align-items: flex-start; gap: var(--space-3); }
.reader-who { flex: 1 1 auto; min-width: 0; display: grid; gap: var(--space-2); align-content: start; }

/* Short book lists: lend search, good fits, scan matches. */
.desk-books { display: grid; gap: var(--space-2); }
/* Titles that match the search but are all out: the child can join the waiting list. */
.desk-out-head { margin-top: var(--space-3); font-size: var(--text-sm); font-weight: 700; color: var(--ink-2); }
.desk-book {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-3); align-items: center;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.desk-book-main { display: grid; gap: 2px; min-width: 0; }
.desk-note { font-size: var(--text-sm); color: var(--muted); text-wrap: pretty; }
.desk-side-note { font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }

/* ---------- Desk ---------- */
/* Top to bottom: a short head, the scan bar (the hero), then one workspace: the class's
   readers on the left, the chosen reader on the right. Block flow (not grid) so the scan
   bar can stay stuck while the page scrolls. --bar is the scan bar's height, which the
   sticky reader pane sits under. */
.desk { --bar: 124px; }
.desk.is-holding { --bar: 198px; }
.desk > * + * { margin-top: var(--space-5); }

.desk-head { align-items: baseline; }
.desk .desk-date { margin: 0; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* The scan bar: the one raised surface on the page, solid so it can stay stuck over the list. */
.desk-bar {
  display: grid; gap: var(--space-3); padding: var(--space-4) var(--space-5) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--edge); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}
.desk-scan { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-2) var(--space-3); }
.desk-scan label { font-weight: 700; font-size: var(--text-sm); color: var(--ink-2); }
.desk-ready {
  justify-self: end; display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: 700; color: var(--muted);
}
.desk-ready-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sand-400); }
.desk-ready-on { display: none; }
.desk-scan:focus-within .desk-ready { color: var(--good); }
.desk-scan:focus-within .desk-ready-dot { background: var(--good); box-shadow: 0 0 0 4px var(--good-tint); }
.desk-scan:focus-within .desk-ready-on { display: inline; }
.desk-scan:focus-within .desk-ready-off { display: none; }
.desk-scan-field { position: relative; grid-column: 1 / -1; grid-row: 2; gap: var(--space-3); }
.desk-scan-icon { position: absolute; left: var(--space-4); top: 50%; translate: 0 -50%; display: grid; color: var(--accent); pointer-events: none; }
/* The hero field: the one input with an accent edge at rest, a size up from the family. */
.desk-scan input[type="text"] {
  min-height: 56px; padding-left: 56px;
  border-color: var(--accent); border-radius: var(--radius-md);
  box-shadow: 0 0 0 3px var(--accent-soft);
  font-size: var(--text-xl); font-weight: 600; letter-spacing: 0.005em;
}
.desk-scan input[type="text"]:hover { border-color: var(--accent-strong); }
.desk-scan input[type="text"]:focus-visible { box-shadow: 0 0 0 4px var(--focus-halo); }
.desk-scan input[type="text"]::placeholder { font-weight: 400; }
.desk-scan .btn-primary { min-height: 56px; padding: 0 var(--space-8); border-radius: var(--radius-md); font-size: var(--text-lg); }

/* A scanned book waiting for a reader: held in the bar itself. */
.desk-hand {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--ink);
  font-weight: 600;
}
.desk-hand p { flex: 1 1 auto; min-width: 0; }
.desk-hand-copy { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--accent-ink); }

.desk-result { position: relative; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-color: var(--accent); }
.desk-result::before {
  content: ""; position: absolute; left: -1px; top: var(--space-4); bottom: var(--space-4); width: 4px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0; background: var(--accent);
}
.desk-result-body { flex: 1 1 auto; min-width: 0; display: grid; gap: var(--space-3); }
.desk-outs { display: grid; gap: var(--space-2); }
.desk-out {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.desk-out p { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); }

/* Classes: a row of full-height pills, one per class; the chosen one is tinted. */
.desk-classes { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.desk-classes .chip { min-height: var(--control); padding: 0 var(--space-4); font-size: 0.9375rem; }

/* The workspace: one solid surface in two panes. Tiles inside it keep their edge and drop
   their shadow, like anything nested in a panel. */
.desk-layout {
  display: grid;
  background: var(--surface);
  border: 1px solid var(--edge); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.desk-class { display: grid; gap: var(--space-4); align-content: start; padding: var(--space-5); min-width: 0; }
.desk-class-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-1) var(--space-3);
}
.desk-class-head h2 { text-wrap: balance; }
.desk-sky .sky { height: 96px; }
.desk-today { gap: var(--space-2); }
.desk-today-chip.is-alert, .desk-today-chip.is-alert .chip-count { color: var(--alert); }
.desk-today-chip.is-alert { border-color: var(--alert-line); }
.desk-none { padding: var(--space-6) 0; text-align: center; }
.desk-class .reader { width: 100%; height: 100%; box-shadow: none; }
.desk-class .reader:hover { background: var(--surface-hover); box-shadow: none; }
.desk-class .reader[aria-pressed="true"], .desk-class .reader[aria-pressed="true"]:hover {
  background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent);
}
.desk-flag { font-weight: 700; }
.desk-class .reader-line > .muted { white-space: nowrap; }
/* One dot for each book a child may have out: filled in soaring blue when it is. */
.reader-dots { display: inline-flex; gap: var(--space-1); }
.reader-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.reader-dot.is-out { background: var(--brand); border-color: var(--brand); }

/* The chosen reader: the right-hand pane of the workspace, on the quieter plane. */
.desk-child {
  display: grid; gap: var(--space-5); align-content: start; scroll-margin-top: 150px;
  border: 0; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--surface-quiet);
  box-shadow: none;
}
.desk-child-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.desk-child h2 { font-size: var(--text-2xl); }
.desk-child h2 a { color: var(--ink); text-decoration: none; }
.desk-child h2 a:hover { text-decoration: underline; }
/* Picture and words side by side, so the books out stay high in the pane. */
.desk-child-hawk .hawk-card { background: var(--surface); border-radius: var(--radius-md); }
.desk-child-hawk .hawk-card-stage-houston { background: var(--sun-surface); }
.desk-child-hawk .hawk-caption { flex-basis: 140px; }
.desk-sub { display: grid; gap: var(--space-3); }
.desk-child.is-empty { justify-items: center; align-content: center; gap: var(--space-2); min-height: 260px; text-align: center; }
.desk-hint-icon { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--space-2); border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.desk-hint { text-align: center; max-width: 30ch; text-wrap: balance; }

@media (max-width: 959px) {
  .desk-child.is-empty { display: none; }
}

@media (min-width: 721px) {
  .desk-bar { position: sticky; top: var(--space-3); z-index: 5; }
  /* One line keeps the bar's height steady; only a long title is shortened. */
  .desk-hand p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .desk-hand-title {
    display: inline-block; max-width: 30ch; vertical-align: bottom;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
}

@media (min-width: 960px) {
  .desk-layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); align-items: start; }
  .desk-child {
    position: sticky; top: calc(var(--space-3) + var(--bar) + var(--space-3));
    max-height: calc(100dvh - var(--bar) - var(--space-8)); overflow-y: auto;
    border-top: 0; border-left: 1px solid var(--line);
    border-radius: 0 calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0;
    align-self: stretch;
  }
}

@media (max-width: 720px) {
  .desk > * + * { margin-top: var(--space-4); }
  .desk-bar { padding: var(--space-3); border-radius: var(--radius-md); }
  .desk-scan input[type="text"] { min-height: 52px; padding-left: 48px; font-size: var(--text-lg); border-radius: var(--radius-sm); }
  .desk-scan-icon { left: var(--space-3); }
  .desk-scan .btn-primary { min-height: 52px; padding: 0 var(--space-5); border-radius: var(--radius-sm); }
  .desk-layout { border-radius: var(--radius-md); }
  .desk-class { padding: var(--space-3); gap: var(--space-3); }
  .desk-child { border-radius: 0 0 calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px); }
}

@media (prefers-reduced-motion: no-preference) {
  .desk-scan:focus-within .desk-ready-dot { animation: desk-ready 2.4s var(--ease-in-out) infinite; }
}
@keyframes desk-ready { 50% { box-shadow: 0 0 0 7px transparent; } }

/* ---------- Readers ---------- */
.readers { display: grid; gap: var(--space-4); }
/* Six tiles: six across, or three by two. Never five and one left over. */
.readers-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.readers-stats .stat { min-height: var(--tap); }
/* Cards / Table: two halves of one control, the same height as the fields beside it. */
.readers-view {
  display: flex; flex: none; padding: 3px; gap: 2px;
  border: 1px solid var(--control-line); border-radius: var(--radius-sm);
  background: var(--surface-sunk);
}
.readers-view .chip {
  min-height: calc(var(--control) - 8px); padding: 0 var(--space-4);
  border: 0; border-radius: 7px; background: transparent; box-shadow: none;
  font-size: 0.9375rem; color: var(--ink-2);
}
.readers-view .chip:hover { background: var(--surface-hover); color: var(--ink); }
.readers-view .chip[aria-pressed="true"] {
  background: var(--surface); color: var(--accent-ink);
  box-shadow: var(--shadow-0), 0 0 0 1px var(--line);
}
/* The count sits on the open sky, so it carries full ink weight. */
.readers-count { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; text-shadow: var(--ground-halo); }

.readers-card { cursor: auto; gap: var(--space-3); }
.readers-card:hover { border-color: var(--edge); box-shadow: var(--shadow-1); }
.readers-card .reader-name { color: var(--ink); text-decoration: none; }
.readers-card .reader-name:hover { text-decoration: underline; }
.readers-card .reader-who { gap: 2px; }
.readers-class { font-size: var(--text-sm); }
.readers-loans { display: grid; gap: var(--space-3); padding: 2px 0; }
.readers-loans li { display: grid; gap: var(--space-1); justify-items: start; }
.readers-book { font-weight: 650; line-height: var(--leading-snug); color: var(--ink); text-decoration: none; overflow-wrap: anywhere; text-wrap: pretty; }
.readers-book:hover { text-decoration: underline; }
.readers-facts { font-size: var(--text-xs); line-height: 1.45; color: var(--muted); text-wrap: pretty; }

.readers-hawk { white-space: nowrap; }
.readers-hawk .hawk-pic { display: inline-grid; vertical-align: middle; margin-right: var(--space-2); }
.readers-hawk-text { display: inline-grid; vertical-align: middle; line-height: 1.3; font-size: var(--text-sm); }

.readers-table th[scope="row"] { font-weight: 700; white-space: nowrap; }
.readers-table td:nth-child(2) { white-space: nowrap; }
.readers-table th[scope="row"] a { color: var(--ink); }
.readers-cell-loans { display: grid; gap: 6px; }
.readers-cell-loans li { display: grid; gap: 2px; }
.readers-loan-facts {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: var(--text-xs); color: var(--muted);
}

/* ---------- Reader page ---------- */
.student { display: grid; gap: var(--space-5); }

/* The top of the page is for the child: one solid surface holding their name and, beside
   it, their Houston. The hawk card inside gives up its own edge: the hero is its frame. */
.student-hero {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-5) var(--space-10);
  padding: var(--space-6) var(--space-8);
  background: var(--surface);
  border: 1px solid var(--edge); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.student-hero-name { flex: 0 1 auto; display: grid; gap: var(--space-2); min-width: min(100%, 220px); }
.student-hero h1 { font-size: clamp(2rem, 4.5vw, 3rem); line-height: 1.08; overflow-wrap: anywhere; text-wrap: balance; }
.student-class { color: var(--muted); font-weight: 600; font-size: var(--text-lg); }
.student-hero .hawk-card {
  flex: 1 1 420px; flex-wrap: wrap; min-width: 0; gap: var(--space-4) var(--space-8);
  padding: 0 0 0 var(--space-10); background: none; border: 0; border-left: 1px solid var(--line); border-radius: 0;
}
.student-hero .hawk-caption { flex: 1 1 220px; max-width: 460px; }
.student-hero .hawk-stage-name { font-size: var(--text-2xl); }
.student-hero .hawk-line { font-size: var(--text-md); }
.student-head { align-items: center; }
.student-head .reader-line { color: var(--ink); font-size: 0.9375rem; text-shadow: var(--ground-halo); }
.student-head .reader-line .muted { color: var(--ink-2); }
.student-head .reader-line .range, .student-head .reader-line .pill, .student-head .reader-line .level { text-shadow: none; }
.student-notes {
  white-space: pre-line; max-width: 70ch; padding: var(--space-3) var(--space-4);
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius-sm);
  box-shadow: inset 3px 0 0 var(--line-strong);
}
.student-grid {
  display: grid; gap: var(--space-4); align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
.student-section { display: grid; gap: var(--space-3); }
.student-section .panel-head { margin-bottom: 0; }
.student-wide { grid-column: 1 / -1; }

/* Reading range over time: one bar per recorded range on a shared AR level scale. */
.rh { display: grid; gap: 6px; }
.rh-row { display: grid; grid-template-columns: 8.5em minmax(0, 1fr) 4.5em; gap: var(--space-3); align-items: center; }
.rh-when { display: grid; line-height: 1.3; }
.rh-date { font-size: var(--text-sm); font-weight: 650; font-variant-numeric: tabular-nums; }
.rh-source { font-size: var(--text-xs); color: var(--muted); }
.rh-track, .rh-axis { display: block; overflow: visible; }
.rh-grid { stroke: var(--line); stroke-width: 1; }
.rh-bar { fill: var(--brand-tint); stroke: var(--brand); stroke-width: 1.5; }
.is-latest .rh-bar { fill: var(--brand); }
.rh-range { font-size: var(--text-sm); font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.rh-axis { font-size: 12px; fill: var(--muted); }
.rh-axis-label { font-size: var(--text-2xs); color: var(--muted); text-align: right; }

/* Dialog parts (dialogs sit outside .student). */
.st-suggest { display: grid; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-sunk); }
.st-suggest-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-2) var(--space-3); }
.st-suggest-row .field { flex: 1 1 200px; }
.st-suggest-row .btn { margin-top: 25px; }

@media (max-width: 1040px) {
  .readers-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  /* Stacked: the name above, the Houston card below, the rule between them level. */
  .student-hero { padding: var(--space-5); gap: var(--space-4); }
  .student-hero .hawk-card { flex-basis: 100%; padding: var(--space-4) 0 0; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .page-head.has-sky { flex-wrap: wrap; }
  .head-sky { flex-basis: 100%; order: 3; }
  .readers .head-sky .sky { height: 88px; }
  /* The title keeps Print beside it; the stat tiles go three across so the list starts sooner. */
  .readers .page-head > div:first-child { flex: 1 1 0; min-width: 0; }
  .readers-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
  .readers-stats .stat { padding: var(--space-3); }
  .readers-stats .stat-number { font-size: var(--text-2xl); }
  .readers-stats .stat-label { font-size: var(--text-xs); }
  .readers-view { flex: 1 1 100%; }
  .readers-view .chip { flex: 1 1 0; justify-content: center; }
  .student-hero { padding: var(--space-4); border-radius: var(--radius-md); }
  /* A phone shows the large picture a size down, so the words beside it keep their room. */
  .student-hero .hawk-card-art { --hawk-pad: 10px; --hawk-corner: 28px; }
  .student-hero .hawk-card-art > .hawk { width: 100px; height: 100px; }
  .student-hero .hawk-card { gap: var(--space-4); }
  .student-hero .hawk-caption { flex: 1 1 150px; gap: var(--space-2); }
  .student-hero .hawk-stage-name { font-size: var(--text-xl); }
  .student-hero .hawk-line { font-size: var(--text-sm); }
  /* Narrow tiles: a smaller Houston leaves room for the name. */
  .reader .hawk-pic { --hawk-pad: 4px; --hawk-corner: 12px; }
  .reader .hawk-pic > .hawk { width: 36px; height: 36px; }
  .reader-head { gap: var(--space-2); }
  .toolbar .field-narrow { flex: 1 1 140px; }
}

@media (max-width: 480px) {
  /* A reader's card holds too much to share a phone's width. */
  .readers .reader-grid { grid-template-columns: 1fr; }
  .rh-row { grid-template-columns: 6.5em minmax(0, 1fr) 4em; gap: var(--space-2); }
  .student-actions { width: 100%; }
  .student-actions .btn { flex: 1 1 auto; }
}

/* ---------- Print: the Readers table as a class list ---------- */
@media print {
  .print-only { display: block; }
  .readers .stats, .readers-view, .student .stats { display: none !important; }
  .readers-print { font-weight: 700; margin-bottom: 4pt; }
  .readers .table-wrap { overflow: visible; border: 0; }
  .readers-table { font-size: 10pt; }
  .readers-table th, .readers-table td { padding: 4pt 6pt; border-bottom: 1px solid #bbb; }
  .readers-table tr { break-inside: avoid; }
  .readers-table thead { display: table-header-group; }
  /* Houston's pictures stay on screen; the printed list keeps the stage in words. */
  .readers .hawk-pic { display: none !important; }
  .readers-table th { white-space: normal; }
  .readers .reader-grid { grid-template-columns: repeat(2, 1fr); }
  .readers .reader { break-inside: avoid; }
  /* Tinted pills and badges print as plain words. */
  .readers .pill, .readers .level, .readers .level-tag, .readers .range {
    min-height: 0; padding: 0; border: 0; background: none; color: inherit;
  }
  .readers .level-tag::after { content: " "; }
}

/* On a touch screen the two halves are full touch height, and a card's title link is
   easier to hit: its target reaches 12px above and below the words. */
@media (pointer: coarse) {
  a.reader-name, .readers-book { position: relative; }
  a.reader-name::after, .readers-book::after { content: ""; position: absolute; inset: -12px 0; }
  .readers-view { padding: 0; gap: 0; overflow: hidden; }
  .readers-view .chip { min-height: var(--tap); border-radius: 0; }
}
