/* Light pastel theme. Chrome is pastel; the STAGE behind the slide is a
   neutral mid-light grey with no hue on purpose - a tinted surround shifts
   perceived stain colour (simultaneous contrast), and tissue is judged by
   colour. Status stays unmistakable: pastel fills with dark text, and the
   wrong-case banner also carries a solid red edge.
   Contrast, WCAG AA 4.5:1 minimum (computed, see git history / README):
     --fg #1f2433 on --bg #f6f7fb          14.4:1
     --muted #5b6275 on --panel-2 #eef1f8   5.4:1 (lowest pairing)
     --accent #3b5bab on --side #f4f2fb     5.8:1
     --danger-fg #7f1d16 on --danger #fde2e1 8.2:1
     --warn-fg #5e4200 on --warn #fff0c2    8.2:1
     --ok #1d6436 on --ok-bg #dff3e6        6.2:1
     primary #15305f on #bcd3fb             8.6:1 */
:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --side: #f4f2fb;       /* pastel lavender: slide list */
  --side-2: #f1f8f5;     /* pastel mint: details panel */
  --line: #d9deea;
  --fg: #1f2433;
  --muted: #5b6275;
  --accent: #3b5bab;
  --btn: #e8eefb;
  --btn-hover: #dbe5f8;
  --btn-on: #c9d8f5;
  --btn-on-line: #8fa9dc;
  --primary: #bcd3fb;
  --primary-hover: #a9c6f8;
  --primary-fg: #15305f;
  --danger: #fde2e1;
  --danger-fg: #7f1d16;
  --danger-edge: #c62828;
  --danger-chip: #f8c9c6;
  --warn: #fff0c2;
  --warn-fg: #5e4200;
  --warn-text: #8a5a00;
  --ok: #1d6436;
  --ok-bg: #dff3e6;
  --bad: #b3261e;
  --img-bg: #eceef2;     /* behind label/macro/thumbnail images: neutral */
  --stage: #d6d6d6;      /* neutral grey behind the slide: no hue, glass reads as glass */
  color-scheme: light;
}

