/* ── CSS Custom Properties ── Light (default) ─────────────── */
:root {
    --bg-app:      #f5f5f3;
    --bg-surface:  #ffffff;
    --bg-elevated: #fafaf9;
    --bg-hover:    #f0f0ee;
    --bg-active:   #ebebea;

    --text-primary: #1a1a18;
    --text-muted:   #5F5E5A;
    --text-faint:   #888780;
    --text-whisper: #B4B2A9;

    --border:        rgba(0,0,0,0.10);
    --border-subtle: rgba(0,0,0,0.06);
    --border-input:  rgba(0,0,0,0.15);

    --shadow-card:  0 1px 3px rgba(0,0,0,0.05);
    --shadow-modal: 0 8px 40px rgba(0,0,0,0.18);
    --overlay:      rgba(0,0,0,0.45);

    --accent:               #378ADD;
    --accent-green:         #3B6D11;
    --accent-green-bg:      #eaf3de;
    --accent-green-border:  #c0dd97;
    --accent-green-hover:   #d4eab0;

    --topbar-bg:      #2C2C2A;
    --topbar-border:  rgba(255,255,255,0.06);
    --topbar-text:    #B4B2A9;
    --topbar-pill-bg: rgba(255,255,255,0.07);

    --thumb-bg:       #e2e2de;
    --page-border:    rgba(0,0,0,0.22);
}

/* ── Dark theme ───────────────────────────────────────────── */
html.dark {
    --bg-app:      #111110;
    --bg-surface:  #1a1a18;
    --bg-elevated: #212120;
    --bg-hover:    #282826;
    --bg-active:   #2f2f2d;

    --text-primary: #e5e3dc;
    --text-muted:   #9c9a93;
    --text-faint:   #6c6a64;
    --text-whisper: #484642;

    --border:        rgba(255,255,255,0.07);
    --border-subtle: rgba(255,255,255,0.04);
    --border-input:  rgba(255,255,255,0.12);

    --shadow-card:  0 1px 3px rgba(0,0,0,0.4);
    --shadow-modal: 0 8px 40px rgba(0,0,0,0.7);
    --overlay:      rgba(0,0,0,0.70);

    --accent:               #5ba3eb;
    --accent-green:         #6aaa2a;
    --accent-green-bg:      #1a2e0a;
    --accent-green-border:  #3a5c15;
    --accent-green-hover:   #253f10;

    --topbar-bg:      #0d0d0c;
    --topbar-border:  rgba(255,255,255,0.06);
    --topbar-text:    #6e6c66;
    --topbar-pill-bg: rgba(255,255,255,0.05);

    --thumb-bg:       #2a2a28;
    --page-border:    rgba(255,255,255,0.14);
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    background: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
}

/* ── App shell ────────────────────────────────────────────── */
/* dvh = dynamic viewport height: shrinks when iOS Safari's URL bar is
   visible so the footer (New publication button, version) stays in view. */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    height: 44px;
    background: var(--topbar-bg);
    border-bottom: 0.5px solid var(--topbar-border);
    flex-shrink: 0;
    z-index: 10;
}

.topbar-brand {
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-shrink: 0;
}
.topbar-logo {
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.01em;
}
.topbar-by {
    font-size: 10px;
    color: rgba(255,255,255,0.2);
}

.topbar-sep {
    width: 0.5px;
    height: 16px;
    background: var(--topbar-border);
    flex-shrink: 0;
    margin: 0 2px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.topbar-user {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--topbar-text);
    padding-left: 2px;
}
.topbar-user-btn {
    background: none;
    border: none;
    margin: 0;
    padding: 4px 8px;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 6px;
    font: inherit;
    transition: background 0.15s, color 0.15s;
}
.topbar-user-icon { flex: 0 0 auto; opacity: 0.7; }
.topbar-user-name { white-space: nowrap; }
.topbar-user-caret {
    flex: 0 0 auto;
    opacity: 0.45;
    margin-left: 2px;
    transition: transform 0.15s;
}
.topbar-user.open .topbar-user-caret { transform: rotate(180deg); }

/* User dropdown — available at every viewport size. Hidden until the user
   icon is clicked, then anchored under the topbar. */
.topbar-user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    background: var(--bg-surface);
    border: 0.5px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-modal);
    padding: 10px 12px;
    min-width: 160px;
    z-index: 90;
}
.topbar-user.open .topbar-user-menu { display: flex; }
.topbar-user-menu-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}
.topbar-user-menu-link {
    margin-top: 4px;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 12px;
    width: 100%;
    box-sizing: border-box;
    transition: background 0.12s;
}
.topbar-user-menu-link:hover,
.topbar-user-menu-link:focus-visible {
    background: var(--bg-hover);
    outline: none;
}
.topbar-user-btn:hover,
.topbar-user.open .topbar-user-btn { background: rgba(255,255,255,0.08); color: #fff; }
.topbar-user-btn:hover .topbar-user-icon,
.topbar-user.open .topbar-user-btn .topbar-user-icon,
.topbar-user-btn:hover .topbar-user-caret,
.topbar-user.open .topbar-user-btn .topbar-user-caret { opacity: 1; }

.topbar-role-pill {
    font-size: 9px;
    background: var(--topbar-pill-bg);
    color: rgba(255,255,255,0.3);
    padding: 2px 7px;
    border-radius: 10px;
    border: 0.5px solid rgba(255,255,255,0.07);
    white-space: nowrap;
}

.icon-btn {
    background: none;
    border: 0.5px solid rgba(255,255,255,0.10);
    border-radius: 6px;
    color: var(--topbar-text);
    cursor: pointer;
    padding: 4px 9px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-family: inherit;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* ── Body row ─────────────────────────────────────────────── */
.body-row { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--bg-surface);
    border-right: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease, border-right-width 0.2s ease;
}
body.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    border-right-width: 0;
}
.sidebar-toggle {
    margin-right: 4px;
}
body.sidebar-collapsed .sidebar-toggle { color: var(--accent); }
.sidebar-backdrop { display: none; }

