/* PDF Editor — paper on a light-table desk. One bold idea: in Edit text mode
   every editable line is pre-marked with a highlighter swipe. */
:root {
  --desk: #e3e7ec;
  --desk-deep: #d3d9e0;
  --paper: #ffffff;
  --ink: #1b2533;
  --muted: #5d6b7b;
  --line: #c9d0d8;
  --action: #0e6b6b;
  --action-deep: #0a5353;
  --action-soft: #e1efee;
  --marker: #ffe45c;
  --danger: #b4322a;
  --danger-soft: #fbe9e7;

  --r-control: 8px;
  --r-panel: 12px;
  --r-dialog: 16px;
  --shadow-paper: 0 1px 2px rgba(27, 37, 51, .08), 0 8px 28px rgba(27, 37, 51, .12);
  --shadow-float: 0 12px 40px rgba(27, 37, 51, .22);
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--desk);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--action) 55%, transparent); outline-offset: 2px; }

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--r-control);
  border: 1px solid transparent; background: transparent; cursor: pointer;
  font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--action); color: #fff; }
.btn.primary:hover { background: var(--action-deep); }
.btn.quiet { color: var(--ink); border-color: var(--line); background: var(--paper); }
.btn.quiet:hover { border-color: var(--muted); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--r-control); border: 0; background: transparent; cursor: pointer; color: var(--ink);
}
.icon-btn:hover:not(:disabled) { background: var(--desk); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line); position: relative; z-index: 30;
}
.brand {
  border: 0; background: none; cursor: pointer; padding: 4px 2px;
  font-size: 17px; font-weight: 700; letter-spacing: -.01em; color: var(--ink);
}
.brand::before {
  content: ""; display: inline-block; width: 14px; height: 18px; margin-right: 8px; vertical-align: -3px;
  background: var(--marker); border-radius: 2px; transform: skewX(-12deg);
}
.docname {
  min-width: 0; padding-left: 12px; border-left: 1px solid var(--line);
  color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.grow { flex: 1; }
.doc-actions { display: flex; align-items: center; gap: 6px; }
.chev { width: 16px; height: 16px; }

.menu { position: relative; }
.menu-list {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; z-index: 40;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-panel);
  box-shadow: var(--shadow-float); padding: 6px;
}
.menu.open .menu-list { display: block; }
.menu-list button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-radius: 6px;
  background: none; cursor: pointer;
}
.menu-list button:hover, .menu-list button:focus-visible { background: var(--action-soft); }
.menu-note { margin: 4px 12px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.menu-note:first-child { color: var(--ink); font-weight: 600; margin-top: 8px; }
.menu-note + button { margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 6px 6px; }
.account-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--action-soft); color: var(--action-deep); font-weight: 700;
}

/* busy indicator: a thin moving line under the top bar while the server works */
#busy {
  position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 60; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--action), transparent) 0 0 / 40% 100% no-repeat;
  opacity: 0; transition: opacity .2s;
}
body.is-busy #busy { opacity: 1; animation: busy 1s linear infinite; }
@keyframes busy { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* ---- home ---------------------------------------------------------------- */
.home { flex: 1; overflow: auto; padding: 40px 16px 64px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  max-width: 680px; margin: 0 auto; padding: 48px 24px; cursor: pointer;
  background: var(--paper); border: 2px dashed var(--line); border-radius: var(--r-dialog);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--action); background: var(--action-soft); }
.drop-icon { width: 40px; height: 40px; color: var(--action); margin-bottom: 4px; }
.drop-title { font-size: 21px; font-weight: 700; }
.drop-sub { color: var(--muted); margin-bottom: 12px; }

.doclist { max-width: 680px; margin: 40px auto 0; }
.doclist h2 { font-size: 17px; margin-bottom: 12px; }
.doclist ul { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: var(--r-panel); border: 1px solid var(--line); }
.doclist li { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; }
.doclist li + li { border-top: 1px solid var(--line); }
.doclist .open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; cursor: pointer; text-align: left; padding: 4px 0;
}
.doclist .open svg { color: var(--action); }
.doclist .open:hover .doc-title { text-decoration: underline; text-underline-offset: 3px; }
.doc-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { display: block; color: var(--muted); font-size: 13px; }
.doclist .icon-btn:hover { color: var(--danger); background: var(--danger-soft); }

/* ---- editor layout ----------------------------------------------------------- */
.editor { flex: 1; display: flex; min-height: 0; }
.pages {
  width: 168px; flex: none; overflow-y: auto; padding: 16px 14px;
  background: var(--paper); border-right: 1px solid var(--line);
}
.pages-title { font-size: 15px; }
.pages-hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
#thumbs { display: flex; flex-direction: column; gap: 14px; }
.thumb { position: relative; cursor: grab; }
.thumb img {
  display: block; width: 100%; background: #fff; border-radius: 2px;
  box-shadow: 0 0 0 1px var(--line); transition: box-shadow .15s;
}
.thumb.current img { box-shadow: 0 0 0 3px var(--action); }
.thumb.drag-over img { box-shadow: 0 0 0 3px var(--marker); }
.thumb .n { display: block; text-align: center; font-size: 13px; color: var(--muted); margin-top: 4px; }
.thumb .ops {
  position: absolute; right: 4px; top: 4px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s;
}
.thumb:hover .ops, .thumb:focus-within .ops { opacity: 1; }
@media (hover: none) { .thumb .ops { opacity: 1; } }
.thumb .ops button {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; border: 0; cursor: pointer;
  background: rgba(27, 37, 51, .82); color: #fff;
}
.thumb .ops svg { width: 16px; height: 16px; }
.thumb .ops button.del:hover { background: var(--danger); }

