:root {
  --bg: #fff6f9; --surface: #ffffff; --text: #2a1720; --muted: #75606a; --line: #f0d6e0;
  --brand: #c2185b; --brand-ink: #ffffff; --brand-soft: #fde4ee; --soft: #fdf0f5;
  --ok: #1d7a46; --ok-bg: #e5f4ea; --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #a3242a; --bad-bg: #fde8e8;
  --year: #7b1fa2; --year-bg: #f3e5f8;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1116; --surface: #251920; --text: #f4e8ee; --muted: #b59eaa; --line: #3d2a33;
    --brand: #f48fb1; --brand-ink: #2a0f1a; --brand-soft: #3d1f2c; --soft: #2a1c23;
    --ok: #6fd39a; --ok-bg: #16301f; --warn: #f0c060; --warn-bg: #33290f; --bad: #f08a8f; --bad-bg: #3a1a1c;
    --year: #e1a6f0; --year-bg: #36203d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1116; --surface: #251920; --text: #f4e8ee; --muted: #b59eaa; --line: #3d2a33;
  --brand: #f48fb1; --brand-ink: #2a0f1a; --brand-soft: #3d1f2c; --soft: #2a1c23;
  --ok: #6fd39a; --ok-bg: #16301f; --warn: #f0c060; --warn-bg: #33290f; --bad: #f08a8f; --bad-bg: #3a1a1c;
  --year: #e1a6f0; --year-bg: #36203d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Arial Hebrew", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
a { color: var(--brand); }
.top {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 8px;
  background: var(--brand); color: var(--brand-ink); padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
}
.top h1 { font-size: 18px; margin: 0; }
.top h1 a { color: inherit; text-decoration: none; }
.top-space { flex: 1; }
.icon-btn { background: none; color: var(--brand-ink); font-size: 22px; padding: 4px 10px; min-height: 40px; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 48px; }

input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
button {
  border: 0; border-radius: 12px; padding: 12px 16px; background: var(--brand); color: var(--brand-ink);
  font-weight: 600; cursor: pointer; min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.small, .small { font-size: 14px; }
button.ghost.small { min-height: 36px; padding: 6px 12px; }
button.link, a.link { background: none; color: var(--brand); padding: 6px 0; min-height: 0; font-weight: 500; text-align: start; }
form { display: flex; gap: 8px; margin: 8px 0; }
form.stack, .stack { flex-direction: column; display: flex; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; }

/* sidebar */
#nav {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: 30; width: min(320px, 86vw); overflow-y: auto;
  background: var(--surface); border-inline-start: 1px solid var(--line); padding: calc(env(safe-area-inset-top) + 12px) 8px 24px;
  transform: translateX(105%); transition: transform .2s ease; box-shadow: -8px 0 24px rgba(0,0,0,.12);
}
#nav.open { transform: none; }
#nav-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(30, 5, 15, .35); }
.nav-item {
  display: block; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600;
  cursor: pointer; list-style: none; width: 100%; text-align: start; background: none; min-height: 0;
}
.nav-item:hover, .tree a:hover { background: var(--soft); }
summary.nav-item::-webkit-details-marker { display: none; }
#nav hr { border: 0; border-top: 1px solid var(--line); margin: 8px 4px; }
.tree { padding-inline-start: 14px; }
.tree a { display: block; padding: 7px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 15px; }
.tree summary { list-style: none; cursor: pointer; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary a::before { content: "▸ "; color: var(--muted); }
.tree details[open] > summary a::before { content: "▾ "; }
.count { color: var(--muted); font-weight: 400; font-size: 13px; }
#admin-count:not(:empty) { background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 0 7px; font-weight: 700; }

/* search */
.search { position: sticky; top: 56px; z-index: 4; background: var(--bg); padding: 6px 0; margin: 0; }
.search input, .search textarea { border: 2px solid var(--brand-soft); }
.search textarea { resize: none; line-height: 1.4; min-height: 64px; }
.search input::placeholder, .search textarea::placeholder { color: var(--brand); opacity: .8; }
.search button { align-self: stretch; }
.note { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.status { margin: 12px 0; }
.syn { margin: 6px 0; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; align-items: center; }
.chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--text); border-radius: 999px;
  padding: 4px 12px; min-height: 32px; font-weight: 500; font-size: 14px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card.soft { background: var(--soft); }
.t-he { font-size: 17px; font-weight: 700; margin: 0; line-height: 1.35; }
.t-en { font-size: 14px; color: var(--muted); text-align: right; unicode-bidi: plaintext; margin-top: 1px; }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
bdi { unicode-bidi: isolate; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; align-items: center; }
.badge { font-size: 12.5px; font-weight: 600; border-radius: 6px; padding: 2px 8px; }
.badge.year { background: var(--year-bg); color: var(--year); font-size: 13.5px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.mine { background: var(--brand-soft); color: var(--brand); }
.badge.plain { background: var(--soft); color: var(--muted); }

.snippet { white-space: pre-wrap; font-size: 14.5px; margin: 8px 0; unicode-bidi: plaintext; }
.snippet mark { background: var(--warn-bg); color: inherit; border-radius: 3px; }
.thumb {
  display: block; width: 100%; height: 190px; object-fit: cover; object-position: top;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: zoom-in;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.row .grow, .grow { flex: 1; }
.fb { display: flex; gap: 8px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; flex-wrap: wrap; }
.fb button { flex: 1; min-width: 120px; }
.fb .done, .done { color: var(--ok); font-size: 14px; padding: 8px 0; }

.question { border-color: var(--warn); background: var(--warn-bg); }
.question h3 { margin: 0 0 6px; font-size: 15px; }
.question button { display: block; width: 100%; text-align: start; margin: 6px 0; background: var(--surface); color: var(--text); border: 1px solid var(--line); font-weight: 500; }

/* generated answer */
.answer { border: 2px solid var(--brand); background: linear-gradient(var(--surface), var(--soft)); }
.answer.pending { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.answer .warning { font-size: 13px; color: var(--warn); margin-bottom: 8px; }
.answer .text { white-space: pre-wrap; unicode-bidi: plaintext; }
.cite {
  display: inline-flex; align-items: center; justify-content: center; min-height: 0; min-width: 22px; height: 22px;
  padding: 0 6px; margin: 0 2px; border-radius: 999px; font-size: 12.5px; vertical-align: 2px;
}
.sources { margin: 10px 0 0; padding-inline-start: 22px; font-size: 14px; }
.sources li { margin: 2px 0; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* lists */
.view-title { font-size: 21px; margin: 8px 0; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
h3 { font-size: 16px; margin: 20px 0 6px; }
.doc-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; display: flex; flex-direction: column; gap: 4px; }
.doc .doc-open { background: none; color: var(--text); text-align: start; font-weight: 400; padding: 8px 10px; border-radius: 10px; display: block; width: 100%; }
.doc button.doc-open:hover { background: var(--soft); }
.doc > .ghost.small, .doc > label, .doc > .row { margin: 0 10px 8px; }
.link-item { text-decoration: none; padding: 12px 14px; color: var(--text); }
.link-item .url { font-size: 13px; color: var(--brand); text-align: right; }

/* upload */
.file-pick { border: 2px dashed var(--brand); border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer; background: var(--soft); }
.file-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-pick span { font-weight: 600; color: var(--brand); word-break: break-all; }
.choice { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin: 0; background: var(--surface); }
.choice legend { padding: 0 6px; font-weight: 600; }
.choice label { flex-direction: row; align-items: flex-start; gap: 10px; padding: 6px 0; }
.choice input { width: auto; margin-top: 4px; accent-color: var(--brand); }
.notice { font-size: 13.5px; background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 0; }
.bar { height: 10px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; margin-top: 16px; }
.bar > div { height: 100%; width: 0; background: var(--brand); transition: width .3s; }

/* page viewer */
#viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; align-items: center; gap: 10px; background: var(--surface); color: var(--text);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
}
.viewer-bar button { background: none; color: var(--text); font-size: 20px; padding: 6px 10px; }
.viewer-bar a { color: var(--brand); white-space: nowrap; font-size: 14px; }
.v-title { flex: 1; min-width: 0; }
.v-title #v-doc { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; background: #333; }
.viewer-body img { display: block; width: 100%; height: auto; background: #fff; }
.viewer-nav { display: flex; gap: 8px; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); background: var(--surface); }
.viewer-nav button { flex: 1; }