/* ── Audit log viewer ─────────────────────────────────────── */
.audit-log-modal { width: 640px; max-width: 96vw; max-height: 82vh; }
.audit-log-body {
    overflow-y: auto;
    padding: 8px 4px 12px;
    flex: 1;
    min-height: 0;
}
.audit-log-body .log-entry {
    padding: 7px 16px;
    border-bottom: 0.5px solid var(--border-subtle);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
}
.audit-log-body .log-entry:last-child { border-bottom: 0; }
.audit-log-body .log-ts {
    color: var(--text-faint);
    font-size: 11px;
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}
.audit-log-body .log-user {
    color: var(--accent);
    font-size: 11px;
    font-weight: 500;
    margin-right: 6px;
}
.audit-log-body .log-page {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg-app);
    border: 0.5px solid var(--border);
    color: var(--text-muted);
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}
.audit-log-body .empty-hint { padding: 30px 16px; }

.sidebar-header {
    padding: 8px 14px;
    border-bottom: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
    min-height: 46px;
    justify-content: center;
}
.sidebar-header h2 {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.loc-filter {
    font-size: 10px;
    color: var(--text-faint);
    padding: 3px 6px;
    border: 0.5px solid var(--border);
    border-radius: 5px;
    background: var(--bg-app);
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    appearance: auto;
}
.loc-filter:focus { outline: none; border-color: var(--accent); }

.pub-list { flex: 1; overflow-y: auto; padding: 6px; }

.pub-item {
    padding: 9px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12px;
    border: 0.5px solid transparent;
    margin-bottom: 1px;
    transition: background 0.1s;
}
.pub-item:hover { background: var(--bg-hover); }
.pub-item.active { background: var(--bg-app); border-color: var(--border); }

.pub-item-title {
    font-weight: 500;
    margin-bottom: 2px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pub-sub {
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 1px;
}

.sidebar-footer { padding: 10px; border-top: 0.5px solid var(--border); flex-shrink: 0; }
.sidebar-version {
    margin-top: 8px;
    text-align: center;
    font-size: 9px;
    letter-spacing: 0.04em;
    color: var(--text-whisper);
    font-variant-numeric: tabular-nums;
    user-select: none;
}
.sidebar-footer:has(> .sidebar-version:only-child) .sidebar-version { margin-top: 0; }

.sidebar-dev-pill {
    margin: 6px auto 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 3px 8px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #8a5a00;
    background: #fff6df;
    border: 1px dashed #e8b84a;
    border-radius: 999px;
    width: fit-content;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}
.sidebar-footer { display: flex; flex-direction: column; align-items: stretch; }
.sidebar-footer > .sidebar-dev-pill { align-self: center; }
.sidebar-dev-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #e8b84a;
    flex-shrink: 0;
}
.sidebar-dev-host {
    font-weight: 400;
    letter-spacing: 0.02em;
    text-transform: none;
    color: #a87a1a;
}
html.dark .sidebar-dev-pill {
    color: #f3cf7a;
    background: rgba(232, 184, 74, 0.08);
    border-color: rgba(232, 184, 74, 0.55);
}
html.dark .sidebar-dev-host { color: #d6b166; }

.btn-new {
    width: 100%;
    padding: 8px;
    font-size: 12px;
    background: var(--accent-green-bg);
    color: var(--accent-green);
    border: 0.5px solid var(--accent-green-border);
    border-radius: 7px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-new:hover { background: var(--accent-green-hover); }
.btn-new:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: var(--bg-hover);
    color: var(--text-faint);
    border-color: var(--border);
}

/* ── Main ─────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.toolbar {
    padding: 8px 18px;
    min-height: 46px;
    background: var(--bg-surface);
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pub-title {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}
.pub-subtitle { font-size: 11px; color: var(--text-faint); font-weight: 400; margin-left: 5px; }
.empty-title-hint { color: var(--text-faint); font-weight: 400; }

.tbtn {
    padding: 6px 12px;
    font-size: 11px;
    border: 0.5px solid var(--border-input);
    border-radius: 7px;
    cursor: pointer;
    background: var(--bg-surface);
    color: var(--text-primary);
    white-space: nowrap;
    font-family: inherit;
    font-weight: 500;
    transition: background 0.15s;
}
.tbtn:hover { background: var(--bg-hover); }
.tbtn.green {
    background: var(--accent-green-bg);
    color: var(--accent-green);
    border-color: var(--accent-green-border);
}
.tbtn.green:hover { background: var(--accent-green-hover); }
.tbtn:disabled { opacity: 0.3; cursor: not-allowed; }
.tbtn:disabled:hover { background: var(--bg-surface); }

.toolbar-actions { display: flex; align-items: center; gap: 6px; }
.toolbar-menu-btn { display: none; padding: 6px 10px; font-size: 16px; line-height: 1; }
/* ── Flatplan ─────────────────────────────────────────────── */
.flatplan { flex: 1; overflow-y: auto; padding: 18px; }

.empty-hint {
    padding: 60px 40px;
    text-align: center;
    color: var(--text-whisper);
    font-size: 12px;
}

.section-tag {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 0 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-tag::after {
    content: '';
    flex: 1;
    height: 0.5px;
    background: var(--border);
}
.section-tag-hint {
    text-transform: none;
    letter-spacing: 0;
    font-size: 9px;
    color: var(--text-whisper);
    font-weight: 400;
}

.spreads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
    position: relative;
}

.singles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 140px));
    gap: 12px;
    margin-bottom: 22px;
}

