/* PageStudio — a light table for seforim.
   The sefer's own pages are the memorable thing; everything around them is
   quiet: cool grey desk, white panels, blue-black ink, tekhelet for the one
   thing that acts or is chosen. */
:root {
  --desk: #e6e8eb;
  --panel: #fbfbfc;
  --page: #ffffff;
  --ink: #1c2330;
  --ink-2: #4a5466;
  --ink-3: #7b8597;
  --rule: #d3d8df;
  --tekhelet: #1f4e8c;
  --tekhelet-soft: #e3ebf6;
  --warn: #9a3412;
  --ok: #276b45;
  --ui: 'Assistant', system-ui, sans-serif;
  --display: 'Frank Ruhl Libre', 'Assistant', serif;
  --r: 6px;
  --shadow-page: 0 1px 2px rgba(28, 35, 48, .10), 0 6px 18px rgba(28, 35, 48, .10);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--desk); color: var(--ink);
  font: 16px/1.5 var(--ui); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hide { display: none !important; }
:focus-visible { outline: 2px solid var(--tekhelet); outline-offset: 2px; }

/* ── top bar ─────────────────────────────────────────────── */
.top {
  height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.wordmark { font: 700 21px/1 var(--display); letter-spacing: .01em; margin: 0; }
.link { background: none; border: 0; padding: 4px 2px; cursor: pointer; color: inherit; }
.link.small { font-size: 14px; color: var(--ink-2); }
.link:hover { color: var(--tekhelet); }
.crumb { font: 500 18px/1.2 var(--display); color: var(--ink-2); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.top-meta { display: flex; gap: 12px; }
.status { font-size: 14px; color: var(--ink-3); }
.status.busy { color: var(--tekhelet); }

/* ── buttons and fields ─────────────────────────────────── */
.btn {
  border: 1px solid var(--rule); background: var(--page); border-radius: var(--r);
  padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 15px;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--tekhelet); border-color: var(--tekhelet); color: #fff; }
.btn.primary:hover { background: #193f73; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.big { padding: 12px 22px; font-size: 17px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  border: 1px solid var(--rule); border-radius: var(--r); background: var(--page);
  padding: 8px 10px; font-size: 16px; color: var(--ink); width: 100%;
}
textarea { resize: vertical; line-height: 1.7; }
.err { color: var(--warn); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ── sign in ─────────────────────────────────────────────── */
.veil { position: fixed; inset: 0; background: rgba(28, 35, 48, .35); display: grid;
  place-items: center; z-index: 50; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; }
.signin { width: min(360px, 100%); padding: 28px; display: grid; gap: 14px; }
.signin .wordmark { font-size: 28px; margin-bottom: 6px; }

/* ── the shelf ───────────────────────────────────────────── */
.shelf { max-width: 1080px; margin: 0 auto; padding: 40px 20px 80px; }
.shelf h1 { font: 700 34px/1.2 var(--display); margin: 0 0 6px; }
.shelf .lead { color: var(--ink-2); margin: 0 0 32px; max-width: 60ch; }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 28px 24px; }
.book { background: none; border: 0; padding: 0; cursor: pointer; text-align: start; }
.book .cover {
  aspect-ratio: 2 / 3; background: var(--page); box-shadow: var(--shadow-page);
  display: grid; place-items: center; overflow: hidden;
}
.book .cover img { width: 100%; height: 100%; object-fit: cover; }
.book .name { font: 600 17px/1.3 var(--display); margin-top: 10px; }
.book .when { font-size: 13px; color: var(--ink-3); }
.book:hover .cover { outline: 2px solid var(--tekhelet); outline-offset: 3px; }
.book.new .cover { background: transparent; box-shadow: none; border: 2px dashed var(--ink-3);
  color: var(--ink-2); font: 600 18px/1.3 var(--display); text-align: center; padding: 16px; }

/* ── setup ───────────────────────────────────────────────── */
.setup { max-width: 860px; margin: 0 auto; padding: 36px 20px 80px; }
.setup h1 { font: 700 30px/1.2 var(--display); margin: 0 0 4px; }
.setup .lead { color: var(--ink-2); margin: 0 0 28px; }
.part { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px;
  padding: 22px 24px; margin-bottom: 16px; display: grid; grid-template-columns: 36px 1fr; gap: 4px 14px; }
.part .n { font: 700 22px/1.3 var(--display); color: var(--tekhelet); }
.part h2 { font: 600 20px/1.3 var(--display); margin: 0; }
.part .body { grid-column: 2; display: grid; gap: 12px; margin-top: 8px; }
.part.locked { opacity: .55; }
.part.locked .body { pointer-events: none; }
.drop { border: 2px dashed var(--rule); border-radius: 8px; padding: 22px; text-align: center;
  color: var(--ink-2); cursor: pointer; }
.drop.over { border-color: var(--tekhelet); background: var(--tekhelet-soft); }
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 15px; }
.files li { display: flex; gap: 8px; }
.files .role { color: var(--ink-3); font-size: 13px; }
.parts-list { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 24px; font-size: 15px; }
.parts-list li { break-inside: avoid; padding: 2px 0; }
.parts-list .k { color: var(--ink-3); font-size: 13px; margin-inline-start: 6px; }
.looks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.look { background: none; border: 2px solid transparent; border-radius: 8px; padding: 6px; cursor: pointer; text-align: start; }
.look img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; background: var(--page); box-shadow: var(--shadow-page); display: block; }
.look .t { font-weight: 600; margin-top: 6px; }
.look .d { font-size: 13px; color: var(--ink-3); line-height: 1.35; }
.look[aria-pressed=true] { border-color: var(--tekhelet); background: var(--tekhelet-soft); }
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row > label { flex: 1 1 180px; }
.go { display: flex; justify-content: flex-end; gap: 12px; align-items: center; margin-top: 8px; }

