/* Autumn Rooms look: white, black, electric blue for actions and selection, serif headings.
   Instrument Serif stands in for the licensed heading face until Autumn's web licence is confirmed. */
:root {
  --bg: #ffffff;
  --ink: #0a0a0a;
  --muted: #5f5f5f;
  --line: #e4e4e4;
  --soft: #f6f6f4;
  --blue: #0000e0;
  --blue-ink: #ffffff;
  --danger: #b00020;
  --ok: #0b6b2f;
  --radius: 10px;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.45; }
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--ink);
}
.brand { font-family: var(--serif); font-size: 28px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.brand span { color: var(--blue); }
.top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topnav { display: flex; gap: 4px; margin-right: auto; }
.topnav a { padding: 8px 10px; border-radius: 999px; font-weight: 600; font-size: 15px; color: var(--ink); text-decoration: none; }
.topnav a[aria-current="page"] { background: var(--ink); color: #fff; }
.topnav a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.venue-tag { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }
.pad { padding: 16px 0; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; margin: 0 0 8px; }
h1 { font-size: 40px; line-height: 1.05; }
h2 { font-size: 30px; }
h3 { font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--ink);
  background: var(--bg); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .cat-head:focus-visible, .doc:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 2px;
}
.linkish { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; text-decoration: underline; font-weight: 500; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.search { width: 100%; min-height: 50px; padding: 0 16px; border: 1.5px solid var(--ink); border-radius: 999px; font-size: 17px; background: var(--bg); }

.broken { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0 18px; padding: 14px 16px; border-radius: var(--radius); background: var(--soft); }
.broken strong { display: block; }

.cats { border-top: 1px solid var(--ink); }
.cat { border-bottom: 1px solid var(--line); }
.cat-head {
  width: 100%; display: flex; align-items: baseline; gap: 14px; padding: 16px 2px; background: none; border: 0; text-align: left; cursor: pointer;
}
.cat-num { font-size: 13px; font-weight: 700; color: var(--blue); min-width: 40px; font-variant-numeric: tabular-nums; }
.cat-name { font-family: var(--serif); font-size: 26px; line-height: 1.1; flex: 1; }
.cat-count { font-size: 14px; color: var(--muted); }
.cat-head[aria-expanded="true"] .cat-name { color: var(--blue); }
.cat-body { padding: 0 0 12px 54px; }
.sub { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 12px 0 4px; }
.empty { color: var(--muted); font-size: 15px; padding: 4px 0 8px; }

.doc { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 10px 8px; margin: 0 -8px; border-radius: 8px; text-decoration: none; color: var(--ink); background: none; border: 0; text-align: left; cursor: pointer; }
.doc:hover { background: var(--soft); }
.doc-no { font-size: 13px; font-weight: 700; min-width: 64px; padding-top: 2px; font-variant-numeric: tabular-nums; }
.doc-main { flex: 1; min-width: 0; }
.doc-title { font-weight: 600; }
.doc-desc { font-size: 15px; color: var(--muted); }
.doc-meta { font-size: 13px; color: var(--muted); white-space: nowrap; padding-top: 2px; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 14px 0; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 14px; }
input[type=text], input[type=email], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1.5px solid #bdbdbd; border-radius: 8px; background: var(--bg);
}
textarea { min-height: 120px; resize: vertical; }
input[type=file] { width: 100%; padding: 10px 0; }
.code-input { font-size: 30px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1.5px solid var(--line); border-radius: 8px; font-weight: 500; margin: 0; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--blue); background: #f2f2ff; }
.choice input { margin-top: 4px; accent-color: var(--blue); }
.err { color: var(--danger); font-weight: 600; margin: 10px 0 0; }

.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--ink); margin: 8px -16px 16px; padding: 0 16px; }
.tab { border: 0; background: none; padding: 12px 10px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--blue); border-color: var(--blue); }