* { box-sizing: border-box; }
/* Author `display` rules otherwise beat the hidden attribute, and a hidden
   "Wrong case risk" banner that still shows teaches people to ignore it. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--btn); border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 10px; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--btn-hover); }
button:disabled { opacity: .4; cursor: not-allowed; background: var(--btn); }
button[aria-pressed="true"], button.on { background: var(--btn-on); border-color: var(--btn-on-line); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.pad { padding: 12px; }
kbd { background: var(--btn); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 12px; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------------------------------------------------------- browser */
#browser { width: 300px; flex: none; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
#browser.collapsed { display: none; }
.browser-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.field { display: grid; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); }
select, input[type=search] { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; width: 100%; }
.case-banner { display: grid; gap: 4px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; }
.case-banner strong { font-size: 16px; }
.case-banner button { justify-self: start; margin-top: 4px; }
.admin-link { color: var(--accent); font-size: 13px; }
.lab-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
button.linkish { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; }
button.linkish:hover { color: var(--fg); text-decoration: underline; }
#crumbs { display: flex; flex-wrap: wrap; gap: 2px 4px; font-size: 13px; }
#crumbs button { background: none; border: 0; padding: 0 2px; color: var(--accent); }
#crumbs button:hover { text-decoration: underline; }
#crumbs .sep { color: var(--muted); }
.listing { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.listing li button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 0; padding: 6px 12px; }
.listing li button:hover { background: var(--btn-hover); }
.listing li button.current { background: var(--btn-on); }
.listing .thumb { width: 56px; height: 48px; flex: none; object-fit: contain; background: var(--img-bg); border-radius: 2px; }
.listing .folder-icon { width: 56px; text-align: center; font-size: 22px; flex: none; color: var(--muted); }
.listing .name { overflow-wrap: anywhere; font-size: 13px; }
.listing .kind { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------------------------------------------------------- main */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#slidebar { display: flex; align-items: center; gap: 12px; padding: 6px 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.icon { font-size: 16px; padding: 2px 8px; }
.ident { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1 1 260px; }
.ident-barcode { font-size: 18px; font-weight: 600; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ident-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: .05em; }
.chip.match { color: var(--ok); background: var(--ok-bg); border: 1px solid #9fd3b2; }
.chip.mismatch { background: var(--danger-chip); color: var(--danger-fg); border: 1px solid var(--danger-edge); }
.chip.unknown { background: var(--warn); color: var(--warn-fg); border: 1px solid #e6c56a; }
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mag-group { display: flex; }
.mag-group button { border-radius: 0; margin-left: -1px; padding: 4px 8px; }
.mag-group button:first-child { border-radius: 4px 0 0 4px; }
.mag-group button:last-child { border-radius: 0 4px 4px 0; }
.mag-readout { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

.banner { padding: 8px 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner-danger { background: var(--danger); color: var(--danger-fg); border-left: 6px solid var(--danger-edge); }
.banner-danger button { background: #fff; color: var(--danger-fg); border-color: var(--danger-edge); }
.banner-warn { background: var(--warn); color: var(--warn-fg); border-left: 6px solid #e0b43c; }

#stage { position: relative; flex: 1; min-height: 0; background: var(--stage); }
#viewer { position: absolute; inset: 0; }
#measure-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#measure-layer line { stroke: #00e5ff; stroke-width: 2; }
#measure-layer line.halo { stroke: #000; stroke-width: 4; stroke-opacity: .6; }
#measure-layer circle { fill: #00e5ff; }
#measure-layer text { fill: #fff; font: 600 13px "Segoe UI", system-ui, sans-serif; paint-order: stroke; stroke: #000; stroke-width: 3px; }
#stage.measuring, #stage.measuring .openseadragon-canvas { cursor: crosshair !important; }

#scalebar { position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,.9); color: var(--fg); border: 1px solid var(--line);
  padding: 4px 8px 3px; border-radius: 3px; font-size: 12px; pointer-events: none; }
#scalebar-bar { height: 4px; background: var(--fg); margin-bottom: 2px; }

.welcome { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--bg); }
.welcome h1 { font-weight: 600; margin: 0 0 8px; }
.welcome[hidden] { display: none; }
.loading { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(31,36,51,.12);
  padding: 6px 14px; border-radius: 4px; }

.sharpening { position: absolute; left: 12px; bottom: 44px; background: var(--warn); color: var(--warn-fg);
  padding: 3px 10px; border-radius: 3px; font-size: 12px; font-weight: 600; pointer-events: none; }

/* ---------------------------------------------------------- details */
#details { width: 300px; flex: none; background: var(--side-2); border-left: 1px solid var(--line); overflow-y: auto; }
#details section { padding: 10px 12px; border-bottom: 1px solid var(--line); }
#details h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
#details img { width: 100%; background: var(--img-bg); border-radius: 2px; display: block; }
#details img[hidden] { display: none; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv-small { font-size: 11px; grid-template-columns: 1fr; gap: 0; }
.kv-small dt { margin-top: 6px; }
summary { cursor: pointer; color: var(--muted); }

/* OpenSeadragon navigator */
.navigator { border: 1px solid var(--line) !important; background: var(--img-bg) !important; box-shadow: 0 2px 8px rgba(31,36,51,.15); }
.displayregion { border: 2px solid #00e5ff !important; }

@media (max-width: 900px) {
  #details { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; }
  #browser { position: absolute; left: 0; top: 0; bottom: 0; z-index: 21; width: min(300px, 85vw); }
}

/* ================================================= admin + access-code pages */
.small { font-size: 12px; }
.bad { color: var(--bad); }
.warn-text { color: var(--warn-text); }
button.primary { background: var(--primary); border-color: var(--btn-on-line); color: var(--primary-fg); font-weight: 600; }
button.primary:hover { background: var(--primary-hover); }
button.danger { border-color: var(--danger-edge); color: var(--danger-fg); }
button.danger:hover { background: var(--danger); }
code { font-family: Consolas, "Cascadia Mono", monospace; }

body.page { height: auto; min-height: 100%; }
.page-head { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.page-head h1 { margin: 4px 0 0; font-size: 20px; font-weight: 600; }
.page-body { max-width: 1100px; margin: 0 auto; padding: 16px 20px 40px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; }
.card h2 { margin: 0 0 8px; font-size: 16px; }
.step { margin-top: 16px; display: grid; gap: 8px; }
.step h3, .result h3 { margin: 0; font-size: 14px; }
.step > select, .step > input[type=search] { max-width: 480px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px 4px; font-size: 13px; }
.crumbs button { background: none; border: 0; padding: 0 2px; color: var(--accent); }
.crumbs .sep { color: var(--muted); }
.folder-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }
.folder-list button { width: 100%; text-align: left; border: 0; border-radius: 0; background: none; padding: 6px 10px; }
.folder-list button:hover { background: var(--panel-2); }
.form-grid { display: grid; grid-template-columns: 2fr 1.3fr 120px; gap: 10px; }
.form-grid input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; width: 100%; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.ack { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; background: var(--danger); color: var(--danger-fg); border: 1px solid var(--danger-edge); border-radius: 4px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; overflow-wrap: anywhere; }
table.grid a { color: var(--accent); }
tr.check-mismatch td, tr.check-error td { background: var(--danger); color: var(--danger-fg); }
tr.check-unknown td { background: var(--warn); color: var(--warn-fg); }
td.actions { white-space: nowrap; }
td.actions button + button { margin-left: 6px; }
.pill { display: inline-block; white-space: nowrap; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); }
.pill.active { color: var(--ok); background: var(--ok-bg); border-color: #9fd3b2; }
.pill.locked { background: var(--warn); color: var(--warn-fg); border-color: #e6c56a; }
.pill.revoked, .pill.expired { color: var(--muted); }
tr.status-revoked td, tr.status-expired td { color: var(--muted); }

.result { margin-top: 16px; padding: 12px 14px; background: var(--ok-bg); border: 1px solid #9fd3b2; border-radius: 6px; display: grid; gap: 8px; }
.secret { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; }
.secret span { color: var(--muted); }
.secret code { background: var(--panel-2); padding: 6px 8px; border-radius: 4px; overflow-wrap: anywhere; user-select: all; }
.secret code.code { font-size: 22px; letter-spacing: .12em; }
.result > button { justify-self: start; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; width: min(900px, 95vw); }
dialog::backdrop { background: rgba(31, 36, 51, .35); }
dialog h2 { font-size: 16px; margin-top: 0; }
dialog form { margin-top: 12px; text-align: right; }

.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 22px; display: grid; gap: 12px; }
.gate-card h1 { margin: 0; font-size: 20px; }
.gate-card p { margin: 0; }
.gate-card input { font-size: 22px; letter-spacing: .15em; text-transform: uppercase; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 8px; width: 100%; }
.gate-card button { padding: 8px; font-size: 15px; background: var(--primary); border-color: var(--btn-on-line); color: var(--primary-fg); font-weight: 600; }
.gate-msg { min-height: 1.4em; }
.gate-msg.bad { color: var(--bad); }
.who { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.who strong { color: var(--fg); }
.pw-form { display: grid; gap: 10px; }
.pw-form input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; width: 100%; }
.gate-card input[type=password], .gate-card #username { font-size: 15px; letter-spacing: normal; text-transform: none; text-align: left; }
.loose { background: var(--warn); color: var(--warn-fg); border: 1px solid #e6c56a; border-radius: 4px; padding: 8px 12px; }
.loose p { margin: 4px 0; }
.loose ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

.add-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.add-form .field { flex: 0 1 320px; }
.add-form input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; width: 100%; }
.page-head .crumbs .sep, .who .sep { color: var(--muted); margin: 0 4px; }

.folder-list .del-note { margin-left: 10px; }