/* ── Spread / single unit ─────────────────────────────────── */
.spread-unit,
.single-unit {
    display: flex;
    border-radius: 7px;
    border: 0.5px solid var(--page-border);
    overflow: hidden;
    background: var(--bg-surface);
    width: 100%;
    box-shadow: var(--shadow-card);
}

/* ── Spread badge ─────────────────────────────────────────── */
.spread-unit { position: relative; }

.spread-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--accent);
    color: #fff;
    font-size: 8px;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
    z-index: 2;
    box-shadow: 0 0 0 2px var(--bg-surface);
}

/* ── Spread drag-drop indicator (floating bar in gap) ────── */
.spread-drop-indicator {
    position: absolute;
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s, left 0.08s, top 0.08s, height 0.08s;
    z-index: 4;
    box-shadow: 0 0 0 1px var(--bg-surface);
}
.spread-drop-indicator.active { opacity: 1; }

/* ── Spread move handle ───────────────────────────────────── */
/* padding-bottom gives the handle its own non-overlapping space below page-halves */
.spread-unit:has(.spread-move-handle) { padding-bottom: 16px; }
.spread-unit.dragging { opacity: 0.22; }

.spread-move-handle {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 16px;
    display: flex; align-items: center; justify-content: center;
    cursor: grab;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 3;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    background: linear-gradient(to top, rgba(0,0,0,0.06), transparent);
    letter-spacing: 2px;
}
/* On touch devices the handle doesn't get a hover — keep it visible */
@media (hover: none) {
    .spread-move-handle { opacity: 0.7; height: 22px; font-size: 13px; }
}
.spread-unit:hover .spread-move-handle { opacity: 1; }
.spread-move-handle:active { cursor: grabbing; }

/* ── Page half ────────────────────────────────────────────── */
.page-half {
    position: relative;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}
