/* Quillora — a quiet desk surface; documents sit on it as white paper sheets,
   amber "sign here" flags mark fields, a side panel holds status and actions. */
:root {
  --desk: #eceef3; --surface: #ffffff; --ink: #17213d; --muted: #5b6480; --line: #d6dae4;
  --accent: #2b3fa8; --accent-ink: #ffffff; --accent-soft: #e3e7fa;
  --flag: #f2b631; --flag-soft: rgba(242, 182, 49, 0.18); --flag-ink: #3a2a00;
  --ok: #1f7a4d; --ok-soft: #dff2e8; --danger: #b3261e; --danger-soft: #fbe3e1;
  --paper-shadow: 0 1px 2px rgba(23, 33, 61, 0.08), 0 6px 24px rgba(23, 33, 61, 0.08);
  --f-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --f-body: "Public Sans", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --f-script: "Mrs Saint Delafield", "Brush Script MT", cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #12151d; --surface: #1b1f2a; --ink: #e7e9f0; --muted: #9aa2b8; --line: #2d3344;
    --accent: #93a3ff; --accent-ink: #10142a; --accent-soft: #232a4a;
    --flag-soft: rgba(242, 182, 49, 0.22); --flag-ink: #2a1e00;
    --ok: #57c993; --ok-soft: #173326; --danger: #ff8a80; --danger-soft: #3a1c1b;
    --paper-shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--desk); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1180px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.bar { border-bottom: 1px solid var(--line); background: var(--surface); }
