/* ---------------------------------------------------------------------------
   features.css — everything layered on the base app: sharing, guests, people,
   uploads and file previews (features.js); comments and page history
   (collab.js); templates, grouping, gallery previews, inline databases, file
   and embed blocks, read-only mode and public links. Loaded after styles.css
   and uses its variables.
--------------------------------------------------------------------------- */

/* ---- topbar actions --------------------------------------------------------------- */
.page-actions { flex: none; display: flex; align-items: center; gap: 2px; }
.page-actions:empty { display: none; }
.page-actions .tb { font-size: 14px; }
.cc-btn { gap: 3px; }
.cc-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cc-count:empty { display: none; }
.star { font-size: 16px; color: var(--faint); }
.star.on { color: #e9b10c; }
.share-btn { font-weight: 500; }
.public-tag { font-size: 12px; color: var(--muted); padding: 2px 8px; border-radius: 10px; background: var(--hover); }
.page-edited { margin-top: 6px; font-size: 12.5px; color: var(--faint); min-height: 1em; }
.page-edited:empty { display: none; }

/* public link: no sidebar, no page menu */
body.public .sidebar, body.public .menu-btn, body.public #page-menu { display: none !important; }

/* read-only: hide the affordances that would only error */
.page.ro .add-icon, .ro .add-prop-btn, .editor.ro .editor-tail { display: none; }
.editor.ro .blk-row { margin-left: 0; }
.editor.ro .blk-text { cursor: text; }
.prop-val.files-val { cursor: default; }
.prop-val.files-val:hover { background: none; }

/* ---- sidebar: favorites, recent ------------------------------------------------------- */
.sb-nav { display: flex; flex-direction: column; }
#sb-favs, #sb-recent { display: flex; flex-direction: column; padding: 0 6px; }
#sb-favs .sb-section, #sb-recent .sb-section { padding-left: 8px; padding-right: 4px; }
.trow.flat { gap: 6px; padding-left: 8px; text-decoration: none; }
button.sb-section.toggle { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
button.sb-section.toggle:hover { color: var(--muted); }
button.sb-section.toggle .tcaret { width: 16px; height: 16px; font-size: 11px; }

/* ---- generic bits used by the dialogs ----------------------------------------------------- */
.tag { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; margin-left: 6px; border-radius: 9px; background: var(--hover-2); color: var(--muted); font-size: 11px; font-weight: 500; vertical-align: middle; }
.tag.warn { background: #fdecc8; color: #6b4a14; }
.tag.bad { background: #ffe2dd; color: #8a2a24; }
.tag.good { background: #dbeddb; color: #1c3829; }
.avatar.big { width: 30px; height: 30px; font-size: 12px; }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--accent); font: inherit; font-size: 13.5px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.btn.ghost { background: none; box-shadow: none; }
.btn.ghost:hover { background: var(--hover); }
.danger-btn { color: var(--danger); }
.form-err { color: var(--danger); font-size: 13px; min-height: 1em; }
.form-err:empty { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 6px; }
.form-grid.two { grid-template-columns: 1fr 1.4fr; }
.link-row { display: flex; gap: 6px; align-items: center; }
.link-inp { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }

/* ---- modal ---------------------------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px;
  background: rgba(15, 15, 15, .35);
  animation: fade-in .15s ease-out;
}
.modal {
  width: min(560px, 100%);
  max-height: 84vh;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow-pop);
}
.modal-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 14px 16px 8px; }
.modal-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-x { border: 0; background: none; width: 28px; height: 28px; border-radius: 6px; font-size: 20px; color: var(--muted); cursor: pointer; }
.modal-x:hover { background: var(--hover); }
.modal-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 16px 16px; }

/* ---- share dialog ------------------------------------------------------------------------ */
.share-sec { padding: 10px 0; border-top: 1px solid var(--border); }
.share-sec:first-child { border-top: 0; padding-top: 2px; }
.sec-title { font-size: 12px; font-weight: 600; color: var(--faint); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.add-row { display: flex; gap: 6px; }
.add-row > .inp { flex: 1; min-width: 0; }
.level-sel { width: auto; flex: none; }
.pick-results { display: flex; flex-direction: column; margin-top: 4px; }
.pick-item { display: flex; align-items: center; gap: 8px; padding: 6px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; font: inherit; font-size: 14px; }
.pick-item:hover { background: var(--hover); }
.pi-name { font-weight: 500; }
.pi-email { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.acc-list { display: flex; flex-direction: column; gap: 2px; }
.acc-row { display: flex; align-items: center; gap: 10px; padding: 6px 2px; }
.acc-row.inherited { opacity: .8; }
.acc-who { flex: 1; min-width: 0; }
.acc-name { font-weight: 500; font-size: 14px; }
.acc-email { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-email a { color: inherit; }
.acc-level { font-size: 13px; color: var(--muted); }
.invite-form { display: flex; flex-direction: column; gap: 6px; }
.invite-box { margin-top: 8px; padding: 10px; border-radius: 8px; background: var(--soft-bg); display: flex; flex-direction: column; gap: 8px; }
.ib-msg { font-size: 13px; color: var(--muted); }
.switch-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.switch-row input { margin-top: 3px; }
.check-row { display: flex; align-items: center; gap: 6px; margin: 10px 0 8px; font-size: 13.5px; }

/* ---- people page ---------------------------------------------------------------------------- */
.people-page { width: 100%; max-width: 860px; margin: 0 auto; padding: 40px var(--pad-x) 80px; }
.people-head { display: flex; align-items: center; gap: 12px; }
.people-head .page-title { flex: 1; }
.page-title.static { font-size: 32px; font-weight: 700; margin: 0; }
.people-sec { display: flex; align-items: center; gap: 8px; margin: 28px 0 8px; font-size: 15px; }
.guest-list, .staff-list { display: flex; flex-direction: column; gap: 6px; }
.guest-card { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.guest-card.off { opacity: .6; }
.guest-main { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.guest-meta { text-align: right; font-size: 12.5px; }
.guest-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 64px; }
.guest-pages { margin: 8px 0 0 64px; display: flex; flex-direction: column; gap: 2px; }
.gp-row { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.gp-row a { color: var(--text); }
.card-ish { padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; }
.staff-row { display: flex; align-items: center; gap: 10px; padding: 4px 2px; font-size: 14px; }
#invite { position: fixed; inset: 0; z-index: 950; background: var(--soft-bg); }
.invite-note { font-size: 14px; color: var(--muted); line-height: 1.5; }

/* ---- uploads ------------------------------------------------------------------------------ */
.files-thumbs { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 0; }
.td .files-thumbs { flex-wrap: nowrap; overflow: hidden; }
.fthumb { position: relative; flex: none; padding: 0; border: 0; border-radius: 4px; background: var(--soft-bg); overflow: hidden; cursor: zoom-in; }
.fthumb img, .fthumb video { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.fs-sm .fthumb.img, .fs-sm .fthumb.vid { width: 26px; height: 26px; }
.fs-md .fthumb.img, .fs-md .fthumb.vid { width: 64px; height: 64px; }
.fs-lg .fthumb.img, .fs-lg .fthumb.vid { width: 96px; height: 96px; border-radius: 6px; }
.fthumb.chip { height: 22px; padding: 0 6px; font-size: 12.5px; cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fplay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); pointer-events: none; }
.fs-lg .fplay, .gcover .fplay { font-size: 22px; }
.files-prop { display: flex; flex-direction: column; gap: 6px; min-width: 0; width: 100%; padding: 2px 0; }
.files-prop.in-pop { width: 340px; max-width: calc(100vw - 48px); }
.files-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.files-actions .hint { font-size: 12px; color: var(--faint); }
.drop-files { outline: 2px dashed rgba(35, 131, 226, .6); outline-offset: 2px; background: rgba(35, 131, 226, .04); border-radius: 6px; }
.up-list { display: flex; flex-direction: column; gap: 6px; }
.up-row { padding: 6px 8px; border-radius: 6px; background: var(--soft-bg); font-size: 12.5px; }
.up-row.err { background: #ffe2dd; }
.up-row.in-editor { margin: 4px 0; }
.up-top { display: flex; align-items: center; gap: 8px; }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.up-x { border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0 2px; }
.up-x:hover { color: var(--text); }
.up-err { margin-top: 4px; color: #8a2a24; }
.up-bar { height: 4px; margin-top: 5px; border-radius: 2px; background: rgba(55, 53, 47, .1); overflow: hidden; }
.up-fill { height: 100%; background: var(--accent); transition: width .2s; }
.files-pop { padding: 2px; }

/* ---- lightbox -------------------------------------------------------------------------------- */
.lightbox { position: fixed; inset: 0; z-index: 1100; background: rgba(15, 15, 15, .92); display: flex; flex-direction: column; }
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px 56px; }
.lb-media { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; background: #000; }
.lb-file { color: #eee; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.lb-file-ico { font-size: 48px; }
.lb-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: #eee; font-size: 13.5px; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-size { color: #aaa; }
.lb-btn { border: 0; border-radius: 6px; padding: 6px 10px; background: rgba(255, 255, 255, .12); color: #fff; font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.lb-btn:hover { background: rgba(255, 255, 255, .22); }
.lb-btn.danger { color: #ffb4ab; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .08); color: #fff; font-size: 30px; cursor: pointer; }
.lb-nav:hover { background: rgba(255, 255, 255, .18); }
.lb-nav.prev { left: 6px; }
.lb-nav.next { right: 6px; }

/* ---- blocks: heading 4, file, embed ---------------------------------------------------------------- */
.blk.t-heading_4 { margin-top: 10px; }
.t-heading_4 > .blk-row .blk-text { font-size: 1.08em; font-weight: 600; line-height: 1.35; }
.t-heading_4 > .blk-row > .blk-handle { margin-top: 3px; }
.media img { cursor: zoom-in; }
.file-blk {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px;
  background: var(--soft-bg); border: 1px solid var(--border);
  max-width: 100%; font-size: 14px;
}
.file-blk:hover { background: #f1f0ed; }
.fb-ico { flex: none; font-size: 18px; }
.fb-name { flex: 1; min-width: 0; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-name:hover { text-decoration: underline; }
.fb-size { flex: none; color: var(--faint); font-size: 12.5px; }
.fb-dl { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; color: var(--muted); text-decoration: none; }
.fb-dl:hover { background: var(--hover-2); color: var(--text); }
.file-body .blk-cap { margin-top: 4px; }
.embed-frame { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 70vh; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--soft-bg); }
.embed-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.embed-open { display: inline-block; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.editor.drop-files { outline-offset: 6px; }
.ro-empty { min-height: 40px; }

/* ---- inline databases ---------------------------------------------------------------------- */
.inline-db { margin: 8px 0 12px; min-width: 0; }
.inline-db-title { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 2px; font-size: 18px; font-weight: 600; color: var(--text); text-decoration: none; }
.inline-db-title:hover { text-decoration: underline; text-decoration-color: rgba(55, 53, 47, .3); text-underline-offset: 3px; }
.dbv.inline { display: flex; flex-direction: column; }
.dbv.inline .dbv-body { flex: none; }
.dbv.inline .dbv-body > .tbl-scroll { max-height: 440px; min-height: 0; }
.dbv.inline .board-scroll, .dbv.inline .gallery-view, .dbv.inline .list-view, .dbv.inline .cal { max-height: 560px; }
.dbv.inline .dbv-bar { border-bottom: 1px solid var(--border); }

/* ---- database bar: count, New ▾ ---------------------------------------------------------------- */
.dbv-count { font-size: 12px; color: var(--faint); padding: 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dbv-count:empty { display: none; }
.new-split { display: inline-flex; margin-left: 6px; }
.dbv-tools .new-split .btn.primary { margin-left: 0; }
.new-split .new-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.new-split .new-more { border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 0 6px; border-left: 1px solid rgba(255, 255, 255, .35); }
.tpl-item { display: flex; align-items: center; }
.tpl-item .menu-item { flex: 1; min-width: 0; }
.tpl-more { flex: none; width: 26px; height: 26px; border: 0; border-radius: 4px; background: none; color: var(--faint); cursor: pointer; }
.tpl-more:hover { background: var(--hover-2); color: var(--text); }
.template-banner { margin: 18px 0 -8px; padding: 8px 12px; border-radius: 6px; background: #fdecc8; color: #6b4a14; font-size: 13.5px; }
.two-way { display: flex; flex-direction: column; gap: 6px; }

/* ---- grouping (table and list) ---------------------------------------------------------------- */
.grp-head { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 4px; position: sticky; left: 0; font-size: 14px; }
.grp-head .count { color: var(--faint); font-size: 12.5px; }
.grp-head .tcaret { border: 0; background: none; cursor: pointer; border-radius: 4px; }
.grp-head .tcaret:hover { background: var(--hover-2); }
.grp-add { width: 22px; height: 22px; border: 0; border-radius: 4px; background: none; color: var(--faint); font-size: 16px; cursor: pointer; opacity: 0; }
.grp-head:hover .grp-add { opacity: 1; }
.grp-add:hover { background: var(--hover-2); color: var(--text); }
.grp-label { font-weight: 500; }
.tbody.grouped .tr { position: relative; }
.tbody.grouped .grp-head { border-bottom: 1px solid var(--border); margin-top: 10px; }
.grp-list { display: flex; flex-direction: column; margin-bottom: 8px; }
.list-view .grp-head { margin-top: 8px; }

/* ---- gallery previews -------------------------------------------------------------------------- */
.card.gcard:has(> .gcover)::before { display: none; }
.gcover { position: relative; flex: none; margin: 0 !important; height: 150px; background: var(--soft-bg); border-bottom: 1px solid var(--border); overflow: hidden; }
.gcover img, .gcover video { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.gcover.empty { background: linear-gradient(135deg, #f4f3f0, #ecebe7); }
.gcover.broken::after { content: "Preview unavailable"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 12px; background: var(--soft-bg); }
.gallery.size-small { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.gallery.size-small .gcover { height: 110px; }
.gallery.size-large { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.gallery.size-large .gcover { height: 220px; }

/* ---- side panel (comments) ------------------------------------------------------------------------ */
.side-panel {
  position: fixed; top: var(--nav-h); right: 0; bottom: 0; z-index: 70;
  width: min(380px, 100vw);
  display: flex; flex-direction: column;
  background: #fff;
  box-shadow: rgba(15, 15, 15, .06) 0 0 0 1px, rgba(15, 15, 15, .14) -8px 0 32px;
  transform: translateX(104%);
  transition: transform .2s cubic-bezier(.2, .8, .3, 1);
}
.side-panel.in { transform: none; }
.sp-head { flex: none; display: flex; align-items: center; gap: 4px; height: 46px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--border); }
.sp-title { font-weight: 600; font-size: 14.5px; }
.cm-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 10px; }
.cm-thread { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }
.cm-thread.resolved { background: var(--soft-bg); }
.cm-resolved { font-size: 12px; color: #1c3829; }
.cm { display: flex; flex-direction: column; gap: 2px; }
.cm + .cm { padding-left: 14px; border-left: 2px solid var(--border); }
.cm-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.cm-author { font-weight: 600; }
.cm-time { color: var(--faint); font-size: 12px; }
.cm-more { border: 0; background: none; width: 24px; height: 22px; border-radius: 4px; color: var(--faint); cursor: pointer; opacity: 0; }
.cm:hover .cm-more { opacity: 1; }
.cm-more:hover { background: var(--hover-2); color: var(--text); }
.cm-body { font-size: 14px; line-height: 1.45; padding-left: 28px; word-break: break-word; }
.cm-thread-actions { display: flex; gap: 10px; padding-left: 28px; }
.cm-compose { display: flex; align-items: flex-end; gap: 6px; }
.side-panel > .cm-compose { flex: none; padding: 10px 12px 14px; border-top: 1px solid var(--border); }
.cm-compose.reply { padding-left: 28px; }
.cm-compose > .inp, .cm-compose > textarea { flex: 1; min-width: 0; resize: none; font: inherit; font-size: 14px; line-height: 1.4; }
.cm-compose > .form-actions { flex-basis: 100%; }
.cm-compose:has(> .form-actions) { flex-wrap: wrap; }
.cm-empty { text-align: center; padding: 24px 8px; }

/* ---- page history -------------------------------------------------------------------------------- */
.modal.history-modal { width: min(1040px, 100%); height: 84vh; }
.history-modal .modal-body { padding: 0; display: flex; }
.hist { flex: 1; min-height: 0; display: flex; }
.hist-side { flex: none; width: 280px; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.hist-tabs { flex: none; display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.hist-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.hist-item { display: block; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; text-align: left; font: inherit; cursor: pointer; }
button.hist-item:hover { background: var(--hover); }
.hist-item.on { background: var(--accent-soft); }
.hist-item.current { cursor: default; border-bottom: 1px solid var(--border); border-radius: 0; margin-bottom: 4px; }
.hist-item.act { cursor: default; }
.hi-when { font-size: 13.5px; font-weight: 500; }
.hi-who, .hi-what { font-size: 12.5px; color: var(--muted); word-break: break-word; }
.hist-preview { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hist-preview > .sb-note { padding: 24px; }
.hp-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.hp-when { font-weight: 600; }
.hp-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 32px 40px; }
.hp-scroll .page-title.static { font-size: 28px; margin-bottom: 10px; }
.hp-doc { max-width: none; padding: 0; }

/* ---- mobile ------------------------------------------------------------------------------------------ */
@media (max-width: 800px) {
  .page-actions .share-btn { padding: 0 6px; }
  .side-panel { top: 0; width: 100vw; z-index: 85; }
  .modal-back { padding: 0; align-items: stretch; }
  .modal { max-height: none; height: 100%; width: 100%; border-radius: 0; }
  .modal.history-modal { height: 100%; }
  .hist { flex-direction: column; }
  .hist-side { width: 100%; max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .hp-scroll { padding: 12px 16px 32px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
  .guest-actions, .guest-pages { margin-left: 0; }
  .people-page { padding-top: 24px; }
  .lb-stage { padding: 8px; }
  .lb-nav { display: none; }
  .gcover { height: 120px; }
  .grp-add, .cm-more { opacity: 1; }
  .embed-frame { aspect-ratio: 3 / 4; }
}