.page-half.draggable {
    cursor: grab;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.page-half.draggable img { -webkit-touch-callout: none; pointer-events: none; }
.page-half.draggable:active { cursor: grabbing; }
.page-half + .page-half { border-left: 0.5px solid var(--page-border); }
.page-half.dragging { opacity: 0.22; }
.page-half.swap-target .page-footer {
    background: var(--accent);
    color: #fff;
}
.page-half.swap-target .page-footer .page-label,
.page-half.swap-target .page-footer .page-date {
    color: #fff;
}
.page-card-inner { background: var(--bg-surface); transition: background 0.1s; }
.page-half:not(.swap-target):hover .page-card-inner { background: var(--bg-hover); }

/* When a row has a card with a tall footer (wrapped title), every other
   card stretches to match. We want the thumb+title aligned to the top and
   any extra space to appear BELOW the card content — not between the thumb
   and the footer. A grow-only pseudo-element at the bottom of the column
   absorbs the slack. Blank slots keep the classic fill so their dashed
   divider still covers the full card height. */
.page-half:not(.blank-slot)::after {
    content: "";
    flex: 1 1 auto;
    min-height: 0;
}
.blank-slot .page-card-inner { flex: 1; }

.thumb {
    width: 100%;
    aspect-ratio: 1330/1838;
    background: var(--thumb-bg);
    position: relative;
    overflow: hidden;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb-empty {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 8px; color: var(--text-whisper);
    text-align: center; padding: 6px;
    box-sizing: border-box;
}

/* ── Zones (multi-zone layouts) ──────────────────────────── */
.thumb .zone {
    position: absolute;
    overflow: hidden;
    box-sizing: border-box;
}
.thumb .zone + .zone { outline: 0.5px dashed rgba(255,255,255,0.3); outline-offset: -0.5px; }
html.dark .thumb .zone + .zone { outline-color: rgba(0,0,0,0.35); }

/* full layout: one zone filling the whole thumb */
.thumb.layout-full .zone { inset: 0; }

/* halves */
.thumb.layout-halves .zone-top    { top: 0; left: 0; right: 0; height: 50%; }
.thumb.layout-halves .zone-bottom { bottom: 0; left: 0; right: 0; height: 50%; }

/* third_inner — outer 1/3, inner 2/3 single */
.thumb.layout-third_inner.hand-left .zone-outer  { top: 0; bottom: 0; left: 0; width: 33.333%; }
.thumb.layout-third_inner.hand-left .zone-inner  { top: 0; bottom: 0; left: 33.333%; right: 0; }
.thumb.layout-third_inner.hand-right .zone-outer { top: 0; bottom: 0; right: 0; width: 33.333%; }
.thumb.layout-third_inner.hand-right .zone-inner { top: 0; bottom: 0; left: 0; right: 33.333%; }

/* third_split — outer 1/3 + inner 2/3 halved top/bottom */
.thumb.layout-third_split.hand-left  .zone-outer        { top: 0; bottom: 0; left: 0; width: 33.333%; }
.thumb.layout-third_split.hand-left  .zone-inner_top    { top: 0; left: 33.333%; right: 0; height: 50%; }
.thumb.layout-third_split.hand-left  .zone-inner_bottom { bottom: 0; left: 33.333%; right: 0; height: 50%; }
.thumb.layout-third_split.hand-right .zone-outer        { top: 0; bottom: 0; right: 0; width: 33.333%; }
.thumb.layout-third_split.hand-right .zone-inner_top    { top: 0; left: 0; right: 33.333%; height: 50%; }
.thumb.layout-third_split.hand-right .zone-inner_bottom { bottom: 0; left: 0; right: 33.333%; height: 50%; }

/* drop-hover state on a single zone */
.thumb .zone.drop-hover { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--bg-hover); }

/* ── Slot swap mode ──────────────────────────────────────── */
body.slot-swap-mode .page-half.draggable { cursor: default; }
body.slot-swap-mode .spread-move-handle { display: none; }

.thumb .zone.slot-draggable { cursor: grab; }
.thumb .zone.slot-draggable:active { cursor: grabbing; }
body.slot-swap-mode .thumb .zone.slot-draggable::after {
    content: "";
    position: absolute; inset: 3px;
    pointer-events: none;
    border: 1.5px dashed rgba(77,158,216,0.85);
    border-radius: 4px;
}
.thumb .zone.slot-dragging { opacity: 0.35; }
.thumb .zone.slot-drop-ok  { outline: 2.5px solid #4a9f40; outline-offset: -2px; background: rgba(74,159,64,0.12); }
.thumb .zone.slot-drop-bad { outline: 2px dashed #d14845;  outline-offset: -2px; }

.tbtn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.page-num-badge {
    position: absolute; top: 4px; left: 4px;
    background: rgba(0,0,0,0.52); color: #fff;
    font-size: 9px; font-weight: 500;
    padding: 2px 5px; border-radius: 6px;
    pointer-events: none; line-height: 1.3;
}

.status-pip {
    position: absolute; top: 4px; right: 4px;
    width: 7px; height: 7px; border-radius: 50%;
    pointer-events: none;
}

.lock-icon {
    position: absolute; bottom: 4px; right: 4px;
    font-size: 10px; opacity: 0.32;
    pointer-events: none;
}

.page-footer > .card-chips { margin: 4px 0 2px; flex-wrap: wrap; }
.card-chips { display: flex; gap: 3px; flex-shrink: 0; }
.card-chip {
    font-size: 8px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    color: #fff;
    line-height: 1.35;
    letter-spacing: 0.02em;
    white-space: nowrap;
    pointer-events: none;
}

.thumb-empty {
    font-size: 9px; color: var(--text-whisper);
    transition: background 0.12s, outline 0.12s;
}
.thumb-empty.drop-hover {
    background: var(--bg-hover) !important;
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
    color: var(--accent);
}

.page-footer {
    padding: 5px 7px 6px;
    border-top: 0.5px solid var(--border-subtle);
    background: var(--bg-surface);
    flex-shrink: 0;
}
.page-label {
    font-size: 10px; font-weight: 500;
    color: var(--text-primary);
    line-height: 1.35;
    word-break: break-word;
}
.page-date { font-size: 9px; color: var(--text-whisper); margin-top: 1px; }

/* ── Modal overlay ────────────────────────────────────────── */
.modal-wrap {
    position: fixed; inset: 0;
    background: var(--overlay);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
}

.pdf-lightbox {
    background: var(--bg-surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    width: 90vw;
    height: 92vh;
    height: 92dvh;
    max-width: 1100px;
}
.pdf-lightbox iframe {
    flex: 1;
    width: 100%;
    border: none;
    display: block;
}

.modal {
    background: var(--bg-surface);
    border-radius: 12px;
    border: 0.5px solid var(--border);
    width: 900px; max-width: 96vw; max-height: 92vh; max-height: 92dvh;
    overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-modal);
}

.modal-head {
    padding: 13px 18px;
    border-bottom: 0.5px solid var(--border);
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
.modal-num {
    background: var(--bg-app);
    border: 0.5px solid var(--border);
    border-radius: 14px;
    padding: 2px 10px; font-size: 11px; font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
}
.modal-title-text { font-size: 14px; font-weight: 500; flex: 1; color: var(--text-primary); }
.modal-x {
    background: none; border: none;
    font-size: 20px; cursor: pointer;
    color: var(--text-faint); padding: 2px 6px; line-height: 1;
    flex-shrink: 0;
    font-family: inherit;
}
.modal-x:hover { color: var(--text-primary); }

.modal-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.modal-l {
    width: 230px; min-width: 230px;
    padding: 14px;
    border-right: 0.5px solid var(--border);
    overflow-y: auto;
    background: var(--bg-elevated);
    flex-shrink: 0;
    display: flex; flex-direction: column; gap: 10px;
}

.modal-thumb-lg {
    width: 100%; aspect-ratio: 1330/1838;
    background: var(--bg-app);
    border-radius: 7px; overflow: hidden;
    border: 0.5px solid var(--border);
    flex-shrink: 0;
    position: relative;
}
.modal-thumb-lg.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-thumb-lg .thumb-empty {
    font-size: 11px; color: var(--text-faint);
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 0 8px;
    pointer-events: none;
}
.modal-thumb-lg .zone:has(.thumb-empty) { cursor: pointer; }
.modal-thumb-lg .zone:has(.thumb-empty):hover { background: var(--bg-hover); }
.modal-thumb-lg .zone:has(.thumb-empty):active { background: var(--bg-active); }
.modal-thumb-empty {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: var(--text-faint);
}

.modal-r { flex: 1; padding: 14px 18px; overflow-y: auto; min-width: 0; }

/* ── Meta column (Categories / Tags) ──────────────────────── */
.modal-meta {
    width: 200px;
    min-width: 200px;
    padding: 14px 14px 14px 12px;
    border-left: 0.5px solid var(--border);
    background: var(--bg-elevated);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    flex-shrink: 0;
}
.meta-group { display: flex; align-items: flex-start; gap: 10px; }
.meta-group-lbl {
    font-size: 9px;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-top: 6px;
    width: 62px;
    flex-shrink: 0;
}
.meta-chips { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.meta-chip {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    background: var(--chip-bg, #666);
    border: 1px solid transparent;
    cursor: pointer;
    user-select: none;
    opacity: 0.32;
    transition: opacity 0.12s, transform 0.08s;
    letter-spacing: 0.01em;
}
.meta-chip:hover { opacity: 0.7; }
.meta-chip.selected { opacity: 1; }
.meta-chip.selected:hover { opacity: 1; }
.meta-chip.readonly { cursor: default; }
.meta-chip.readonly:hover { opacity: 0.32; }
.meta-chip.readonly.selected:hover { opacity: 1; }

/* ── Layout picker (in meta column) ──────────────────────── */
.meta-group-col { flex-direction: column; align-items: stretch; gap: 8px; }
.meta-group-lbl-top { width: auto; padding-top: 0; }

.layout-picker {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.layout-tile {
    aspect-ratio: 38/52;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-surface);
    border: 0.5px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-muted);
    transition: border-color 0.1s, color 0.1s, background 0.1s;
    padding: 4px;
}
.layout-tile svg { width: 100%; height: 100%; }
.layout-tile:hover { color: var(--text-primary); background: var(--bg-hover); }
.layout-tile.selected {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-surface);
}
.layout-tile.readonly { cursor: default; }
.layout-tile.readonly:hover { color: var(--text-muted); background: var(--bg-surface); }

/* ── Modal content ────────────────────────────────────────── */
.info-grid-slim { grid-template-columns: 1fr !important; }
.zone-block {
    border: 0.5px solid var(--border);
    border-radius: 7px;
    padding: 12px 14px 6px;
    margin-bottom: 14px;
    background: var(--bg-app);
}
.zone-block-head {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 10px;
}
.zone-block .info-grid { margin-bottom: 10px; padding-bottom: 10px; }
.zone-block .ef-row:last-child { margin-bottom: 8px; }
.zone-status-grid { grid-template-columns: 1fr 1fr 1fr; }

.info-grid {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: 10px; margin-bottom: 14px; padding-bottom: 14px;
    border-bottom: 0.5px solid var(--border-subtle);
}
.info-cell .lbl {
    font-size: 9px; font-weight: 500; color: var(--text-faint);
    margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.04em;
}
.info-cell .val { font-size: 12px; color: var(--text-primary); }

.field-blk { margin-bottom: 12px; }
.field-blk .lbl {
    font-size: 10px; font-weight: 500; color: var(--text-faint); margin-bottom: 3px;
}
.field-blk .val { font-size: 12px; color: var(--text-primary); line-height: 1.5; }

.file-row { display: flex; align-items: center; gap: 8px; }
.file-link {
    color: var(--accent); text-decoration: underline; font-size: 12px; cursor: pointer;
    background: none; border: none; padding: 0; font-family: inherit;
}
.file-zone-tag {
    font-size: 9px; font-weight: 600;
    padding: 1px 5px; border-radius: 3px;
    background: var(--bg-surface); color: var(--text-muted);
    border: 0.5px solid var(--border);
    text-decoration: none; text-transform: uppercase; letter-spacing: 0.03em;
    margin-right: 2px;
}

.spread-val { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread-linked-lbl { font-size: 12px; color: var(--accent); font-weight: 500; }
.btn-link-spread {
    font-size: 11px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
    border: 0.5px solid var(--accent); color: var(--accent);
    background: none; font-family: inherit;
}
.btn-link-spread:hover { background: rgba(55,138,221,0.08); }
.btn-unlink-spread {
    font-size: 11px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
    border: 0.5px solid var(--border-input); color: var(--text-muted);
    background: none; font-family: inherit;
}
.btn-unlink-spread:hover { background: var(--bg-hover); }
.file-sz { font-size: 10px; color: var(--text-faint); }

.act-row {
    display: flex; gap: 8px;
    margin-top: 14px; padding-top: 14px;
    border-top: 0.5px solid var(--border-subtle);
    flex-wrap: wrap;
}

.btn-edit {
    padding: 7px 16px; font-size: 11px;
    background: var(--accent-green); color: #fff;
    border: none; border-radius: 7px; cursor: pointer; font-weight: 500;
    font-family: inherit;
}
.btn-edit:hover { opacity: 0.88; }

.btn-log {
    padding: 7px 16px; font-size: 11px;
    background: var(--bg-app);
    border: 0.5px solid var(--border);
    border-radius: 7px; cursor: pointer;
    color: var(--text-primary);
    font-family: inherit;
}
.btn-log:hover { background: var(--bg-hover); }

.btn-delete {
    padding: 7px 16px; font-size: 11px;
    background: transparent;
    border: 0.5px solid rgba(220,50,50,0.3);
    border-radius: 7px; cursor: pointer;
    color: #c0392b;
    font-family: inherit;
}
.btn-delete:hover { background: rgba(220,50,50,0.07); }
html.dark .btn-delete { color: #e57373; border-color: rgba(220,80,80,0.3); }

/* "Clear page" action — amber/muted (content-destructive but non-structural) */
.btn-clear {
    padding: 7px 16px; font-size: 11px;
    background: transparent;
    border: 0.5px solid rgba(200,140,40,0.3);
    border-radius: 7px; cursor: pointer;
    color: #b0681a;
    margin-left: auto;
    font-family: inherit;
}
.btn-clear:hover { background: rgba(200,140,40,0.08); }
html.dark .btn-clear { color: #e0a030; border-color: rgba(224,160,48,0.3); }

.log-area { margin-top: 14px; padding-top: 14px; border-top: 0.5px solid var(--border-subtle); }
.log-hd {
    font-size: 10px; font-weight: 500; color: var(--text-muted);
    margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em;
}
.log-entry {
    font-size: 11px; color: var(--text-muted);
    margin-bottom: 8px; line-height: 1.6;
    padding-bottom: 8px; border-bottom: 0.5px solid var(--border-subtle);
}
.log-entry:last-child { border-bottom: none; margin-bottom: 0; }
.log-ts { color: var(--text-primary); font-weight: 500; }

.read-only-notice {
    font-size: 11px; color: var(--text-faint);
    padding: 10px 12px; background: var(--bg-app);
    border-radius: 7px; margin-top: 12px;
    border: 0.5px solid var(--border);
}

/* ── Edit form ────────────────────────────────────────────── */
.edit-form { display: flex; flex-direction: column; gap: 11px; }
.ef-row { display: flex; flex-direction: column; gap: 3px; }
.ef-lbl { font-size: 10px; font-weight: 500; color: var(--text-muted); }

.ef-input,
.ef-select,
.ef-ta {
    padding: 7px 10px; font-size: 12px;
    border: 0.5px solid var(--border-input);
    border-radius: 7px;
    background: var(--bg-surface);
    color: var(--text-primary);
    width: 100%;
    font-family: inherit;
    appearance: auto;
}
.ef-input:focus, .ef-select:focus, .ef-ta:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(55,138,221,0.12);
}
.ef-ta { resize: vertical; min-height: 52px; }

.upload-zone {
    border: 0.5px dashed var(--border-input);
    border-radius: 7px; padding: 14px;
    text-align: center; font-size: 11px;
    color: var(--text-faint); cursor: pointer;
    background: var(--bg-app);
    transition: background 0.15s, border-color 0.15s;
}
.upload-zone:hover { border-color: var(--accent); color: var(--accent); }
.upload-zone.dragover { background: var(--bg-hover); border-color: var(--accent); }
/* Multi-zone layouts: the bar is an informational hint only — upload happens
   per-zone on the thumbnail above. */
.upload-zone.hint-only { cursor: default; pointer-events: none; opacity: 0.7; }
.upload-zone.hint-only:hover { border-color: var(--border-input); color: var(--text-faint); }

.ef-actions {
    display: flex; gap: 8px;
    padding-top: 10px; border-top: 0.5px solid var(--border-subtle);
    margin-top: 2px; flex-wrap: wrap;
}
.btn-save {
    padding: 8px 16px; font-size: 11px;
    background: var(--accent-green); color: #fff;
    border: none; border-radius: 7px; cursor: pointer; font-weight: 500;
    font-family: inherit;
}
.btn-save:hover { opacity: 0.88; }
.btn-cancel {
    padding: 8px 16px; font-size: 11px;
    background: var(--bg-app);
    border: 0.5px solid var(--border);
    border-radius: 7px; cursor: pointer;
    color: var(--text-primary);
    font-family: inherit;
}
.btn-cancel:hover { background: var(--bg-hover); }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 22px; left: 50%;
    transform: translateX(-50%);
    background: #1a1a18; color: #fff;
    padding: 8px 18px; border-radius: 18px;
    font-size: 11px; opacity: 0;
    transition: opacity 0.2s; z-index: 999;
    pointer-events: none; white-space: nowrap;
    border: 0.5px solid rgba(255,255,255,0.08);
}
.toast.show { opacity: 1; }

/* ── Blank slot ───────────────────────────────────────────── */
.blank-slot { opacity: 0.35; cursor: default; }
.blank-slot.addable { opacity: 0.5; cursor: pointer; }
.blank-slot.addable:hover { opacity: 0.85; }
.blank-slot.addable:hover .page-card-inner { background: var(--bg-hover); }
.blank-slot .page-card-inner { border-left: 0.5px dashed var(--border) !important; }
.blank-slot-inner {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 6px;
}
.blank-slot-plus {
    font-size: 28px; line-height: 1;
    color: var(--text-whisper);
}
.blank-slot.addable:hover .blank-slot-plus { color: var(--accent); }
.blank-slot-label {
    font-size: 10px;
    color: var(--text-whisper);
}
.blank-slot.addable:hover .blank-slot-label { color: var(--accent); }

/* ── View toggle buttons ──────────────────────────────────── */
.view-btns {
    display: flex;
    border: 0.5px solid var(--border-input);
    border-radius: 7px;
    overflow: hidden;
    flex-shrink: 0;
}
.view-btn {
    background: var(--bg-surface);
    border: none;
    border-left: 0.5px solid var(--border-input);
    padding: 5px 9px;
    cursor: pointer;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    transition: background 0.12s, color 0.12s;
    font-family: inherit;
}
.view-btn:first-child { border-left: none; }
.view-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.view-btn.active { background: var(--bg-active); color: var(--text-primary); }

/* ── Large view ───────────────────────────────────────────── */
.flatplan.view-large .spreads-grid {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}
.flatplan.view-large .singles-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 280px));
}

/* ── XL view ──────────────────────────────────────────────── */
.flatplan.view-xl .spreads-grid {
    grid-template-columns: repeat(auto-fill, minmax(525px, 1fr));
}
.flatplan.view-xl .singles-grid {
    grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
}

/* ── List view ────────────────────────────────────────────── */
.list-row {
    display: flex;
    gap: 20px;
    cursor: pointer;
    border-radius: 7px;
    padding: 10px;
    margin: 0 -10px;
    transition: background 0.1s;
    margin-bottom: 4px;
}
.list-row:hover { background: var(--bg-hover); }

.list-thumb {
    width: 190px;
    min-width: 190px;
    aspect-ratio: 1330/1838;
    position: relative;
    border-radius: 5px;
    overflow: hidden;
    background: var(--thumb-bg);
    border: 0.5px solid var(--page-border);
    flex-shrink: 0;
}
.list-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.list-thumb .thumb-empty { font-size: 9px; }
.list-thumb .zone .thumb-empty { font-size: 9px; }

.list-detail {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 2px 0;
}

.list-label {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-statuses {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.list-status-chip {
    font-size: 12px;
    font-weight: 500;
}
/* Category / tag chips in list view — slightly larger than on cards */
.list-statuses .card-chip {
    font-size: 10px;
    padding: 2px 7px;
    align-self: center;
}

.list-fields {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Per-zone blocks in the list view (multi-zone layouts) */
.list-zone-group {
    border-left: 2px solid var(--border);
    padding: 4px 0 4px 10px;
    margin: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.list-zone-group + .list-zone-group { margin-top: 2px; }
.list-zone-head {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
}
.list-zone-empty { font-size: 11px; color: var(--text-whisper); }
.list-field {
    font-size: 12px;
    display: flex;
    gap: 10px;
    line-height: 1.5;
}
.list-fl {
    color: var(--text-faint);
    flex-shrink: 0;
    min-width: 100px;
    font-size: 11px;
}
.list-fv {
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.list-modified {
    font-size: 11px;
    color: var(--text-whisper);
    margin-top: auto;
    padding-top: 6px;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-input); }

/* ── Mobile (≤800px) ──────────────────────────────────────── */
@media (max-width: 800px) {
    /* Toolbar: collapse text buttons into a dropdown behind the ⋯ menu. */
    .toolbar { position: relative; padding: 8px 10px; gap: 6px; }
    .pub-title { font-size: 12px; }
    .toolbar-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
    .toolbar-actions {
        display: none;
        position: absolute;
        top: calc(100% + 2px);
        right: 8px;
        flex-direction: column;
        align-items: stretch;
        background: var(--bg-surface);
        border: 0.5px solid var(--border);
        border-radius: 8px;
        box-shadow: var(--shadow-modal);
        padding: 6px;
        gap: 4px;
        min-width: 180px;
        z-index: 90;
    }
    .toolbar-actions.open { display: flex; }
    .toolbar-actions .tbtn { text-align: left; justify-content: flex-start; padding: 8px 10px; font-size: 12px; }

    /* Sidebar becomes an overlay drawer so it doesn't eat horizontal space. */
    .body-row { position: relative; }
    .sidebar {
        position: absolute;
        top: 0; left: 0; bottom: 0;
        width: 240px; min-width: 240px;
        z-index: 80;
        box-shadow: 6px 0 24px rgba(0,0,0,0.25);
        transition: transform 0.22s ease;
    }
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
        width: 240px;
        min-width: 240px;
        border-right-width: 0.5px;
    }
    body:not(.sidebar-collapsed) .sidebar-backdrop {
        display: block;
        position: absolute; inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 79;
    }

    /* Modal: single-column stack. Sections flow: thumb → upload → view/edit
       → categories/tags/layouts. Thumb is centered and constrained so it
       doesn't dominate the viewport. */
    .modal { width: 96vw; max-height: 92vh; max-height: 92dvh; }
    .modal-body { flex-direction: column; overflow-y: auto; }
    .modal-l {
        width: 100%; min-width: 0;
        padding: 12px;
        border-right: none; border-bottom: 0.5px solid var(--border);
        flex-direction: column; gap: 10px;
        overflow: visible;
        flex: 0 0 auto;
    }
    .modal-thumb-lg {
        max-width: 260px;
        width: 100%;
        margin: 0 auto;
        flex: 0 0 auto;
    }
    .modal-l .upload-zone { flex: 0 0 auto; padding: 10px; }
    .modal-r {
        padding: 12px 14px;
        overflow: visible;
        flex: 0 0 auto;
    }
    .modal-meta {
        width: 100%; min-width: 0;
        padding: 12px 14px;
        border-left: none; border-top: 0.5px solid var(--border);
        flex-direction: column; gap: 14px;
        overflow: visible;
        flex: 0 0 auto;
    }
    .modal-meta .meta-group { flex: 0 0 auto; }
    .modal-meta .meta-group-lbl { width: 72px; }
    /* Compact layout picker so the 4 tiles fit in a single row */
    .modal-meta .layout-picker {
        grid-template-columns: repeat(4, 1fr);
        max-width: 260px;
    }

    /* Flatplan grid shrinks so spreads fit in portrait width */
    .spreads-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .singles-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 120px)); }
    .flatplan { padding: 10px; }

    /* Large view on mobile: one full-width spread per row so both pages fit
       side-by-side on phones down to 375px. */
    .flatplan.view-large .spreads-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .flatplan.view-large .singles-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
    }

    /* Activity list row stacks thumb above text on narrow screens */
    .list-row { flex-direction: column; gap: 10px; }
    .list-thumb { width: 100%; min-width: 0; max-width: 260px; }

    /* Hide xl grid and list view — not useful on narrow screens. */
    #vBtnXl, #vBtnList { display: none; }

    /* Topbar: collapse user identity behind the profile icon to save space. */
    .topbar-user { padding-left: 0; }
    .topbar-user-btn {
        border: 0.5px solid rgba(255,255,255,0.10);
        padding: 4px 7px;
    }
    .topbar-user-btn .topbar-user-name,
    .topbar-user-btn .topbar-role-pill,
    .topbar-user-btn .topbar-user-caret { display: none; }
}

@media (max-width: 401px) {
    .topbar-by { display: none; }
}

/* ── Flipbook preview lightbox ─────────────────────────── */
.flipbook-wrap {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(10, 10, 10, 0.92);
    display: none;
    flex-direction: column;
}
body.flipbook-lock { overflow: hidden; }

.flipbook-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    color: #fff;
    border-bottom: 0.5px solid rgba(255,255,255,0.10);
}
.flipbook-title {
    font-size: 14px;
    font-weight: 600;
    margin-right: auto;
    color: #fff;
}
.flipbook-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.flipbook-btn {
    background: rgba(255,255,255,0.10);
    border: 0.5px solid rgba(255,255,255,0.15);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s;
}
.flipbook-btn:hover { background: rgba(255,255,255,0.20); }
.flipbook-counter {
    color: rgba(255,255,255,0.75);
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    min-width: 56px;
    text-align: center;
}
.flipbook-jump {
    width: 56px;
    height: 28px;
    border-radius: 6px;
    border: 0.5px solid rgba(255,255,255,0.20);
    background: rgba(0,0,0,0.40);
    color: #fff;
    text-align: center;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.flipbook-x {
    background: transparent;
    color: rgba(255,255,255,0.65);
    border: 0;
    width: 32px;
    height: 32px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.flipbook-x:hover { background: rgba(255,255,255,0.10); color: #fff; }

.flipbook-stage {
    flex: 1 1 auto;
    min-height: 0;          /* allow flex child to shrink below content size */
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.flipbook-fit {
    /* Sized inline by JS to fit the stage. turn.js then sets width:100% on
       the book, so the book scales to fit this wrapper exactly. */
    position: relative;
    max-width:  100%;
    max-height: 100%;
}
.flipbook-book {
    position: relative;
    width: 100%;
    height: 100%;
}
.flipbook-page {
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.18);
    overflow: hidden;
    position: relative;
}
.flipbook-page-num {
    position: absolute;
    bottom: 8px;
    right: 10px;
    font-size: 11px;
    color: rgba(0,0,0,0.45);
    background: rgba(255,255,255,0.85);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 4;
    pointer-events: none;
}

.turn-vanilla-book { perspective: 2400px; }
.turn-vanilla-book .turn-vanilla-page {
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

@media (max-width: 640px) {
    .flipbook-head { padding: 10px 12px; gap: 10px; }
    .flipbook-title { font-size: 13px; }
    .flipbook-jump { display: none; }
    .flipbook-stage { padding: 8px; }
}
