/* ===== Шрифты: PT Serif + PT Sans (OFL, локально, сабсет кириллица+латиница) ===== */
@font-face {
    font-family: 'PT Serif'; font-style: normal; font-weight: 400; font-display: swap;
    src: url('fonts/PT_Serif-Web-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'PT Serif'; font-style: normal; font-weight: 700; font-display: swap;
    src: url('fonts/PT_Serif-Web-Bold.woff2') format('woff2');
}
@font-face {
    font-family: 'PT Sans'; font-style: normal; font-weight: 400; font-display: swap;
    src: url('fonts/PT_Sans-Web-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'PT Sans'; font-style: normal; font-weight: 700; font-display: swap;
    src: url('fonts/PT_Sans-Web-Bold.woff2') format('woff2');
}

/* ============================================================
   Букинистика — дизайн-система «Читальный зал»
   Палитра: бумага, бутылочное стекло, сургуч, латунь.
   Шрифты: книжная антиква в заголовках, системный гротеск в UI.
   Темы: светлая «дневной зал», тёмная «вечерний зал».
   ============================================================ */

:root {
    --paper: #f6f1e7;
    --card: #fffdf8;
    --card-2: #fdf9f0;
    --ink: #221d16;
    --muted: #75695a;
    --line: #e4dbc8;
    --line-strong: #d2c6ad;

    --brand: #19875d;          /* бутылочный зелёный */
    --brand-deep: #0f5f43;
    --brand-ink: #0c3d2c;
    --tint-brand: #e6f4ec;

    --accent: #c2410c;          /* сургуч */
    --accent-deep: #9a3409;
    --tint-accent: #fbeee4;

    --gold: #8a6d00;            /* латунь — брони */
    --tint-gold: #fdf6dd;

    --danger: #b3261e;
    --tint-danger: #fbeae8;

    --shadow: 0 12px 30px rgba(46, 38, 24, .12);
    --shadow-soft: 0 6px 18px rgba(46, 38, 24, .08);
    --radius: 16px;
    --radius-s: 10px;
    --tap: 46px;

    --font-display: 'PT Serif', Georgia, 'Times New Roman', serif;
    --font-ui: 'PT Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

html[data-theme="dark"] {
    --paper: #141815;
    --card: #1c221e;
    --card-2: #202722;
    --ink: #ece5d4;
    --muted: #a39882;
    --line: #313b34;
    --line-strong: #43504a;

    --brand: #3fb583;
    --brand-deep: #2d9468;
    --brand-ink: #bfe9d6;
    --tint-brand: #1c3329;

    --accent: #ef7036;
    --accent-deep: #d85a22;
    --tint-accent: #3a2418;

    --gold: #d8b542;
    --tint-gold: #332b10;

    --danger: #e36258;
    --tint-danger: #3a1f1d;

    --shadow: 0 12px 30px rgba(0, 0, 0, .45);
    --shadow-soft: 0 6px 18px rgba(0, 0, 0, .35);
}
html[data-theme="dark"] img { opacity: .94; }

/* ---------- База ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
    min-width: 320px;
    margin: 0;
    font-family: var(--font-ui);
    font-size: 16px;
    color: var(--ink);
    background:
        radial-gradient(1200px 500px at 80% -200px, var(--tint-brand) 0%, transparent 60%),
        var(--paper);
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--brand); }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; font-size: 16px; }
button, .btn, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--tint-accent); }

h1, h2, h3, .brand, .price, .tag-price, .stat-card strong {
    font-family: var(--font-display);
    letter-spacing: -.01em;
}
h1 { margin: 0 0 12px; font-size: clamp(28px, 4vw, 46px); line-height: 1.08; font-weight: 700; }
h2 { margin: 0 0 10px; font-size: 21px; line-height: 1.25; }
p { line-height: 1.6; }
.price, .tag-price, .stat-card strong { font-variant-numeric: tabular-nums; }

.container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.skip-link {
    position: absolute; left: -9999px; top: 8px; z-index: 100;
    padding: 10px 16px; background: var(--brand); color: #fff; border-radius: var(--radius-s);
}
.skip-link:focus { left: 8px; color: #fff; }

/* ---------- Шапка ---------- */
.site-header {
    position: sticky; top: 0; z-index: 40;
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
}
.header-inner { min-height: 60px; display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; overflow: visible; }
.brand { flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; font-weight: 700; font-size: 20px; white-space: nowrap; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; }
.brand-mark {
    flex: 0 0 auto; display: grid; place-items: center;
    width: 42px; height: 42px; border-radius: 12px 4px 4px 12px; /* силуэт корешка */
    color: #fff; font-family: var(--font-display);
    background: linear-gradient(160deg, var(--brand), var(--brand-deep));
    box-shadow: inset 3px 0 0 rgba(255,255,255,.25), var(--shadow-soft);
}
.top-nav {
    display: flex; gap: 2px; align-items: center;
    font-weight: 600; flex-wrap: nowrap;
    min-width: 0; flex: 1 1 0;
    overflow: visible;
    justify-content: flex-end;
}

/* Главные пункты: иконка + текст */
.nav-link {
    flex: 0 0 auto;
    min-height: 36px;
    display: inline-flex; align-items: center; gap: 5px;
    border-radius: 999px; padding: 6px 11px;
    white-space: nowrap; font-size: 14px; font-weight: 600;
    transition: background .14s ease, color .14s ease;
}
.nav-link:hover { background: var(--tint-brand); color: var(--brand-deep); }
.nav-link[aria-current="page"] { background: var(--brand); color: #fff; }
.nav-link .ni { font-size: 15px; line-height: 1; flex: 0 0 auto; }
.nav-link .nl { }

/* Разделитель */
.nav-sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; flex: 0 0 auto; opacity: .5; }

/* Иконка-кнопка для второстепенных пунктов */
.nav-icon-btn {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; font-size: 17px; line-height: 1;
    border: 0; background: transparent; cursor: pointer;
    color: var(--muted);
    transition: background .14s ease, color .14s ease, transform .14s ease;
    position: relative;
    text-decoration: none;
}
.nav-icon-btn:hover { background: var(--tint-brand); color: var(--brand-deep); transform: translateY(-1px); }
.nav-icon-btn[aria-current="page"] { background: var(--tint-brand); color: var(--brand-deep); }

/* Tooltip из title — только десктоп */
/* tooltip через title — работает при overflow:hidden шапки */
@media (hover: hover) {
    .nav-icon-btn { overflow: visible; }
    .nav-icon-btn::after {
        content: attr(title);
        position: fixed;
        top: 66px;
        left: auto;
        background: var(--ink); color: var(--paper);
        padding: 4px 10px; border-radius: 8px;
        font-size: 12px; font-weight: 600; white-space: nowrap;
        pointer-events: none; opacity: 0;
        transition: opacity .15s ease;
        z-index: 200;
        transform: none;
    }
    .nav-icon-btn:hover::after { opacity: 1; }
}
.nav-logout { display: contents; margin: 0; }
.nav-logout button.nav-icon-btn { font-family: inherit; }

/* Переключатель темы */
.theme-toggle {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 999px;
    border: 1px solid var(--line); background: var(--card); cursor: pointer;
    display: inline-grid; place-items: center; font-size: 17px; line-height: 1;
    transition: transform .2s ease, background .15s ease;
}
.theme-toggle:hover { transform: rotate(20deg); background: var(--tint-brand); }
.theme-toggle .ico-moon, html[data-theme="dark"] .theme-toggle .ico-sun { display: none; }
html[data-theme="dark"] .theme-toggle .ico-moon { display: block; }

/* Гарантия: скрытое скрыто при любом CSS */
[hidden] { display: none !important; }
/* nav-drop скрывается через JS: style.display=none при закрытии */

/* Бургер — мобильное меню */
.nav-burger { position: relative; display: none; }
.burger-btn {
    cursor: pointer; width: 42px; height: 42px;
    display: grid; place-items: center; border: 1px solid var(--line);
    border-radius: var(--radius-s); background: var(--card); padding: 0;
}
.burger-ico, .burger-ico::before, .burger-ico::after {
    content: ''; display: block; width: 18px; height: 2px; background: var(--ink);
    border-radius: 2px; position: relative; transition: transform .2s ease, opacity .2s ease;
}
.burger-ico::before { position: absolute; top: -6px; }
.burger-ico::after { position: absolute; top: 6px; }
.burger-btn[aria-expanded="true"] .burger-ico { background: transparent; }
.burger-btn[aria-expanded="true"] .burger-ico::before { transform: translateY(6px) rotate(45deg); }
.burger-btn[aria-expanded="true"] .burger-ico::after { transform: translateY(-6px) rotate(-45deg); }
.nav-burger .nav-drop { right: 0; left: auto; }

/* Выпадающее меню */
.nav-more { position: relative; }
.menu-btn { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 7px 11px; border-radius: 999px; font-weight: 600; min-height: 36px; display: inline-flex; align-items: center; font-size: 15px; white-space: nowrap; font-family: inherit; }
.nav-more .menu-btn .arr { font-size: 10px; opacity: .6; margin-left: 4px; display: inline-block; transition: transform .2s ease; }
.nav-more .menu-btn[aria-expanded="true"] .arr { transform: rotate(180deg); }
.menu-btn:hover, .menu-btn[aria-expanded="true"], .menu-btn[aria-current="page"] { background: var(--tint-brand); color: var(--brand-deep); }
.nav-drop {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
    min-width: 220px; padding: 8px; display: grid; gap: 2px;
    background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
    animation: drop-in .16s ease;
}
@keyframes drop-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.nav-drop a, .nav-drop button { padding: 10px 12px; border-radius: var(--radius-s); font-weight: 600; white-space: nowrap; text-align: left; border: 0; background: transparent; cursor: pointer; width: 100%; }
.nav-drop a:hover, .nav-drop button:hover { background: var(--tint-brand); color: var(--brand-deep); }
.nav-drop .drop-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---------- Каркас ---------- */
.main { padding: 28px 0 84px; min-height: calc(100vh - 150px); }
.site-footer { border-top: 1px solid var(--line); padding: 22px 0 calc(22px + env(safe-area-inset-bottom)); color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.hero, .admin-head {
    display: flex; align-items: center; justify-content: space-between; gap: 24px;
    margin-bottom: 24px; padding: 26px 28px;
    border-radius: var(--radius);
    background: linear-gradient(150deg, var(--card) 55%, var(--tint-brand));
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}
.eyebrow { margin: 0 0 8px; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .1em; font-size: 12px; font-family: var(--font-ui); }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-title h1 { margin-bottom: 0; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 10px 18px;
    border: 1px solid var(--line-strong); border-radius: 999px;
    background: var(--card); color: var(--ink);
    font-weight: 700; cursor: pointer; touch-action: manipulation;
    line-height: 1.2; text-align: center;
    transition: transform .14s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); color: var(--ink); }
.btn:active { transform: translateY(0); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-deep); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger, .row-actions .danger, button.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn.danger:hover, .row-actions .danger:hover, button.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

/* ---------- Формы ---------- */
input, select, textarea {
    width: 100%; min-height: var(--tap);
    border: 1px solid var(--line-strong); border-radius: 12px;
    padding: 10px 13px; background: var(--card); color: var(--ink);
    transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--tint-brand); outline: none; }
textarea { resize: vertical; }
input[type="file"] { padding: 9px 12px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--brand); }
.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions, .actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; align-items: end; }
.grid-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
label { font-weight: 600; }

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) minmax(160px, 1fr) auto auto;
    gap: 12px; margin-bottom: 18px; padding: 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}
