:root {
    --bg: #f6f6f3;
    --card: #ffffff;
    --text: #1d1f1d;
    --muted: #686d68;
    --border: #e1e3df;
    --accent: #21634f;
    --accent-dark: #174839;
    --danger: #a52c2c;
    --shadow: 0 6px 24px rgba(0,0,0,.06);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; }

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

.narrow { width: min(720px, calc(100% - 28px)); }

.site-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-inner {
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    text-decoration: none;
}

.tagline {
    margin-top: 3px;
    color: var(--muted);
    font-size: .9rem;
}

.selected-top {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 999px;
    padding: 9px 13px;
    cursor: pointer;
    font-weight: 700;
}

.notice {
    margin: 22px 0 16px;
    padding: 14px 16px;
    border: 1px solid #ddd7b8;
    background: #fffdf0;
    border-radius: 12px;
    line-height: 1.5;
    font-size: .95rem;
}

.catalog-tools {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 220px auto auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 13px;
}

.catalog-tools label span,
.form-field > span {
    display: block;
    font-size: .78rem;
    color: var(--muted);
    margin: 0 0 5px 2px;
    font-weight: 700;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #cfd3ce;
    background: #fff;
    border-radius: 9px;
    padding: 11px 12px;
    font: inherit;
    color: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(33, 99, 79, .18);
    border-color: var(--accent);
}

