/* doorhand UI — family design tokens (gatehand/queuehand pattern):
   dense, card-based, one badge system, light + dark themes.
   Composition bands (v1.3.0, Duo F1): Compact ≤640 (mobile-first,
   single column, cardified tables), Mid 641–1023 (the Duo
   unfolded composition: capped-track poster grids, shelf rail,
   list + detail side by side, real tables), Wide ≥1024
   (desktop-first: wide grids, side detail panel, real tables).
   Each band is composed for itself — none is another stretched.
   No breakpoint sits inside the 600–700 / 880–960 uncertainty
   intervals except the inherited 640 shell edge, whose crossing
   is non-destructive (pure CSS over the same server state). */
:root, [data-theme="dark"] {
  --bg: #10131a; --panel: #171b24; --panel2: #1e242f; --line: #2a3140;
  --text: #e6e9ef; --muted: #8b94a5; --accent: #5b9dff;
  --ok: #3fb96f; --warn: #e0a32e; --bad: #e5534b;
  /* Safe-area insets (v1.2.2, Duo F5): defined once, here;
     env() resolves to 0 on devices without cutouts, so
     non-notch rendering is unchanged. */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
[data-theme="light"] {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #eef0f3; --line: #d8dce2;
  --text: #1c2128; --muted: #5c6672; --accent: #0969da;
  --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif; }
header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: calc(10px + var(--sat));
  background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
  z-index: 20; }
.brand { font-weight: 700; font-size: 17px; }
.brand .ver { color: var(--muted); font-weight: 400; font-size: 12px; }
.head-right { margin-left: auto; display: flex; gap: 8px;
  align-items: center; flex-wrap: wrap; }
#main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
#main-nav button.active, .tabbar button.active {
  border-color: var(--accent); color: var(--accent); }
button { background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #fff;
  border-color: var(--accent); }
a { color: var(--accent); }
input, select, textarea { background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; max-width: 100%; }
main { padding: 16px; padding-bottom: calc(16px + var(--sab));
  max-width: 760px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; margin: 10px 0; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.list { display: grid; gap: 10px; }
.shelf { display: grid; gap: 12px; grid-template-columns: 1fr; }
.tile { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; }
.tile h3 { margin: 0 0 4px; font-size: 15px; }
.tile a.go { display: inline-block; margin-top: 8px; font-weight: 600; }
.pill { padding: 2px 10px; border-radius: 999px; font-size: 12px;
  background: var(--panel2); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); } .pill.bad { color: var(--bad); }
