:root {
    --green: #19875d;
    --green-dark: #0f5f43;
    --orange: #ff6b35;
    --orange-dark: #e45723;
    --bg: #f8f5ee;
    --card: #ffffff;
    --text: #27231f;
    --muted: #756d63;
    --line: #e4ded3;
    --shadow: 0 14px 34px rgba(31, 45, 39, .10);
    --shadow-soft: 0 8px 22px rgba(31, 45, 39, .08);
    --radius: 18px;
    --tap: 46px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    min-width: 320px;
    margin: 0;
    font-family: Arial, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--green); }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; font-size: 16px; }
button, .btn, a { -webkit-tap-highlight-color: transparent; }

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(248,245,238,.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
}
.header-inner {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    font-weight: 800;
    font-size: 24px;
}
.brand span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.brand-mark {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    box-shadow: var(--shadow-soft);
}
.top-nav {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    font-weight: 700;
    flex-wrap: wrap;
}
.top-nav a,
.nav-logout button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 8px 10px;
}
.top-nav a:hover,
.nav-logout button:hover {
    background: #ffffff;
    color: var(--green-dark);
    text-decoration: none;
}

.main {
    padding: 30px 0 60px;
    min-height: calc(100vh - 140px);
}
.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: 28px;
    border-radius: var(--radius);
    background: radial-gradient(circle at top left, #e9fff5, #fff 60%);
    box-shadow: var(--shadow);
}
.eyebrow {
    margin: 0 0 8px;
    color: var(--green);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 12px;
}
h1 { margin: 0 0 12px; font-size: clamp(28px, 4vw, 48px); line-height: 1.05; }
h2 { margin: 0 0 10px; font-size: 20px; line-height: 1.25; }
p { line-height: 1.55; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    line-height: 1.2;
    text-align: center;
}
.btn.primary { border-color: var(--orange); background: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-dark); color: #fff; }
.btn.ghost { background: transparent; }

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) minmax(160px, 1fr) auto auto;
    gap: 12px;
    margin-bottom: 26px;
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.filters.compact { grid-template-columns: minmax(220px, 1fr) auto auto; }
input,
select,
textarea {
    width: 100%;
    min-height: var(--tap);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
input[type="file"] { padding: 9px 12px; }

.catalog-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.book-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.cover { display: block; aspect-ratio: 3 / 4; background: #efe8dc; overflow: hidden; }
.cover img,
.detail-cover img,
.cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.genre-pill {
    align-self: flex-start;
    padding: 5px 10px;
    border-radius: 999px;
    background: #e7f8f1;
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 800;
}
.muted,
.meta { color: var(--muted); margin: 0; }
.card-bottom { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.price { color: var(--orange-dark); font-size: 20px; }
.count { color: var(--muted); white-space: nowrap; }

.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
.pagination a { min-width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; background: #fff; }
.pagination a.active { background: var(--green); color: #fff; border-color: var(--green); }
.empty,
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.panel.narrow { max-width: 560px; margin: 0 auto; }

.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);
}
.detail-cover { border-radius: 18px; overflow: hidden; background: #efe8dc; align-self: start; }
.author { font-size: 22px; margin: 0 0 8px; }
.copies-list { display: grid; gap: 10px; }
.copy-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; grid-template-columns: 120px 1fr; gap: 12px; background: #fffaf2; }
.copy-card small { grid-column: 2; color: var(--muted); }

.flash { padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; border: 1px solid var(--line); background: #fff; }
.flash.success { border-color: #b8e1cd; background: #effaf5; }
.flash.error { border-color: #fac2b4; background: #fff2ed; }
.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; }
.cover-preview { width: 160px; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }

.table-wrap {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    -webkit-overflow-scrolling: touch;
}
.admin-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.admin-table th,
.admin-table td { padding: 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th { background: #f3efe6; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row-actions form { display: inline; }
.row-actions a,
.row-actions button {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    border: 0;
    border-radius: 999px;
    background: #fff6ef;
    padding: 7px 10px;
    color: var(--orange-dark);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    touch-action: manipulation;
}
.row-actions a:hover,
.row-actions button:hover { background: #ffe3d5; color: var(--orange-dark); }
.status { display: inline-flex; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; background: #eee; }
.status.available { background: #e7f8f1; color: var(--green-dark); }
.status.sold { background: #fff1e8; color: var(--orange-dark); }
.status.archived { background: #eee; color: #666; }
.import-result { padding: 14px; border-radius: 14px; border: 1px solid #b8e1cd; background: #effaf5; margin-bottom: 16px; }
code { background: #f2eee5; padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }

.nav-logout { display: inline; margin: 0; }
.nav-logout button { border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }

@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; }
}

@media (max-width: 760px) {
    .container { width: min(100% - 24px, 1180px); }
    .header-inner { min-height: 64px; gap: 12px; padding: 10px 0; align-items: flex-start; flex-direction: column; }
    .brand { font-size: 20px; }
    .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
    .top-nav { width: 100%; justify-content: flex-start; gap: 8px; }
    .top-nav a,
    .nav-logout button { background: #fff; min-height: 40px; padding: 8px 12px; }
    .main { padding: 20px 0 44px; }
    .hero,
    .admin-head { align-items: flex-start; flex-direction: column; padding: 20px; gap: 16px; }
    .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: 14px; }
    .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; }

    .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: 800;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: .04em;
    }
    .admin-table td.row-actions { display: block; }
    .admin-table td.row-actions::before { display: block; margin-bottom: 8px; }
    .row-actions { gap: 8px; }
    .row-actions a,
    .row-actions button { min-height: 40px; padding: 8px 12px; }
}

@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; }
    .card-bottom { align-items: flex-start; flex-direction: column; gap: 4px; }
    .price { font-size: 22px; }
    .panel,
    .empty { padding: 16px; }
    .admin-table td { grid-template-columns: 1fr; gap: 4px; }
    .admin-table td::before { margin-bottom: 2px; }
    .row-actions a,
    .row-actions button { width: 100%; justify-content: center; }
    .site-footer { font-size: 14px; }
}

@media (max-width: 360px) {
    .brand { font-size: 18px; }
    .top-nav a,
    .nav-logout button { width: 100%; justify-content: center; }
}

.section-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.section-title h1 { margin-bottom: 0; }
.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);
}
.stat-card span {
    display: block;
    color: var(--muted);
    font-weight: 800;
    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(--green-dark);
}
.quick-actions form { flex: 1 1 120px; }
.row-actions .quick-sell,
.quick-actions .quick-sell {
    background: var(--orange);
    color: #fff;
}
.row-actions .quick-sell:hover,
.quick-actions .quick-sell:hover {
    background: var(--orange-dark);
    color: #fff;
}
.btn.danger,
.row-actions .danger,
button.danger {
    border-color: #c83f22;
    background: #c83f22;
    color: #fff;
}
.btn.danger:hover,
.row-actions .danger:hover,
button.danger:hover {
    background: #a8321b;
    color: #fff;
}
.danger-panel {
    border-color: #f2b7a7;
    background: linear-gradient(180deg, #fff, #fff7f3);
}
.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-weight: 700;
}
.checkline input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: 20px;
    flex: 0 0 auto;
}
.admin-table .status { margin: 2px 4px 2px 0; }
.book-card .cover,
.detail-cover {
    background: linear-gradient(135deg, #f4efe4, #e7dcc9);
}
.top-nav a,
.nav-logout button {
    white-space: nowrap;
}

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .section-title { flex-direction: column; }
}

@media (max-width: 760px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .quick-actions form { flex: 1 1 100%; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card strong { font-size: 26px; }
}

/* Пагинация — оконная */
.pagination .page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; padding: .25rem .5rem; border-radius: var(--radius, 6px); text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--line); font-size: .9rem; }
.pagination .page-link.active { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
.pagination .page-link:hover:not(.active) { background: var(--bg); }
.pagination .page-gap { display: inline-flex; align-items: center; padding: 0 .25rem; color: var(--muted); }

/* Админские улучшения: отчёты, QR, роли */
.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:700; }
.grid-form input, .grid-form select, .grid-form textarea { width:100%; }
.narrow { max-width: 860px; margin-left:auto; margin-right:auto; }
.dashboard-cards .accent { background: linear-gradient(135deg, #fff4ed, #ffffff); border-color:#ffd7c5; }
.report table { font-size: 14px; }
#salesChart { width:100%; max-width:100%; background:#fff; border:1px solid var(--line); border-radius:16px; }
.qr-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.qr-label { break-inside: avoid; background:#fff; border:1px dashed #9ab8a7; 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; }
.qr-label strong { color:var(--green-dark); }
.qr-label small { color:var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; word-break: break-all; }
.scanner-box { display:grid; gap:14px; }
#qrVideo { width:100%; max-width:520px; min-height:240px; background:#0d1c16; border-radius:18px; justify-self:start; }
.item-focus { border-color:#c9e5d2; background:linear-gradient(180deg,#fff,#f5fbf7); }
.danger-zone { border-color:#f2b7a7; background:#fff8f5; }
.admin-table input, .admin-table select { min-width: 120px; }
@media (max-width: 720px) { .grid-form { grid-template-columns: 1fr; } .admin-head .actions { width:100%; } .admin-head .actions .btn, .admin-head .actions form { width:100%; } .admin-head .actions button { width:100%; } }
@media print { .site-header, .no-print, .flash, .admin-head .actions, .top-nav, .nav-logout { display:none !important; } body { background:#fff; } .container { max-width:none; } .main { padding:0; } .qr-grid { grid-template-columns: repeat(3, 1fr); gap:8px; } .qr-label { border:1px solid #222; border-radius:0; page-break-inside:avoid; } .qr-label img { width:120px; height:120px; } }