/* ── building ────────────────────────────────────────────── */
.building { max-width: 640px; margin: 80px auto; padding: 0 20px; text-align: center; }
.building h1 { font: 700 28px/1.3 var(--display); margin: 0 0 8px; }
.bar { height: 6px; background: var(--rule); border-radius: 3px; overflow: hidden; margin: 24px 0 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--tekhelet); transition: width .6s ease; }
.saying { color: var(--ink-2); min-height: 1.5em; }

/* ── the book ────────────────────────────────────────────── */
.bookview { display: grid; grid-template-columns: 132px 1fr 360px; height: calc(100vh - 56px); }
.strip { overflow-y: auto; padding: 14px 10px; border-inline-end: 1px solid var(--rule); background: var(--panel); }
.strip button { display: block; width: 100%; background: none; border: 0; padding: 4px; cursor: pointer; }
.strip img { width: 100%; aspect-ratio: 2 / 3; background: var(--page); box-shadow: 0 1px 2px rgba(28, 35, 48, .15); display: block; }
.strip .pn { font-size: 12px; color: var(--ink-3); }
.strip button.here img { outline: 2px solid var(--tekhelet); outline-offset: 2px; }
.desk { overflow: auto; padding: 32px 24px 64px; position: relative; }
.spread { display: flex; justify-content: center; gap: 2px; margin: 0 auto 36px; direction: ltr; }
.pg { position: relative; background: var(--page); box-shadow: var(--shadow-page); cursor: text; }
.pg img { display: block; width: 100%; height: 100%; }
.pg .no { position: absolute; bottom: -22px; inset-inline: 0; text-align: center; font-size: 12px; color: var(--ink-3); }
.pg .mark { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: var(--tekhelet); box-shadow: 0 0 0 4px rgba(31, 78, 140, .2); pointer-events: none; }
.pg.blank { visibility: hidden; box-shadow: none; }
.zoom { position: sticky; top: 0; display: flex; justify-content: center; gap: 6px; margin: -16px 0 18px; z-index: 5; }
.zoom .btn { padding: 3px 10px; font-size: 14px; }

.side { background: var(--panel); border-inline-start: 1px solid var(--rule); display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--rule); }
.tabs button { flex: 1; background: none; border: 0; padding: 14px 8px 12px; cursor: pointer; font-weight: 600;
  color: var(--ink-2); border-bottom: 2px solid transparent; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--tekhelet); }
.pane { overflow-y: auto; padding: 18px 18px 40px; display: grid; gap: 16px; align-content: start; }
.pane h3 { font: 600 17px/1.3 var(--display); margin: 0; }
.hint { color: var(--ink-3); font-size: 14px; margin: 0; }
.group { display: grid; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.group:last-child { border-bottom: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--tekhelet); margin: 0; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper input { text-align: center; }
.stepper .btn { padding: 6px 10px; }
.para-text { font-family: 'Frank Ruhl Libre', serif; font-size: 17px; direction: rtl; }

.chat { display: grid; grid-template-rows: 1fr auto; min-height: 0; height: 100%; }
.msgs { overflow-y: auto; display: grid; gap: 10px; align-content: start; padding-bottom: 12px; }
.msg { padding: 10px 12px; border-radius: 8px; font-size: 15px; white-space: pre-wrap; }
.msg.me { background: var(--tekhelet-soft); }
.msg.ai { background: var(--page); border: 1px solid var(--rule); }
.ask { display: grid; gap: 8px; border-top: 1px solid var(--rule); padding-top: 12px; }

.toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; }
[dir=rtl] .toast { transform: translateX(50%); }
.toast.on { opacity: 1; }
.toast.bad { background: var(--warn); }

.menu { position: relative; }
.menu .items { position: absolute; top: calc(100% + 6px); inset-inline-end: 0; background: var(--panel);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 8px 24px rgba(28, 35, 48, .12);
  min-width: 220px; padding: 6px; display: grid; z-index: 30; }
.menu .items button, .menu .items a { text-align: start; background: none; border: 0; padding: 8px 10px;
  border-radius: 6px; cursor: pointer; color: var(--ink); text-decoration: none; font-size: 15px; }
.menu .items button:hover, .menu .items a:hover { background: var(--tekhelet-soft); }

@media (max-width: 1100px) {
  .bookview { grid-template-columns: 1fr 340px; }
  .strip { display: none; }
}
@media (max-width: 760px) {
  .bookview { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: auto; }
  .side { max-height: 60vh; }
  .parts-list { columns: 1; }
  .part { grid-template-columns: 1fr; }
  .part .body { grid-column: 1; }
  .top { padding: 0 12px; gap: 10px; }
  .top-meta { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