.workspace { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.toolbar {
  display: flex; align-items: center; gap: 4px; padding: 8px 16px; overflow-x: auto;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.tool {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; flex: none;
  border: 1px solid transparent; border-radius: var(--r-control); background: none; cursor: pointer; white-space: nowrap;
}
.tool:hover { background: var(--desk); }
.tool.active { background: var(--action); color: #fff; }
.tool.featured:not(.active) { background: linear-gradient(transparent 58%, var(--marker) 58%, var(--marker) 88%, transparent 88%); font-weight: 600; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; flex: none; }
.swatch {
  margin-left: 8px; width: 38px; height: 38px; border-radius: 50%; overflow: hidden; flex: none; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line), inset 0 0 0 3px #fff;
}
.swatch input { width: 64px; height: 64px; margin: -13px; border: 0; padding: 0; cursor: pointer; background: none; }

.hint { margin: 0; padding: 10px 16px 0; color: var(--muted); font-size: 14px; text-align: center; min-height: 31px; }
.stage { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 16px 24px 24px; }
.paper { position: relative; line-height: 0; box-shadow: var(--shadow-paper); background: #fff; }
#pageImg { display: block; max-width: min(100%, 900px); height: auto; }
#overlay { position: absolute; left: 0; top: 0; }
#overlay.marking { mix-blend-mode: multiply; }
.pager {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 0 12px; color: var(--muted);
}

/* unapplied changes bar */
.pending {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 18px; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; border-radius: 999px; box-shadow: var(--shadow-float);
  animation: rise .18s ease-out;
}
.pending .btn.quiet { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* form drawer */
.drawer {
  width: 320px; flex: none; overflow-y: auto; padding: 16px;
  background: var(--paper); border-left: 1px solid var(--line);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head h2 { font-size: 17px; }
.field { margin-bottom: 14px; }
.field label, .dialog-field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 16px 0; color: var(--muted); font-size: 14px; }
.check input { margin-top: 3px; }
.empty-note { color: var(--muted); }

/* ---- inputs ------------------------------------------------------------------- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-control);
  background: #fff;
}
input:focus, select:focus, textarea:focus { border-color: var(--action); outline: 3px solid var(--action-soft); }
textarea { resize: vertical; min-height: 84px; }
input[type="range"] { width: 100%; accent-color: var(--action); }

/* ---- dialog ------------------------------------------------------------------- */
dialog {
  width: min(460px, calc(100% - 32px)); padding: 0; border: 0; border-radius: var(--r-dialog);
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow-float);
}
dialog[open] { animation: pop .16s ease-out; }
dialog::backdrop { background: rgba(27, 37, 51, .45); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
#dialogForm { padding: 22px 22px 18px; }
#dialogTitle { font-size: 19px; margin-bottom: 14px; }
.dialog-field { margin-bottom: 14px; }
.dialog-help { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.dialog-row { display: flex; gap: 12px; }
.dialog-row > * { flex: 1; }
.dialog-error { min-height: 0; margin: 0; color: var(--danger); font-size: 14px; }
.dialog-error:not(:empty) { margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* the original text being changed, marked like on the page */
.original {
  margin: 0 0 14px; padding: 10px 12px; border-radius: var(--r-control); background: var(--desk);
  font-size: 14px; color: var(--muted);
}
.original mark { background: linear-gradient(transparent 50%, var(--marker) 50%); color: var(--ink); padding: 0 2px; }
.font-note { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* ---- toast -------------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); z-index: 70;
  max-width: min(520px, calc(100% - 32px)); padding: 12px 18px; border-radius: var(--r-panel);
  background: var(--danger); color: #fff; box-shadow: var(--shadow-float);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { background: var(--ink); }

/* ---- login -------------------------------------------------------------------- */
.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-card {
  display: flex; flex-direction: column; gap: 6px; width: min(380px, 100%);
  padding: 28px; background: var(--paper); border-radius: var(--r-dialog); box-shadow: var(--shadow-paper);
}
.login-card .brand { align-self: flex-start; font-size: 20px; margin-bottom: 4px; cursor: default; }
.login-card .lede { margin: 0 0 14px; color: var(--muted); }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.login-card .btn { margin-top: 16px; height: 44px; }
.login-card #error { color: var(--danger); min-height: 1.5em; margin: 6px 0 0; font-size: 14px; }
.tabs { display: flex; gap: 4px; background: var(--desk); border-radius: 10px; padding: 4px; margin-bottom: 4px; }
.tab { flex: 1; background: none; border: 0; padding: 8px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(27, 37, 51, .15); }
#confirmWrap { display: flex; flex-direction: column; gap: 6px; }

/* ---- small screens --------------------------------------------------------------- */
@media (max-width: 860px) {
  .pages { width: 104px; padding: 12px 8px; }
  .pages-hint { display: none; }
  .tool span { display: none; }
  .tool { padding: 0 10px; }
  .drawer { position: fixed; inset: 0 0 0 auto; width: min(340px, 100%); z-index: 50; box-shadow: var(--shadow-float); }
  .docname { display: none; }
}
@media (max-width: 560px) {
  .editor { flex-direction: column-reverse; }
  .pages { width: auto; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
  .pages-title { display: none; }
  #thumbs { flex-direction: row; }
  .thumb { width: 64px; flex: none; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .brand { font-size: 0; }
  .brand::before { margin-right: 0; }
  .doc-actions { gap: 2px; }
  .doc-actions .btn.quiet { padding: 0 10px; }
  .doc-actions .btn.primary { padding: 0 11px; }
  .btn .label { display: none; }
  .stage { padding: 12px; }
  .pending { bottom: 12px; padding-left: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