.btn {
    border: 1px solid #bfc4bf;
    background: #fff;
    color: #222;
    border-radius: 9px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover { border-color: #939a94; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-muted { background: #f5f6f4; }

.btn-danger {
    background: #fff;
    color: var(--danger);
    border-color: #e0baba;
}

.btn-wide { width: 100%; }

.results-meta {
    color: var(--muted);
    font-size: .92rem;
    margin-bottom: 14px;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
    gap: 16px;
    padding-bottom: 28px;
}

.book-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 13px;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.book-image-link {
    display: block;
    aspect-ratio: 4 / 5;
    background: #eceeea;
    overflow: hidden;
}

.book-image-link img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.image-placeholder {
    width: 100%;
    height: 100%;
    min-height: 220px;
    display: grid;
    place-items: center;
    color: #8b8e8b;
    background: #eceeea;
}

.book-body {
    padding: 13px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    height: 100%;
}

.item-code {
    display: inline-flex;
    width: fit-content;
    background: #eef4f1;
    color: var(--accent-dark);
    border-radius: 999px;
    padding: 4px 8px;
    font-size: .76rem;
    font-weight: 900;
    letter-spacing: .04em;
}

.item-code.big {
    font-size: .86rem;
    padding: 5px 9px;
}

.book-title {
    font-weight: 800;
    line-height: 1.3;
    text-decoration: none;
}

.book-title:hover { text-decoration: underline; }

.book-meta {
    color: var(--muted);
    font-size: .85rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.card-bottom {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding-top: 6px;
}

.price {
    font-size: 1.1rem;
    font-weight: 900;
}

.btn-select {
    padding: 8px 10px;
    font-size: .88rem;
}

.btn-select.selected,
[data-select-item].selected {
    background: #e7f2ed;
    border-color: #9dc4b6;
    color: var(--accent-dark);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    padding: 12px 0 92px;
    color: var(--muted);
}

.pagination a {
    color: var(--accent);
    font-weight: 750;
}

.empty-state {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    margin: 28px 0;
}

.mt { margin-top: 18px; }

.selection-bar {
    position: fixed;
    z-index: 30;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    width: min(720px, calc(100% - 24px));
    background: #1f2421;
    color: #fff;
    border-radius: 14px;
    padding: 10px 12px;
    box-shadow: 0 12px 38px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.selection-bar[hidden],
.modal-backdrop[hidden] {
    display: none !important;
}

.text-button {
    border: 0;
    background: transparent;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
    padding: 3px 5px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0,0,0,.48);
    display: grid;
    place-items: center;
    padding: 18px;
}

.selection-modal {
    background: #fff;
    width: min(620px, 100%);
    max-height: min(82vh, 720px);
    overflow: auto;
    border-radius: 14px;
    box-shadow: 0 20px 70px rgba(0,0,0,.28);
    padding: 18px;
}

.modal-head,
.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.modal-head {
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.modal-head h2 { margin: 0; font-size: 1.2rem; }

.modal-close {
    border: 0;
    background: #f2f3f1;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
}

.selection-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
}

.selection-row-right {
    text-align: right;
    white-space: nowrap;
}

.selection-row-right .text-button {
    color: var(--danger);
    display: block;
    margin-left: auto;
}

.modal-actions {
    margin-top: 16px;
}

.empty-mini {
    color: var(--muted);
    padding: 20px 0;
    text-align: center;
}

.detail-wrap { padding-bottom: 90px; }

.back-link {
    display: inline-block;
    margin: 22px 0 16px;
    color: var(--accent);
    font-weight: 750;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr);
    gap: 30px;
    align-items: start;
}

.gallery,
.detail-info {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.gallery { padding: 12px; }

.main-photo {
    width: 100%;
    min-height: 420px;
    max-height: 720px;
    display: grid;
    place-items: center;
    background: #f0f1ef;
    border-radius: 9px;
    overflow: hidden;
}

.main-photo img {
    width: 100%;
    max-height: 720px;
    object-fit: contain;
    display: block;
}

.thumb-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
    gap: 9px;
    margin-top: 10px;
}

.thumb-button {
    border: 2px solid transparent;
    background: #f0f1ef;
    border-radius: 8px;
    overflow: hidden;
    padding: 0;
    aspect-ratio: 1;
    cursor: pointer;
}

.thumb-button.active { border-color: var(--accent); }

.thumb-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.detail-info {
    padding: 22px;
    position: sticky;
    top: 94px;
}

.detail-info h1 {
    margin: 12px 0 6px;
    line-height: 1.22;
    font-size: clamp(1.5rem, 3vw, 2.15rem);
}

.detail-price {
    font-size: 1.55rem;
    font-weight: 900;
    margin: 12px 0 20px;
}

.detail-meta {
    margin: 0 0 22px;
}

.detail-meta div {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}

.detail-meta dt {
    color: var(--muted);
    font-weight: 700;
}

.detail-meta dd {
    margin: 0;
    font-weight: 650;
}

/* Admin */
.admin-shell {
    width: min(1160px, calc(100% - 28px));
    margin: 0 auto;
    padding-bottom: 60px;
}

.admin-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 20px 0;
}

.admin-top h1 { margin: 0; font-size: 1.45rem; }

.admin-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.flash {
    margin-bottom: 14px;
    border-radius: 9px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: #fff;
}

.flash.success {
    border-color: #b8d9cb;
    background: #f1faf6;
}

.flash.error {
    border-color: #e1bbbb;
    background: #fff4f4;
}

.admin-search {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    border-bottom: 1px solid var(--border);
    padding: 10px 8px;
    vertical-align: top;
}

.admin-table th {
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.status {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: .75rem;
    font-weight: 800;
}

.status.active {
    background: #e9f5ef;
    color: #175b43;
}

.status.sold {
    background: #f1f1f1;
    color: #666;
}

.table-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.table-actions .btn {
    padding: 6px 9px;
    font-size: .8rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-field.full { grid-column: 1 / -1; }

.form-help {
    color: var(--muted);
    font-size: .82rem;
    margin-top: 6px;
    line-height: 1.4;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 18px;
}

.existing-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.existing-image {
    border: 1px solid var(--border);
    border-radius: 9px;
    overflow: hidden;
    background: #fff;
}

.existing-image img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.existing-image .image-action {
    padding: 7px;
}

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.login-card h1 { margin-top: 0; }

@media (max-width: 760px) {
    .catalog-tools {
        grid-template-columns: 1fr 1fr;
    }

    .search-field { grid-column: 1 / -1; }

    .book-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .book-body { padding: 10px; }
    .book-title { font-size: .93rem; }
    .book-meta { font-size: .78rem; }
    .card-bottom { align-items: flex-end; }
    .price { font-size: 1rem; }
    .btn-select { padding: 7px 8px; }

    .detail-layout {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .detail-info { position: static; }

    .main-photo { min-height: 300px; }

    .form-grid { grid-template-columns: 1fr; }
    .form-field.full { grid-column: auto; }

    .admin-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 430px) {
    .container { width: min(100% - 18px, 1240px); }
    .tagline { display: none; }
    .catalog-tools { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .book-grid { gap: 8px; }
    .book-image-link { aspect-ratio: 3 / 4; }
    .book-meta strong { display: none; }
    .card-bottom {
        flex-direction: column;
        align-items: stretch;
    }
    .price { align-self: flex-start; }
    .btn-select { width: 100%; }
}