.filters.compact { grid-template-columns: minmax(220px, 1fr) auto auto; }

/* Панель результатов: счётчик + вид */
.results-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; flex-wrap: wrap; }
.results-count { color: var(--muted); font-weight: 600; }
.view-toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.view-toggle button {
    border: 0; background: var(--card); color: var(--muted); cursor: pointer;
    min-height: 38px; padding: 6px 14px; font-weight: 700; font-size: 14px;
}
.view-toggle button.active { background: var(--brand); color: #fff; }

/* ---------- Чипы жанров ---------- */
.genre-chips {
    display: flex; flex-wrap: nowrap; gap: 8px; margin: 12px 0 16px;
    overflow-x: auto; padding-bottom: 6px;
    scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.genre-chips::-webkit-scrollbar { height: 5px; }
.genre-chips::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
.chip {
    flex: 0 0 auto; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
    background: var(--card); border: 1px solid var(--line-strong); white-space: nowrap;
    transition: all .16s ease;
}
.chip:hover { border-color: var(--brand); color: var(--brand-deep); transform: translateY(-1px); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.active:hover { color: #fff; }

/* ---------- Каталог: карточка-корешок ---------- */
.catalog-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.book-card {
    position: relative;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow-soft);
    display: flex; flex-direction: column; min-width: 0;
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.book-card::before {                 /* корешок */
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; z-index: 2;
    background: linear-gradient(180deg, var(--brand), var(--brand-deep));
    box-shadow: inset -2px 0 3px rgba(0,0,0,.18);
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--line-strong); }
.cover { position: relative; display: block; aspect-ratio: 3 / 4; overflow: hidden; background: linear-gradient(135deg, var(--card-2), var(--line)); }
.cover::after {                      /* ляссе — ленточка-закладка */
    content: ''; position: absolute; top: -34px; right: 16px; width: 14px; height: 44px; z-index: 2;
    background: var(--accent);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
    box-shadow: 0 2px 4px rgba(0,0,0,.25);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
.book-card:hover .cover::after { transform: translateY(34px); }
.cover img, .detail-cover img, .cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-card .cover img { transition: transform .35s ease; }
.book-card:hover .cover img { transform: scale(1.04); }
.book-card-body { padding: 15px 16px 16px 20px; display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.book-card h2 { font-size: 17px; margin: 0; }
.book-card h2 a:hover { color: var(--brand-deep); }
.genre-pill {
    align-self: flex-start; padding: 4px 10px; border-radius: 999px;
    background: var(--tint-brand); color: var(--brand-deep); font-size: 12px; font-weight: 700;
}
.muted, .meta { color: var(--muted); margin: 0; }
.meta { font-size: 14px; }
.card-bottom { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 6px; }
.price {                              /* штамп цены */
    display: inline-block; padding: 3px 12px; font-size: 19px; color: var(--accent-deep);
    border: 2px solid currentColor; border-radius: 50% / 42%;
    transform: rotate(-2deg);
}
.count { color: var(--muted); white-space: nowrap; font-size: 14px; }


/* ---------- Появление ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
    .book-card, .chip, .btn, .cover::after, .theme-toggle { transition: none !important; }
    .nav-drop { animation: none; }
}

/* ---------- Пагинация ---------- */
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
.pagination .page-link {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 42px; min-height: 42px; padding: 4px 10px; border-radius: 12px;
    color: var(--ink); background: var(--card); border: 1px solid var(--line-strong);
    transition: background .14s ease;
}
.pagination .page-link.active { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.pagination .page-link:hover:not(.active) { background: var(--tint-brand); }
.pagination .page-gap { display: inline-flex; align-items: center; padding: 0 4px; color: var(--muted); }

/* ---------- Панели ---------- */
.empty, .panel {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 24px; box-shadow: var(--shadow-soft);
}
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty::before { content: '📚'; display: block; font-size: 40px; margin-bottom: 10px; }
.panel.narrow { max-width: 560px; margin: 0 auto; }
.narrow { max-width: 860px; margin-left: auto; margin-right: auto; }
.danger-panel, .danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); background: linear-gradient(180deg, var(--card), var(--tint-danger)); }
.item-focus { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); background: linear-gradient(180deg, var(--card), var(--tint-brand)); }
code { background: var(--card-2); border: 1px solid var(--line); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; font-size: 14px; }

/* ---------- Карточка книги ---------- */
.book-detail {
    display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 34px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 28px; box-shadow: var(--shadow-soft);
}
.detail-cover { position: relative; border-radius: 14px; overflow: hidden; background: linear-gradient(135deg, var(--card-2), var(--line)); align-self: start; box-shadow: var(--shadow-soft); }
.author { font-size: 22px; margin: 0 0 8px; color: var(--muted); font-family: var(--font-display); font-style: italic; }
.copies-list { display: grid; gap: 10px; }
.copy-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 10px 12px; background: var(--card-2); align-items: start; }
.copy-card small { grid-column: 2; color: var(--muted); }
.copy-card .reserve-details, .copy-card .reserved-badge { grid-column: 1 / -1; justify-self: start; }
.copy-main { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.copy-card.is-reserved { opacity: .85; background: var(--tint-gold); }
.reserved-badge { display: inline-flex; padding: 5px 11px; border-radius: 999px; background: var(--tint-gold); border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--line)); color: var(--gold); font-size: 13px; font-weight: 700; }

.reserve-details { margin-top: 10px; }
.reserve-details > summary {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; min-height: var(--tap);
    padding: 10px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700;
    transition: background .16s ease, transform .16s ease;
}
.reserve-details > summary::-webkit-details-marker { display: none; }
.reserve-details > summary:hover { background: var(--accent-deep); transform: translateY(-1px); }
.reserve-form { display: grid; gap: 10px; width: 100%; max-width: 420px; margin-top: 12px; padding: 16px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 14px; box-sizing: border-box; }
.reserve-form label { display: grid; gap: 6px; min-width: 0; }
.reserve-form input { width: 100%; box-sizing: border-box; }
.hp-field { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.related { margin-top: 36px; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 12px; }
.related-grid .book-card h2, .related-grid h3 { font-size: 15px; margin: 6px 0 2px; }

/* ---------- Флэш-сообщения ---------- */
.flash {
    padding: 13px 16px; border-radius: 14px; margin-bottom: 14px;
    border: 1px solid var(--line); background: var(--card);
    display: flex; align-items: center; gap: 10px;
    animation: drop-in .25s ease;
    box-shadow: var(--shadow-soft);
}
.flash::before { font-size: 17px; }
.flash.success { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--tint-brand); }
.flash.success::before { content: '✓'; color: var(--brand-deep); font-weight: 900; }
.flash.error { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: var(--tint-danger); }
.flash.error::before { content: '!'; color: var(--danger); font-weight: 900; }

/* ---------- Таблицы ---------- */
.table-wrap {
    overflow-x: auto; background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-soft);
    -webkit-overflow-scrolling: touch;
}
.admin-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.admin-table th, .admin-table td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th {
    position: sticky; top: 0; z-index: 1;
    background: var(--card-2); color: var(--muted);
    font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
}
.admin-table tbody tr { transition: background .12s ease; }
.admin-table tbody tr:hover { background: var(--card-2); }
.admin-table .status { margin: 2px 4px 2px 0; }
.admin-table input, .admin-table select { min-width: 120px; }
.row-error { background: var(--tint-danger) !important; }
.ok-line { color: var(--brand-deep); font-weight: 700; }