.bar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 14px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: inherit; }
.brand h1 { font-size: 24px; }
.brand .mark { font-family: var(--f-script); font-size: 34px; line-height: 0.6; color: var(--accent); }
.who { font-size: 13px; color: var(--muted); text-align: right; display: flex; gap: 8px; align-items: center; }
main.wrap { padding-block: 28px 64px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 14px; font-weight: 500; font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding-inline: 8px; }
.btn.ghost:hover:not(:disabled) { color: var(--ink); border-color: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.flagbtn[aria-pressed="true"] { background: var(--flag); border-color: var(--flag); color: var(--flag-ink); }
.btn.flagbtn.mine[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; }

.listhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.listhead h2 { font-size: 32px; }
.listhead p { color: var(--muted); max-width: 60ch; margin-top: 4px; }
.envlist { display: grid; gap: 10px; }
.env { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.env .ico { width: 44px; height: 54px; border-radius: 4px; background: var(--desk); border: 1px solid var(--line); position: relative; }
.env .ico::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: 9px; height: 7px; border-radius: 2px; background: var(--flag); }
.env.signed .ico::after { background: var(--ok); }
.env .meta { min-width: 0; display: grid; gap: 2px; }
.env .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env .t a { color: inherit; text-decoration: none; }
.env .t a:hover, .env .t a:focus-visible { color: var(--accent); text-decoration: underline; }
.env .s { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.env .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 4px 9px; border-radius: 8px; white-space: nowrap; width: fit-content; }
.chip.wait { background: var(--flag-soft); color: var(--ink); }
.chip.done { background: var(--ok-soft); color: var(--ok); }

.empty { border: 1.5px dashed var(--line); border-radius: 12px; padding: 40px 24px; text-align: center; color: var(--muted); background: var(--surface); }
.empty h3 { font-size: 22px; color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }
.notice { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; color: var(--muted); }
.notice strong { color: var(--ink); }

.login { max-width: 400px; margin: 8vh auto 0; }
/* Sign-in screen: logo and footnote centred over the panel */
body.signin .bar .wrap { justify-content: center; }
body.signin .who { display: none; }
body.signin .foot { text-align: center; max-width: 520px; margin-inline: auto; }
.acctbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
.acctbar .s { font-size: 13px; color: var(--muted); }
.meter { width: 140px; height: 6px; border-radius: 999px; background: var(--desk); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter span.full { background: var(--danger); }
.lockmsg { background: var(--accent-soft); border-color: var(--accent); }
.panel.locked > :not(#discardBtn) { opacity: .45; }
.panel.locked input, .panel.locked textarea, .panel.locked button { cursor: not-allowed; }
.panel.locked #discardBtn { cursor: pointer; }
.acctpage { max-width: 640px; display: grid; gap: 16px; }
.acctplan { display: grid; gap: 12px; }
.acctrow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.acctrow .s { font-size: 13px; color: var(--muted); }
.acctrow .meter { width: 200px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 320px)); gap: 16px; }
.plan .price { font-size: 15px; color: var(--muted); }
.plan .price strong { font-family: var(--f-display); font-size: 32px; color: var(--ink); }
.plan ul { display: grid; gap: 6px; padding-left: 18px; font-size: 14px; color: var(--muted); }
.plan.pick { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.drop { display: grid; place-items: center; gap: 10px; text-align: center; padding: 56px 24px; border: 1.5px dashed var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop h3 { font-size: 24px; }
.drop p { color: var(--muted); }
.sheet-ico { width: 56px; height: 70px; border: 1.5px solid var(--muted); border-radius: 4px; position: relative; margin-bottom: 6px; }
.sheet-ico::before { content: ""; position: absolute; left: 9px; right: 9px; top: 12px; height: 18px; background: repeating-linear-gradient(var(--line) 0 2px, transparent 2px 6px); }
.sheet-ico::after { content: ""; position: absolute; left: 9px; right: 14px; bottom: 10px; height: 9px; border-radius: 2px; background: var(--flag); }

.dochead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.dochead h2 { font-size: 26px; flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.docgrid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
/* Sticks beside the pages; scrolls on its own when taller than the window. */
.aside { position: sticky; top: 16px; display: grid; gap: 14px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; padding: 2px; margin: -2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px; }
.panel h3 { font-size: 19px; }
.panel .sub { color: var(--muted); font-size: 14px; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field { display: grid; gap: 6px; }
.field input[type="text"], .field input[type="email"], .field input[type="password"], .field input[type="date"], .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--desk); }
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.mono { font-family: var(--f-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { flex: 1; min-width: 0; font-family: var(--f-mono); font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--desk); }
.note { border-left: 3px solid var(--flag); padding: 2px 0 2px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.err { color: var(--danger); font-size: 14px; }
.okline { color: var(--ok); font-weight: 600; }
.sigslot { display: grid; place-items: center; min-height: 72px; border: 1.5px dashed var(--flag); background: var(--flag-soft); border-radius: 8px; cursor: pointer; padding: 8px; color: var(--ink); font-weight: 500; width: 100%; }
.sigslot img { max-height: 64px; max-width: 100%; }
.sigslot.has { border-style: solid; background: #fff; }
.confirmrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); }
.hint.live { color: var(--ink); background: var(--flag-soft); border-radius: 6px; padding: 6px 10px; }

.pages { display: grid; gap: 22px; }
.pagewrap { display: grid; gap: 6px; }
.pageno { font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.page { position: relative; background: #fff; box-shadow: var(--paper-shadow); line-height: 0; user-select: none; -webkit-user-select: none; }
.page canvas { width: 100%; height: auto; display: block; }
.page.placing { cursor: crosshair; }
.overlay { position: absolute; inset: 0; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* Fields sit on white paper in both themes, so their colors are fixed to the paper. */
.fld { position: absolute; line-height: 1.2; font-family: var(--f-body); border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.fld.edit { background: rgba(242, 182, 49, 0.22); border: 1.5px solid #e0a419; color: #4a3500; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; cursor: grab; touch-action: none; }
.fld.edit:active { cursor: grabbing; }
.fld.edit.mine { background: rgba(43, 63, 168, 0.10); border-color: #2b3fa8; color: #1b2a6b; }
.fld.sign { background: rgba(242, 182, 49, 0.25); border: 1.5px solid #e0a419; color: #4a3500; font-size: 11px; font-weight: 600; cursor: pointer; text-transform: uppercase; letter-spacing: .04em; }
.fld.sign.filled { background: rgba(43, 63, 168, 0.06); border: 1px dashed rgba(43, 63, 168, 0.5); text-transform: none; letter-spacing: 0; }
.fld img { max-width: 100%; max-height: 100%; pointer-events: none; }
.fld .dt { color: #17213d; font-weight: 500; white-space: nowrap; font-size: var(--fs, 12px); text-transform: none; letter-spacing: 0; }
.fld .tab { position: absolute; right: 100%; top: 50%; transform: translateY(-50%); margin-right: 4px; background: #f2b631; color: #3a2a00; font-size: 10px; font-weight: 700; padding: 3px 7px 3px 6px; clip-path: polygon(0 0, 82% 0, 100% 50%, 82% 100%, 0 100%); white-space: nowrap; letter-spacing: .04em; }
.fld .x { position: absolute; top: -10px; right: -10px; width: 20px; height: 20px; border-radius: 50%; border: none; background: #17213d; color: #fff; font-size: 13px; line-height: 20px; padding: 0; cursor: pointer; }
.fld .rs { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #17213d; border-radius: 2px; cursor: nwse-resize; touch-action: none; }

.modal { position: fixed; inset: 0; background: rgba(10, 14, 28, 0.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dialog { background: var(--surface); border-radius: 14px; width: min(560px, 100%); padding: 20px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; background: none; padding: 8px 12px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--accent); }
.pad { position: relative; background: #fff; border-radius: 8px; border: 1px solid var(--line); height: 180px; touch-action: none; }
.pad canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.pad .baseline { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1px solid #c9cdd8; pointer-events: none; }
.pad .baseline::before { content: "×"; position: absolute; left: -16px; bottom: -4px; color: #9aa0b0; font-size: 18px; line-height: 1; }
.typed { background: #fff; border-radius: 8px; border: 1px solid var(--line); height: 120px; display: grid; place-items: center; font-family: var(--f-script); font-size: 64px; color: #1b2a6b; overflow: hidden; white-space: nowrap; padding: 0 12px; }
.dialog .row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }
.foot { color: var(--muted); font-size: 12.5px; margin-top: 28px; }

@media (max-width: 860px) {
  .docgrid { grid-template-columns: minmax(0, 1fr); }
  .aside { position: static; order: -1; max-height: none; overflow: visible; }
}
@media (max-width: 620px) {
  .env { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .env .ico { display: none; }
  .env .acts { justify-content: flex-start; }
  .listhead h2 { font-size: 26px; }
  #whoEmail { display: none; }
  .fld .tab { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