.pill.warn { color: var(--warn); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.bad { color: var(--bad); border-color: var(--bad); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.nav-badge { color: var(--bad); border-color: var(--bad);
  font-weight: 700; }
.muted { color: var(--muted); font-size: 12.5px; }
.error { color: var(--bad); font-size: 12.5px; }
.hint { display: block; color: var(--muted); font-size: 12px;
  margin-top: 3px; }
.hidden { display: none !important; }
h2 { font-size: 16px; margin: 18px 0 6px; }
h3 { font-size: 14px; margin: 12px 0 6px; }
.row-between { display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; }
.row-between h2, .row-between h3 { margin-right: auto; }
.form-stack { display: grid; gap: 12px; }
.form-stack label { display: grid; gap: 4px; font-size: 13px; }
.switch-row { display: flex !important; align-items: center; gap: 8px;
  flex-direction: row; }
.filters { display: flex; gap: 10px; flex-wrap: wrap;
  align-items: end; margin: 10px 0; }
.filters label { display: grid; gap: 4px; font-size: 12.5px; }
.tabbar { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center; margin: 10px 0; }
.search-bar input[type="search"] { flex: 1 1 200px; }
.seg { display: inline-flex; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; }
.seg label { padding: 6px 10px; font-size: 13px; cursor: pointer;
  background: var(--panel2); }
.seg label:has(input:checked) { background: var(--accent);
  color: #fff; }
.seg input { position: absolute; opacity: 0; }
.pin-code { font-size: 34px; font-weight: 700; letter-spacing: 6px;
  text-align: center; margin: 12px 0; }
.cover { width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 8px; background: var(--panel2); display: block; }
.cover-ph { width: 100%; aspect-ratio: 2 / 3; border-radius: 8px;
  background: var(--panel2); display: flex; align-items: center;
  justify-content: center; color: var(--muted); font-size: 12px;
  text-align: center; padding: 8px; }
.req-row { display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; }
.req-row .grow { flex: 1; min-width: 0; }
.req-row img { width: 40px; height: 60px; object-fit: cover;
  border-radius: 4px; }
/* Browse posters (v1.4.0, DB-3): poster-first tiles in every
   band — a poster composes its band, never stretches it; the
   detail panel's poster is capped the same way. */
.tile .cover, .tile .cover-ph { max-width: 210px;
  margin-bottom: 8px; }
.detail-cover { max-width: 320px; margin-bottom: 10px; }
.load-more { margin: 4px 0 14px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px;
  border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px; width: 100%; max-width: 480px;
  max-height: 88dvh; overflow: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px; }
.shown-secret { font-family: ui-monospace, monospace; font-size: 14px;
  word-break: break-all; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin: 8px 0; }
#toast { position: fixed; left: 50%; bottom: calc(22px + var(--sab));
  transform: translateX(-50%); background: var(--panel);
  border: 1px solid var(--accent); border-radius: 10px;
  padding: 8px 16px; z-index: 60; font-size: 13px; }
/* DLR-02: toast action button (View request) + the locate flash
   (DL-3) + tappable Ready tiles + issue-open controls. */
#toast .toast-action { margin-left: 10px; font-weight: 600; }
.ready-tile { cursor: pointer; }
.flash { animation: dl-flash 2.6s ease-out; }
@keyframes dl-flash {
  0%, 60% { outline: 3px solid var(--accent); outline-offset: 2px; }
  100% { outline: 3px solid transparent; outline-offset: 2px; } }
.issue-open { font: inherit; color: var(--accent);
  background: none; border: none; padding: 0; cursor: pointer;
  text-decoration: underline; }
#update-banner { display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; background: var(--panel2);
  border-bottom: 2px solid var(--warn); padding: 8px 16px;
  font-size: 13px; position: sticky; top: 0; z-index: 30; }
.books-layout { display: grid; gap: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px;
  font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* --- Diagnose (help) module ---------------------------------------
   Mobile-first: problem picker and guided steps stack in one
   column; the desktop block below widens the picker only. State
   is always carried by text (badge labels, "Selected" picker
   text, hazard/stop headings), never by colour alone. */
.problem-grid { display: grid; gap: 10px;
  grid-template-columns: 1fr; margin: 10px 0 14px; }
.problem-card { display: grid; gap: 2px; text-align: left;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; cursor: pointer; }
.problem-card input { position: absolute; opacity: 0; }
.problem-card strong { font-size: 14px; }
.problem-card .problem-sub { color: var(--muted); font-size: 12.5px; }
.problem-card .problem-picked { display: none; font-size: 12px;
  font-weight: 700; color: var(--accent); }
.problem-card:has(input:checked) { border-color: var(--accent);
  border-width: 2px; }
.problem-card:has(input:checked) .problem-picked { display: block; }
.help-case-row { cursor: pointer; width: 100%; text-align: left; }
.timeline-line { margin: 4px 0; font-size: 13px; }
.step-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; margin: 10px 0; }
.step-head { display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; margin-bottom: 8px; }
.step-ordinal { display: inline-block; padding: 2px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--accent); color: #fff; }
.step-instruction { font-size: 15px; font-weight: 600; margin: 6px 0; }
.step-why, .step-expected { margin: 6px 0; font-size: 13px; }
.step-why .step-label, .step-expected .step-label {
  font-weight: 700; color: var(--muted); }
.step-hazard { border: 2px solid var(--bad); border-radius: 8px;
  background: var(--panel2); padding: 10px 12px; margin: 10px 0;
  font-size: 13px; }
.step-hazard .step-label { font-weight: 700; color: var(--bad);
  text-transform: uppercase; font-size: 12px; letter-spacing: .4px; }
.step-stop { border: 2px solid var(--warn); border-radius: 8px;
  padding: 10px 12px; margin: 10px 0; font-size: 13px; }
.step-stop .step-label { font-weight: 700; color: var(--warn);
  text-transform: uppercase; font-size: 12px; letter-spacing: .4px; }
.step-stop ul { margin: 6px 0 0; padding-left: 18px; }
.step-ref { margin: 10px 0; }
.step-ref img { max-width: 100%; border-radius: 8px;
  border: 1px solid var(--line); display: block; }
.step-ref figcaption { color: var(--muted); font-size: 12.5px;
  margin-top: 4px; }
.step-choices { display: flex; gap: 8px; flex-wrap: wrap;
  margin: 10px 0; }
.step-choices button.selected { border-color: var(--accent);
  border-width: 2px; font-weight: 700; }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; }