.row-actions { position: relative; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions form { display: inline; }
.row-actions a, .row-actions button {
    display: inline-flex; align-items: center; min-height: 34px;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--card-2); padding: 6px 11px; color: var(--ink);
    cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; touch-action: manipulation;
    transition: background .13s ease, border-color .13s ease;
}
.row-actions a:hover, .row-actions button:hover { background: var(--tint-brand); border-color: var(--brand); color: var(--brand-deep); }
.row-actions .quick-sell, .quick-actions .quick-sell { background: var(--accent); border-color: var(--accent); color: #fff; }
.row-actions .quick-sell:hover, .quick-actions .quick-sell:hover { background: var(--accent-deep); color: #fff; }
.quick-actions form { flex: 1 1 120px; }

/* ---------- Статусы ---------- */
.status { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); }
.status.available { background: var(--tint-brand); color: var(--brand-deep); border-color: transparent; }
.status.sold { background: var(--tint-accent); color: var(--accent-deep); border-color: transparent; }
.status.archived { color: var(--muted); }
.status.reserved { background: var(--tint-gold); color: var(--gold); border-color: transparent; }
.status.lost { background: var(--tint-danger); color: var(--danger); border-color: transparent; }
.status.damaged { background: #efe3fb; color: #6b3fa0; border-color: transparent; }
html[data-theme="dark"] .status.damaged { background: #2e2138; color: #c9a8ef; }

/* ---------- Дашборд ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 18px; }
.stat-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow-soft);
    transition: transform .16s ease, box-shadow .16s ease;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); color: inherit; }
.stat-card span { display: block; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.stat-card strong { display: block; font-size: 30px; line-height: 1; color: var(--brand-deep); }
.dashboard-cards .accent { background: linear-gradient(150deg, var(--card), var(--tint-accent)); }
.dashboard-cards .accent strong { color: var(--accent-deep); }
#salesChart { width: 100%; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Массовые действия ---------- */
.check-col { width: 34px; text-align: center; }
.row-check, #checkAll { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.bulk-bar {
    position: sticky; bottom: 10px; z-index: 30;
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    margin-top: 14px; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow);
}
.bulk-bar select, .bulk-bar input[type="text"], .bulk-bar input[type="number"] { width: auto; min-height: 40px; padding: 8px 10px; }
.bulk-bar .count-pill { min-width: 34px; text-align: center; padding: 6px 10px; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 800; font-variant-numeric: tabular-nums; }
.checkline { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-weight: 600; font-size: 14px; color: var(--muted); }
.checkline input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; }
.hidden-form { display: none; }