.mrow { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.mrow .doc-main { min-width: 200px; }
.mrow-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.badge.archived { background: #fde8eb; color: var(--danger); }
.badge.scope { background: #ececff; color: var(--blue); }

table.list { width: 100%; border-collapse: collapse; font-size: 15px; }
table.list th, table.list td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.table-wrap { overflow-x: auto; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg { padding: 20px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

.center { max-width: 460px; margin: 40px auto; }
.foot { margin: 36px 0 12px; text-align: center; font-size: 14px; color: var(--muted); }

@media (max-width: 560px) {
  .brand { font-size: 24px; }
  h1 { font-size: 32px; }
  .cat-name { font-size: 22px; }
  .cat-body { padding-left: 0; }
  .doc-meta { display: none; }
  .broken { flex-direction: column; align-items: stretch; }
}
@media print { .top, .actions, .broken, .foot { display: none; } }

/* ---------- preview panel (tablet and desktop) ----------
   Right side when the screen is wider than tall, bottom half when upright. Phones open documents full screen. */
.pv-toggle { display: none; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1.5px solid var(--ink); background: var(--bg); font-size: 14px; font-weight: 600; cursor: pointer; }
.pv-toggle[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
@media (min-width: 700px) { .pv-toggle.show { display: inline-flex; } }

#pane { display: none; position: fixed; z-index: 4; background: var(--bg); flex-direction: column; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pane-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-title .doc-no { min-width: 0; margin-right: 8px; }
#pane iframe, #pane img { flex: 1; width: 100%; border: 0; background: #f2f2f2; }
#pane img { object-fit: contain; min-height: 0; }
.pane-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; color: var(--muted); }
.doc.selected { background: #ececff; }

@media (min-width: 700px) {
  body.previewing #pane { display: flex; }
  /* Wider than tall: laptop, or iPad held sideways. */
  @media (orientation: landscape) {
    body.previewing #pane { top: var(--top-h, 60px); right: 0; bottom: 0; width: 56vw; border-left: 1px solid var(--ink); }
    body.previewing main { margin: 0; max-width: none; width: 44vw; }
  }
  /* Upright iPad: document in the bottom half, list scrolls in the top half. */
  @media (orientation: portrait) {
    body.previewing #pane { left: 0; right: 0; bottom: 0; height: 52vh; border-top: 1px solid var(--ink); box-shadow: 0 -8px 24px rgba(0,0,0,.08); }
    body.previewing main { padding-bottom: calc(52vh + 16px); }
  }
}
@media print { #pane { display: none !important; } }

/* ---------- format tool ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tpl { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 16px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--bg); cursor: pointer; }
.tpl:hover, .tpl:focus-visible { border-color: var(--blue); outline: none; }
.blocks { display: grid; gap: 10px; margin: 16px 0 10px; }
.blk { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--bg); }
.blk-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.blk-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.blk-move { display: flex; gap: 4px; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 16px; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.blk textarea { min-height: 90px; }
.blk-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0 0 0 6px; font-weight: 500; font-size: 14px; }
.tbl-wrap { overflow-x: auto; }
.tbl-edit { border-collapse: collapse; width: 100%; }
.tbl-edit td { padding: 2px; }
.tbl-edit input { min-height: 38px; padding: 6px 8px; min-width: 110px; }
.tbl-edit input.th { font-weight: 700; background: var(--soft); }
.blk-photo { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 8px; }
.add-blocks { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 0; border-top: 1px dashed var(--line); }
.draft-note { margin-bottom: 4px; }

/* PDF pages drawn by PDF.js on iPad and iPhone */
.pdf-pages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: #e9e9e9; padding: 10px; }
.pdf-page { width: 100%; max-width: 900px; margin: 0 auto 10px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.pdf-page canvas { display: block; width: 100%; height: auto; }

/* Category one-liners */
.cat-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-desc { font-family: var(--sans); font-size: 14px; line-height: 1.35; color: var(--muted); }

.pdf-page-failed { display: flex; align-items: center; justify-content: center; }