.json-view { white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, monospace; font-size: 12px;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; max-height: 420px;
  overflow: auto; }

/* Compact composition: tables become stacked cards so admin
   rows stay readable one-handed; nothing is squeezed sideways. */
@media (max-width: 640px) {
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { background: var(--panel); border: 1px solid var(--line);
    border-radius: 12px; padding: 8px; margin: 8px 0; }
  td { border-bottom: none; padding: 3px 6px; }
  main { padding: 10px; padding-bottom: calc(10px + var(--sab)); }
}

/* Mid composition (641–1023, v1.3.0 Duo F1): composed for the
   unfolded band itself — two-up tile grids, capped covers (a
   cover never renders at full column width), the shelf as its
   240px rail, list + detail side by side, real tables (F7),
   Diagnose at the same rules as Wide. Both candidate Duo inner
   widths (890 / 951) land here and render identically. */
@media (min-width: 641px) and (max-width: 1023px) {
  main { max-width: 1023px; padding: 18px 22px;
    padding-bottom: calc(18px + var(--sab)); }
  .grid { grid-template-columns: repeat(2, 1fr); }
  #search-results { grid-template-columns: repeat(3, 1fr); }
  .shelf { display: flex; overflow-x: auto; padding-bottom: 6px; }
  .shelf .tile { flex: 0 0 240px; }
  .cover, .cover-ph { max-width: 260px; }
  .books-layout { grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start; }
  #work-detail { position: sticky; top: 76px; }
  #movie-detail { position: sticky; top: 76px; }
  .problem-grid { grid-template-columns: repeat(2, 1fr); }
  .step-card { max-width: 760px; }
  .form-stack { max-width: 640px; }
}

/* Wide composition (desktop-first at this width): wide hub,
   ready shelf as a horizontal rail, search + detail side by side,
   real tables, three-up tile grids. */
@media (min-width: 1024px) {
  main { max-width: 1280px; padding: 22px 28px;
    padding-bottom: calc(22px + var(--sab)); }
  .grid { grid-template-columns: repeat(3, 1fr); }
  #search-results { grid-template-columns: repeat(4, 1fr); }
  .tile .cover, .tile .cover-ph { max-width: 260px; }
  .shelf { display: flex; overflow-x: auto; padding-bottom: 6px; }
  .shelf .tile { flex: 0 0 240px; }
  .books-layout { grid-template-columns: minmax(0, 1fr) 400px;
    align-items: start; }
  #work-detail { position: sticky; top: 76px; }
  #movie-detail { position: sticky; top: 76px; }
  #view-admin .grid { grid-template-columns: repeat(2, 1fr); }
  .problem-grid { grid-template-columns: repeat(2, 1fr); }
  .step-card { max-width: 760px; }
  .form-stack { max-width: 640px; }
  #atab-settings .form-stack, #atab-policy .form-stack {
    max-width: 760px; }
}