/* ---------- Мини-формы в строках ---------- */
.inline-details { display: inline-block; }
.inline-details > summary {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; min-height: 34px;
    padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--card-2); font-size: 13px; font-weight: 700;
}
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-details[open] > summary { background: var(--tint-brand); border-color: var(--brand); color: var(--brand-deep); }
.mini-form {
    position: absolute; z-index: 35; margin-top: 6px;
    display: grid; gap: 8px; min-width: 240px; padding: 12px;
    background: var(--card); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow);
    animation: drop-in .16s ease;
}
.mini-form input, .mini-form select { min-height: 40px; padding: 8px 10px; }

/* ---------- QR и ценники ---------- */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.qr-label {
    break-inside: avoid; background: var(--card); border: 1px dashed var(--line-strong); border-radius: 14px;
    padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 5px; min-height: 250px;
}
.qr-label img { width: 140px; height: 140px; object-fit: contain; background: #fff; border-radius: 6px; }
.qr-label strong { color: var(--brand-deep); }
.qr-label small { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; word-break: break-all; }

.tags-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 16px; }
.price-tag {
    display: grid; grid-template-columns: 1fr 76px; gap: 8px; align-items: center;
    padding: 12px; background: var(--card); border: 1.5px dashed var(--line-strong); border-radius: 10px;
    break-inside: avoid; page-break-inside: avoid;
}
.tag-text { min-width: 0; }
.tag-title { font-weight: 700; font-size: 15px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tag-author { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tag-cond { font-size: 12px; margin-top: 4px; }
.tag-price { font-size: 21px; font-weight: 700; color: var(--accent-deep); margin-top: 6px; }
.tag-qr img { width: 76px; height: 76px; display: block; background: #fff; border-radius: 4px; }
.tag-qr small { display: block; text-align: center; font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ---------- Сканер ---------- */
.scanner-box { display: grid; gap: 14px; }
#qrVideo { width: 100%; max-width: 520px; min-height: 240px; background: #0d1c16; border-radius: var(--radius); justify-self: start; }

/* ---------- Отчёт ---------- */
.report table { font-size: 14px; }
.import-result { padding: 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--tint-brand); margin-bottom: 16px; }
.cover-preview { width: 160px; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }

/* ---------- Кнопка «наверх» ---------- */
.to-top {
    position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 45;
    width: 46px; height: 46px; border-radius: 999px; border: 1px solid var(--line-strong);
    background: var(--card); color: var(--ink); font-size: 19px; cursor: pointer;
    box-shadow: var(--shadow); display: grid; place-items: center;
    opacity: 0; pointer-events: none; transform: translateY(8px);
    transition: opacity .2s ease, transform .2s ease;
}
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- Нижняя навигация админа (мобильная) ---------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: none; grid-template-columns: repeat(5, 1fr);
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 18px rgba(0,0,0,.08);
}
.bottom-nav a {
    display: grid; justify-items: center; gap: 2px;
    padding: 6px 2px; border-radius: var(--radius-s);
    font-size: 11px; font-weight: 700; color: var(--muted);
}
.bottom-nav a .bn-ico { font-size: 19px; line-height: 1; }
.bottom-nav a:hover, .bottom-nav a[aria-current="page"] { color: var(--brand-deep); background: var(--tint-brand); }


/* ---------- Прямое управление БД ---------- */
.db-toolbar { align-items: end; }
.db-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
}
.db-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}
.db-table th, .db-table td {
    padding: 11px 12px;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.db-table .col-id { width: 68px; }
.db-table .col-year { width: 92px; }
.db-table .col-date { width: 132px; }
.db-table .col-status { width: 110px; }
.db-table .col-actions { width: 128px; }
.db-table td.db-actions {
    position: sticky;
    right: 0;
    background: var(--card);
    box-shadow: -10px 0 14px color-mix(in srgb, var(--paper) 70%, transparent);
    z-index: 2;
}
.db-table th.col-actions {
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--card-2);
}
.db-cell-muted { color: var(--muted); }
.db-edit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.db-raw-row { margin-top: 14px; }
.db-raw-row summary { cursor: pointer; color: var(--muted); font-weight: 700; }
.db-raw-row pre {
    margin: 10px 0 0;
    padding: 12px;
    border-radius: var(--radius-s);
    background: var(--card-2);
    border: 1px solid var(--line);
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.diagnostics-box {
    margin-top: 14px;
}
.diagnostics-box h3 {
    margin: 0 0 8px;
}
.diagnostics-box pre {
    margin: 0;
    padding: 12px;
    border-radius: var(--radius-s);
    background: var(--card-2);
    border: 1px solid var(--line);
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ============================================================
   Адаптив
   ============================================================ */
/* Средний экран: текст в nav-link скрывается, только иконки */
@media (max-width: 1040px) {
    .nav-link .nl { display: none; }
    .nav-link { padding: 6px 8px; gap: 0; }
    .nav-link .ni { font-size: 18px; }
    .brand { font-size: 18px; }
    .brand span:last-child { display: none; }
}
@media (max-width: 960px) {
    .nav-link { padding: 5px 6px; }
    .nav-icon-btn { width: 32px; height: 32px; font-size: 15px; }
    .nav-sep { margin: 0 2px; }
}

@media (max-width: 1100px) {
    .catalog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .filters, .filters.compact { grid-template-columns: 1fr 1fr; }
    .filters input[type="search"] { grid-column: 1 / -1; }
    .book-detail { grid-template-columns: 260px 1fr; gap: 24px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .section-title { flex-direction: column; }
    .grid-form { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .container { width: min(100% - 24px, 1180px); }
    .header-inner { min-height: 54px; gap: 8px; }
    .brand { font-size: 19px; }
    .brand-mark { width: 38px; height: 38px; }
    .nav-link, .nav-icon-btn, .nav-sep, .nav-more { display: none; }
    .nav-logout { display: none; }
    .nav-burger { display: block; }
    .main { padding: 20px 0 96px; }
    body.has-bottom-nav .main { padding-bottom: 120px; }
    .bottom-nav { display: grid; }
    body.has-bottom-nav .to-top { bottom: calc(78px + env(safe-area-inset-bottom)); }

    .hero, .admin-head { align-items: flex-start; flex-direction: column; padding: 20px; gap: 14px; }
    .hero .btn, .admin-head .btn { width: 100%; }
    .actions { width: 100%; }
    .actions .btn { flex: 1 1 160px; }
    .filters, .filters.compact { grid-template-columns: 1fr; padding: 12px; gap: 10px; }
    .filters .btn { width: 100%; }
    .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .book-card-body { padding: 13px 13px 14px 17px; }
    .book-detail { grid-template-columns: 1fr; padding: 18px; gap: 18px; }
    .detail-cover { max-width: 280px; width: 100%; justify-self: center; }
    .copy-card { grid-template-columns: 1fr; gap: 6px; }
    .copy-card small { grid-column: auto; }
    .form-grid { grid-template-columns: 1fr; }
    .form-actions .btn, .form-actions button, .form-actions a { width: 100%; }
    .cover-preview { width: 130px; }
    .quick-actions form { flex: 1 1 100%; }
    .admin-head .actions, .admin-head .actions .btn, .admin-head .actions form, .admin-head .actions button { width: 100%; }
    .mini-form { position: static; min-width: 0; width: 100%; }
    .bulk-bar { bottom: calc(70px + env(safe-area-inset-bottom)); }
    .tags-grid { grid-template-columns: 1fr 1fr; }
    .nav-drop { position: fixed; left: 12px; right: 12px; top: 58px; min-width: 0; max-height: 72vh; overflow: auto; }

    /* Таблицы → карточки */
    .table-wrap { overflow: visible; background: transparent; border: 0; border-radius: 0; box-shadow: none; }
    .admin-table { display: block; min-width: 0; border-collapse: separate; }
    .admin-table thead { display: none; }
    .admin-table tbody { display: grid; gap: 12px; }
    .admin-table tr { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-soft); overflow: hidden; }
    .admin-table td {
        display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 10px;
        padding: 12px 14px; border-bottom: 1px solid var(--line);
        min-height: 44px; align-items: start; overflow-wrap: anywhere;
    }
    .admin-table td:last-child { border-bottom: 0; }
    .admin-table td::before {
        content: attr(data-label); color: var(--muted); font-weight: 700;
        font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    }
    .admin-table td.row-actions, .admin-table td.check-col { display: block; }
    .admin-table td.row-actions::before { display: block; margin-bottom: 8px; }
    .admin-table td.check-col { width: auto; }
    .admin-table td.check-col::before { content: none; }
    .row-actions { gap: 8px; }
    .row-actions a, .row-actions button { min-height: 40px; padding: 8px 12px; }
    .db-table { table-layout: auto; }
    .db-table td.db-actions, .db-table th.col-actions { position: static; box-shadow: none; }
    .db-edit-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .container { width: min(100% - 20px, 1180px); }
    h1 { font-size: clamp(25px, 8vw, 34px); }
    h2 { font-size: 18px; }
    .catalog-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .book-card h2 { font-size: 15px; }
    .price { font-size: 16px; padding: 2px 9px; }
    .card-bottom { align-items: flex-start; flex-direction: column; gap: 6px; }
    .catalog-grid.as-list .cover { flex-basis: 80px; }
    .panel, .empty { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card strong { font-size: 25px; }
    .admin-table td { grid-template-columns: 1fr; gap: 4px; }
    .admin-table td::before { margin-bottom: 2px; }
    .row-actions a, .row-actions button { flex: 1 1 calc(50% - 8px); justify-content: center; }
    .site-footer { font-size: 14px; }
    .tags-grid { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
    .brand { font-size: 17px; }
    .catalog-grid { grid-template-columns: 1fr; }
    .row-actions a, .row-actions button { flex-basis: 100%; }
}

/* ============================================================
   Печать
   ============================================================ */
@media print {
    .site-header, .filters, .admin-head, .no-print, .bulk-bar, .top-nav, .btn,
    form.filters, .flash, .nav-logout, .to-top, .bottom-nav, .genre-chips, .results-bar { display: none !important; }
    body { background: #fff; color: #000; }
    .container { width: 100%; max-width: none; }
    .main { padding: 0; }
    .tags-grid { grid-template-columns: repeat(3, 1fr); gap: 6mm; }
    .price-tag { border: 1px dashed #777; box-shadow: none; background: #fff; }
    .qr-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .qr-label { border: 1px solid #222; border-radius: 0; page-break-inside: avoid; background: #fff; }
    .qr-label img { width: 120px; height: 120px; }
}

.inventory-sheet-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.inventory-sign { min-width: 260px; text-align: right; }
.inventory-check { display: inline-block; width: 18px; height: 18px; border: 1.5px solid var(--ink); border-radius: 3px; }
.inventory-note-line { display: block; min-width: 110px; height: 22px; border-bottom: 1px solid var(--line-strong); }
.inventory-print-table th:first-child, .inventory-print-table td:first-child { width: 34px; text-align: center; }

@media print {
    .inventory-sheet { padding: 0; border: 0; box-shadow: none; }
    .inventory-sheet-head { color: #000; margin-bottom: 8mm; }
    .inventory-print-wrap { overflow: visible; }
    .inventory-print-table { display: table; font-size: 10.5px; color: #000; }
    .inventory-print-table thead { display: table-header-group; }
    .inventory-print-table tbody { display: table-row-group; }
    .inventory-print-table tr { display: table-row; break-inside: avoid; page-break-inside: avoid; }
    .inventory-print-table th, .inventory-print-table td { display: table-cell; padding: 5px; border: 1px solid #777; vertical-align: top; }
    .inventory-print-table td::before { display: none; }
    .inventory-check { border-color: #000; }
    .inventory-note-line { border-color: #777; }
}

/* Утилитарные отступы (CSP запрещает инлайн-стили) */
.mt-18 { margin-top: 18px; }
.my-16 { margin: 16px 0; }
.w-130 { max-width: 130px; }
.notify-matrix { min-width: 0 !important; }

/* ===== Лист QR-наклеек под вырезание ===== */
.cut-sheet { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--card); }
.cut-cell {
    border: 1.5px dashed var(--line-strong);
    padding: 10px 8px; text-align: center; vertical-align: top;
    break-inside: avoid; page-break-inside: avoid;
}
.cut-qr { display: block; margin: 0 auto 6px; background: #fff; border-radius: 4px; }
.cut-s .cut-qr { width: 96px; height: 96px; }
.cut-m .cut-qr { width: 120px; height: 120px; }
.cut-l .cut-qr { width: 150px; height: 150px; }
.cut-title { display: block; font-size: 12.5px; line-height: 1.25; font-weight: 700; }
.cut-author { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cut-meta { display: block; font-size: 10.5px; color: var(--muted); margin-top: 3px; }
@media (max-width: 760px) {
    .cut-sheet, .cut-sheet tbody, .cut-sheet tr { display: block; }
    .cut-sheet td { display: inline-block; width: calc(50% - 4px); }
}
@media print {
    .cut-sheet { background: #fff; }
    .cut-cell { border-color: #555; }
    .cut-title, .cut-author, .cut-meta { color: #000; }
    .cut-author, .cut-meta { color: #444; }
}

/* ===== Каталог-список без обложек ===== */
.catalog-list { display: grid; gap: 8px; }
.list-row {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 13px 16px; background: var(--card);
    border: 1px solid var(--line); border-left: 5px solid var(--brand);
    border-radius: 12px;
    transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.list-row:hover { transform: translateX(3px); box-shadow: var(--shadow-soft); border-color: var(--line-strong); color: inherit; }
.list-main { display: grid; gap: 2px; min-width: 0; }
.list-main strong { font-family: var(--font-display); font-size: 16.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-main .muted { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-meta { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.list-meta .price { font-size: 16px; padding: 2px 10px; }
.view-toggle a {
    display: inline-flex; align-items: center; min-height: 38px; padding: 6px 14px;
    color: var(--muted); font-weight: 700; font-size: 14px;
}
.view-toggle a.active { background: var(--brand); color: #fff; }
.view-toggle a:hover:not(.active) { background: var(--tint-brand); color: var(--brand-deep); }
@media (max-width: 600px) {
    .list-row { flex-direction: column; align-items: stretch; gap: 8px; }
    .list-meta { justify-content: space-between; }
}

/* ===== Сканер QR ===== */
.scanner-preview { max-width: 100%; }
#qrVideo { width: 100%; max-width: 520px; max-height: 360px; border-radius: var(--radius); background: #0d1c16; display: block; object-fit: cover; }
#qrCanvas { display: none; }
#uploadQrLabel { cursor: pointer; position: relative; }
#uploadQrFile { position: absolute; left: -9999px; width: 1px; height: 1px; }

/* ===== Виджет обложки ===== */
.form-fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin: 0; }
.form-fieldset legend { font-weight: 700; padding: 0 6px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.cover-upload-widget { display: grid; gap: 10px; }
.cover-upload-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.cover-preview-wrap { position: relative; display: inline-block; }
.cover-preview-wrap img { max-width: 200px; max-height: 260px; border-radius: 12px; border: 1px solid var(--line); display: block; object-fit: cover; }
.cover-clear-btn {
    position: absolute; top: -8px; right: -8px;
    width: 26px; height: 26px; border-radius: 999px;
    background: var(--danger); color: #fff; border: 2px solid var(--card);
    font-size: 13px; cursor: pointer; display: grid; place-items: center;
    line-height: 1;
}
.camera-box { display: grid; gap: 8px; }
.camera-box video { width: 100%; max-width: 420px; border-radius: 12px; background: #0d1c16; max-height: 280px; object-fit: cover; }
.cover-upload-widget .muted.small { font-size: 13px; }

/* Попап быстрой загрузки обложки из каталога */
.quick-cover-popup {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: drop-in .18s ease;
}
.quick-cover-inner {
    background: var(--card); border-radius: var(--radius); padding: 22px;
    box-shadow: var(--shadow); max-width: 420px; width: 100%;
    display: grid; gap: 8px;
}
.quick-cover-inner strong { font-size: 16px; }


/* ============================================================
   Финальная вычитка интерфейса: защита от «уплывания» блоков
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 78px; }
body { min-width: 320px; }
input, select, textarea, button { max-width: 100%; }
textarea { resize: vertical; }
pre { max-width: 100%; }
.card, .panel, .empty, .hero, .admin-head, .table-wrap, .flash, .notice { overflow-wrap: anywhere; }
.actions, .row-actions, .quick-actions, .form-actions, .bulk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions form, .row-actions form, .quick-actions form, .form-actions form { margin: 0; }
.row-actions a, .row-actions button, .quick-actions button, .quick-actions a { white-space: nowrap; }

.site-header { box-shadow: 0 1px 0 color-mix(in srgb, var(--line) 65%, transparent); }
.header-inner { position: relative; }
.top-nav { isolation: isolate; }
.menu-btn, .nav-link, .theme-toggle, .burger-btn { touch-action: manipulation; }
.nav-drop { max-height: min(70vh, 560px); overflow: auto; overscroll-behavior: contain; }
.nav-drop form { margin: 0; }
.nav-drop button { color: inherit; font-family: inherit; }

/* Публичный каталог */
.catalog-grid { align-items: stretch; }
.book-card { min-width: 0; }
.book-card h2, .book-title, .tag-title { overflow-wrap: anywhere; hyphens: auto; }
.cover img, .detail-cover img, .cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.no-cover img, .detail-cover.no-cover img { object-fit: contain; padding: 10%; }

/* Админские формы */
.form-grid label, .grid-form label, .form-stack label, .db-edit-grid label { min-width: 0; }
.form-grid input, .form-grid select, .form-grid textarea,
.grid-form input, .grid-form select, .grid-form textarea,
.form-stack input, .form-stack select, .form-stack textarea,
.db-edit-grid input, .db-edit-grid select, .db-edit-grid textarea {
    width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; }

/* Таблицы: десктоп — читаемо, телефон — карточки */
.table-wrap { max-width: 100%; }
.admin-table { max-width: 100%; }
.admin-table td, .admin-table th { overflow-wrap: anywhere; }
.admin-table td form { margin: 0; }
.admin-table input, .admin-table select, .admin-table textarea { width: 100%; min-width: 0; }
.admin-table .row-actions input { flex: 1 1 140px; }

/* Прямое управление БД: компактный безопасный режим */
.db-table-wrap { border-radius: var(--radius); }
.db-table { min-width: 760px; }
.db-table td, .db-table th { line-height: 1.35; }
.db-table td:not(.db-actions) { max-height: 96px; }
.db-actions a { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; padding: 7px 12px; border-radius: 999px; background: var(--tint-brand); color: var(--brand-deep); font-weight: 700; }
.db-raw-row pre { max-height: 420px; }

/* Печать: скрыть управление и не ломать лист */
@media print {
    body { background: #fff !important; color: #111 !important; }
    .site-header, .site-footer, .bottom-nav, .to-top, .no-print, .filters, .actions, .row-actions, .quick-actions, .form-actions { display: none !important; }
    .container { width: 100% !important; }
    .panel, .card, .table-wrap { box-shadow: none !important; border-color: #ddd !important; }
}

@media (max-width: 1180px) {
    .top-nav { gap: 1px; }
    .menu-btn { padding-inline: 9px; }
}

@media (max-width: 760px) {
    html { scroll-padding-top: 64px; }
    .site-header { position: sticky; }
    .brand span:last-child { display: inline; max-width: 42vw; }
    .theme-toggle { width: 38px; height: 38px; }
    .nav-burger { margin-left: 2px; }
    .nav-drop { top: calc(58px + env(safe-area-inset-top)); }
    .hero, .admin-head { margin-bottom: 16px; }
    .admin-head .actions, .hero .actions { display: grid; grid-template-columns: 1fr; }
    .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .book-card h2 { min-height: 0; }
    .table-wrap { overflow: visible; }
    .admin-table tr { margin: 0; }
    .admin-table td { word-break: break-word; }
    .admin-table input, .admin-table select, .admin-table textarea { min-width: 0; }
    .db-table-wrap { overflow: visible; }
    .db-table { min-width: 0; }
    .db-table td:not(.db-actions) { max-height: none; }
    .db-toolbar { display: grid; grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
    .container { width: min(100% - 16px, 1180px); }
    .brand span:last-child { max-width: 34vw; }
    .catalog-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .row-actions a, .row-actions button { flex-basis: 100%; }
}

.input-action { display: flex; gap: 8px; align-items: stretch; }
.input-action input { flex: 1 1 auto; min-width: 0; }
.input-action .btn { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 560px) { .input-action { flex-direction: column; } .input-action .btn { width: 100%; } }


.isbn-inline-scanner{grid-column:1/-1;margin-top:8px;border:1px solid var(--border);border-radius:18px;padding:12px;background:rgba(255,255,255,.04)}
.isbn-camera-frame{position:relative;overflow:hidden;border-radius:14px;background:#0b0f0d}
.isbn-inline-scanner video{display:block;width:100%;max-height:360px;object-fit:contain;background:#0b0f0d}
.isbn-scan-guide{position:absolute;left:8%;right:8%;top:36%;height:28%;border:2px solid rgba(255,255,255,.9);border-radius:12px;box-shadow:0 0 0 999px rgba(0,0,0,.2);pointer-events:none}
.isbn-inline-scanner .scanner-line{display:flex;gap:10px;align-items:center;justify-content:space-between;flex-wrap:wrap;margin-top:8px}
.isbn-inline-scanner canvas{display:none}
@media (max-width:720px){.input-action{display:grid;grid-template-columns:1fr auto auto;gap:8px}.isbn-inline-scanner video{max-height:300px}}
@media (max-width:560px){.input-action{grid-template-columns:1fr 1fr}.input-action input{grid-column:1/-1}.input-action .btn{width:100%}}

/* ISBN lookup status: appears only during search/result, then disappears without keeping layout space. */
#isbnLookupStatus[hidden] { display: none !important; }
#isbnLookupStatus {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
}
#isbnLookupStatus.is-working::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: isbnSpin .75s linear infinite;
}
#isbnLookupStatus.is-ok { border-color: rgba(57, 197, 125, .5); color: #bdf7d7; }
#isbnLookupStatus.is-error { border-color: rgba(255, 115, 72, .55); color: #ffd2c4; }
@keyframes isbnSpin { to { transform: rotate(360deg); } }
