:root {
    --bg: #f5f1ea;
    --panel: #fffdf8;
    --ink: #241c15;
    --muted: #776b5d;
    --line: #ddd2c4;
    --accent: #6f4e37;
    --danger: #9f2d20;
    --shadow: 0 10px 30px rgba(40, 30, 20, .06);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.45;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: clamp(1rem, 2vw, 1.5rem) clamp(1rem, 3vw, 2rem);
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.25rem, 2.4vw, 1.8rem);
}

.topbar p {
    margin: .25rem 0 0;
    color: var(--muted);
    font-size: clamp(.9rem, 1.8vw, 1rem);
}

.container {
    width: min(1440px, calc(100% - clamp(1rem, 4vw, 3rem)));
    margin: clamp(1rem, 2.5vw, 1.75rem) auto;
}

.narrow {
    width: min(920px, calc(100% - clamp(1rem, 4vw, 3rem)));
}

.search-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: clamp(.85rem, 2vw, 1rem);
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.search {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 160px auto auto;
    gap: .65rem;
    align-items: end;
    margin-bottom: .9rem;
}

input,
textarea,
button,
select {
    font: inherit;
}

input,
textarea,
select {
    width: 100%;
    min-height: 44px;
    padding: .72rem .8rem;
    border: 1px solid var(--line);
    border-radius: .65rem;
    background: white;
}

textarea {
    min-height: 140px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 44px;
    padding: .7rem .9rem;
    border: 0;
    border-radius: .65rem;
    background: #e7dccd;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
}

.button.primary {
    background: var(--accent);
    color: white;
}

.button.danger {
    background: var(--danger);
    color: white;
}

.button.muted {
    background: transparent;
    border: 1px solid var(--line);
}

.button.current {
    background: var(--accent);
    color: white;
    cursor: default;
}

.button.disabled {
    opacity: .45;
    cursor: not-allowed;
}

.per-page {
    min-width: 150px;
    display: grid;
    gap: .25rem;
}

.per-page span,
.filters span {
    font-size: .85rem;
    font-weight: 650;
    color: var(--muted);
}

.filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .75rem;
    border-top: 1px solid var(--line);
    padding-top: .9rem;
}

.filters label {
    display: grid;
    gap: .25rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin: 1rem 0;
}

.pagination-bottom {
    justify-content: center;
    margin-top: 1.5rem;
}

.page-status {
    color: var(--muted);
    padding: .7rem .4rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: clamp(.85rem, 2vw, 1.25rem);
}

.card,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.cover {
    width: 100%;
    height: clamp(210px, 18vw, 280px);
    object-fit: cover;
    display: block;
    background: #e7dccd;
}

.placeholder {
    display: grid;
    place-items: center;
    color: var(--muted);
}

.card-body {
    padding: 1rem;
}

.card h2 {
    margin: 0 0 .35rem;
    font-size: clamp(1.05rem, 2vw, 1.2rem);
    line-height: 1.25;
}

.card p {
    margin: .35rem 0;
}

.meta {
    color: var(--muted);
}

.actions {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.actions form {
    margin: 0;
}

.panel {
    padding: clamp(1rem, 2.5vw, 1.25rem);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-grid label {
    display: grid;
    gap: .35rem;
}

.form-grid span {
    font-weight: 650;
}

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

.thumb {
    max-width: 160px;
    max-height: 160px;
    border-radius: .5rem;
    border: 1px solid var(--line);
    object-fit: cover;
}

.form-actions {
    border-top: 1px solid var(--line);
    padding-top: 1rem;
}

small {
    color: var(--muted);
}

/* Desktop / large monitors */
@media (min-width: 1280px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    }
}

/* Classic iPad / tablets */
@media (min-width: 768px) and (max-width: 1180px) {
    body {
        font-size: 17px;
    }

    .container {
        width: min(940px, calc(100% - 2rem));
    }

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

    .cover {
        height: 260px;
    }

    .search {
        grid-template-columns: 1fr 170px;
    }

    .search .button {
        width: 100%;
    }

    .filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .topbar {
        align-items: flex-start;
    }
}

/* Phones, including current standard iPhone sizes */
@media (max-width: 767px) {
    body {
        font-size: 16px;
    }

    .topbar {
        position: static;
        flex-direction: column;
        align-items: stretch;
    }

    .topbar .button {
        width: 100%;
    }

    .container,
    .narrow {
        width: min(100% - 1rem, 560px);
        margin: .75rem auto;
    }

    .search-panel {
        border-radius: .85rem;
        padding: .75rem;
    }

    .search {
        grid-template-columns: 1fr;
    }

    .filters {
        grid-template-columns: 1fr;
        gap: .65rem;
    }

    .grid {
        grid-template-columns: 1fr;
        gap: .85rem;
    }

    .cover {
        height: min(62vw, 320px);
    }

    .card-body {
        padding: .9rem;
    }

    .actions,
    .actions form,
    .actions .button {
        width: 100%;
    }

    .pagination {
        justify-content: center;
    }

    .pagination .button {
        flex: 1 1 auto;
        min-width: 88px;
    }

    .pagination-bottom {
        display: grid;
        grid-template-columns: 1fr;
        text-align: center;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Narrow phones */
@media (max-width: 390px) {
    .cover {
        height: 245px;
    }

    .pagination .button {
        min-width: 72px;
        padding-inline: .65rem;
    }
}


.danger-panel {
    border-color: rgba(159, 45, 32, .35);
}

.danger-panel h2 {
    margin-top: 0;
}

.delete-preview {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    border: 1px solid var(--line);
    border-radius: .85rem;
    padding: 1rem;
    background: white;
    margin: 1rem 0;
}

.warning-text {
    color: var(--danger);
    font-weight: 650;
}

.error-box {
    border: 1px solid rgba(159, 45, 32, .45);
    background: rgba(159, 45, 32, .08);
    color: var(--danger);
    border-radius: .65rem;
    padding: .75rem;
}

.delete-confirm-form {
    display: grid;
    gap: 1rem;
}

.delete-confirm-form label {
    display: grid;
    gap: .35rem;
}

.delete-confirm-form label span {
    font-weight: 650;
}

@media (max-width: 767px) {
    .delete-preview {
        flex-direction: column;
    }
}


.book-gallery {
    background: #e7dccd;
}

.book-gallery .cover {
    cursor: zoom-in;
}

.gallery-thumbs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .35rem;
    padding: .35rem;
    background: var(--panel);
    border-top: 1px solid var(--line);
}

.gallery-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: .45rem;
    border: 1px solid var(--line);
    background: #e7dccd;
    cursor: zoom-in;
    display: block;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 4vw, 3rem);
    background: rgba(0, 0, 0, .72);
    cursor: zoom-out;
}

.image-lightbox.is-open {
    display: flex;
}

.image-lightbox img {
    max-width: min(96vw, 1400px);
    max-height: 94vh;
    object-fit: contain;
    border-radius: .5rem;
    box-shadow: 0 20px 70px rgba(0, 0, 0, .45);
    cursor: zoom-out;
}

body.lightbox-open {
    overflow: hidden;
}

@media (max-width: 767px) {
    .gallery-thumbs {
        gap: .3rem;
        padding: .3rem;
    }

    .image-lightbox {
        padding: .5rem;
    }

    .image-lightbox img {
        max-width: 98vw;
        max-height: 92vh;
    }
}


.gallery-thumb-empty {
    background: white;
    border: 1px solid var(--line);
    border-radius: .45rem;
    aspect-ratio: 4 / 3;
}

.cover[src*="no-image-book"] {
    object-fit: contain;
    background: white;
    padding: 1rem;
}


.gallery-image {
    cursor: zoom-in;
    pointer-events: auto;
}

.gallery-thumbs {
    position: relative;
    z-index: 2;
}

.gallery-thumb.gallery-image {
    display: block;
    cursor: zoom-in;
}

.image-lightbox.is-open {
    display: flex !important;
}


.filters-extended {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

@media (max-width: 1180px) {
    .filters-extended {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767px) {
    .filters-extended {
        grid-template-columns: 1fr;
    }
}


.header-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.login-panel {
    width: min(420px, 100%);
}

.login-form {
    display: grid;
    gap: 1rem;
}

.login-form label {
    display: grid;
    gap: .35rem;
}

.login-form label span {
    font-weight: 650;
}

.success-box {
    border: 1px solid rgba(33, 110, 53, .45);
    background: rgba(33, 110, 53, .08);
    color: #216e35;
    border-radius: .65rem;
    padding: .75rem;
}

@media (max-width: 767px) {
    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }
}


.password-field {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: stretch;
}

.password-field input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.password-toggle {
    min-width: 48px;
    border: 1px solid var(--line);
    border-left: 0;
    border-top-right-radius: .65rem;
    border-bottom-right-radius: .65rem;
    background: white;
    cursor: pointer;
    font-size: 1.05rem;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: clamp(44px, 7vw, 70px);
    height: clamp(44px, 7vw, 70px);
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .84);
    color: #241c15;
    font-size: clamp(2rem, 7vw, 4rem);
    line-height: 1;
    cursor: pointer;
    z-index: 10001;
}

.lightbox-prev {
    left: clamp(.5rem, 3vw, 2rem);
}

.lightbox-next {
    right: clamp(.5rem, 3vw, 2rem);
}

.lightbox-counter {
    position: absolute;
    left: 50%;
    bottom: clamp(.75rem, 3vw, 1.5rem);
    transform: translateX(-50%);
    background: rgba(255, 255, 255, .88);
    color: #241c15;
    border-radius: 999px;
    padding: .4rem .8rem;
    font-weight: 650;
    z-index: 10001;
}

@media (max-width: 767px) {
    .lightbox-nav {
        width: 42px;
        height: 42px;
        font-size: 2.4rem;
        background: rgba(255, 255, 255, .7);
    }

    .lightbox-prev {
        left: .35rem;
    }

    .lightbox-next {
        right: .35rem;
    }
}


.book-detail {
    display: grid;
    grid-template-columns: minmax(280px, 430px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.detail-gallery {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.detail-cover {
    width: 100%;
    aspect-ratio: 4 / 5;
    object-fit: contain;
    background: white;
    display: block;
    cursor: zoom-in;
}

.detail-thumbs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .4rem;
    padding: .5rem;
    border-top: 1px solid var(--line);
}

.detail-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: white;
    border: 1px solid var(--line);
    border-radius: .5rem;
    cursor: zoom-in;
}

.detail-thumb.is-active {
    outline: 3px solid rgba(111, 78, 55, .35);
}

.detail-thumb-empty {
    background: white;
    border: 1px solid var(--line);
    border-radius: .5rem;
    aspect-ratio: 4 / 3;
}

.detail-info h2 {
    margin-top: 0;
    font-size: clamp(1.45rem, 3vw, 2.1rem);
}

.book-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
    margin: 1rem 0;
}

.book-fields div {
    border: 1px solid var(--line);
    background: white;
    border-radius: .7rem;
    padding: .75rem;
}

.book-fields dt {
    font-size: .82rem;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: .25rem;
}

.book-fields dd {
    margin: 0;
    word-break: break-word;
}

.detail-notes {
    border-top: 1px solid var(--line);
    padding-top: 1rem;
    margin-top: 1rem;
}

.detail-notes h3 {
    margin-top: 0;
}

@media (max-width: 900px) {
    .book-detail {
        grid-template-columns: 1fr;
    }

    .detail-cover {
        max-height: 70vh;
    }
}

@media (max-width: 767px) {
    .book-fields {
        grid-template-columns: 1fr;
    }
}


.detail-description {
    border-top: 1px solid var(--line);
    padding-top: 1rem;
    margin-top: 1rem;
}

.detail-description h3 {
    margin-top: 0;
}


.detail-main-photo-wrap {
    position: relative;
    background: white;
}

.detail-photo-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .86);
    color: var(--ink);
    font-size: 2.4rem;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
}

.detail-photo-prev {
    left: .55rem;
}

.detail-photo-next {
    right: .55rem;
}

.detail-gallery-help {
    margin: 0;
    padding: .65rem .75rem;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: .9rem;
    background: var(--panel);
}

.detail-description {
    border: 1px solid var(--line);
    background: white;
    border-radius: .8rem;
    padding: 1rem;
    margin: 1rem 0;
}

.detail-description h3 {
    margin-top: 0;
}

@media (max-width: 767px) {
    .detail-photo-arrow {
        width: 38px;
        height: 38px;
        font-size: 2rem;
    }
}


.euro-input {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
}

.euro-input span {
    min-height: 44px;
    display: grid;
    place-items: center;
    padding: 0 .8rem;
    border: 1px solid var(--line);
    border-right: 0;
    border-top-left-radius: .65rem;
    border-bottom-left-radius: .65rem;
    background: #f7f2eb;
    font-weight: 700;
    color: var(--accent);
}

.euro-input input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}


.view-switcher {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin: .75rem 0 1rem;
}

.book-list {
    display: grid;
    gap: .35rem;
    overflow-x: auto;
}

.book-list-header,
.book-list-row {
    display: grid;
    grid-template-columns: 72px minmax(220px, 1.7fr) minmax(140px, 1fr) minmax(140px, 1fr) 80px minmax(120px, .9fr) 120px 120px 90px;
    gap: .5rem;
    align-items: center;
    min-width: 1180px;
}

.book-list-header {
    padding: .65rem .75rem;
    background: #e7dccd;
    border: 1px solid var(--line);
    border-radius: .75rem;
    font-weight: 700;
    color: var(--ink);
}

.book-list-row {
    padding: .5rem .75rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .75rem;
    box-shadow: 0 4px 16px rgba(40, 30, 20, .04);
}

.book-list-photo img {
    width: 56px;
    height: 72px;
    object-fit: cover;
    background: white;
    border: 1px solid var(--line);
    border-radius: .35rem;
    display: block;
}

.book-list-title {
    display: grid;
    gap: .15rem;
}

.book-list-title small {
    color: var(--muted);
}

@media (max-width: 767px) {
    .view-switcher {
        justify-content: stretch;
    }

    .view-switcher .button {
        flex: 1;
    }

    .book-list {
        margin-inline: -.25rem;
    }
}


.detail-thumb-button {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: .5rem;
}

.detail-thumb-button.is-active {
    outline: 3px solid rgba(111, 78, 55, .45);
    outline-offset: 2px;
}

.detail-main-photo-wrap {
    position: relative;
}

.detail-cover {
    cursor: zoom-in;
}

.detail-photo-arrow {
    z-index: 10;
    pointer-events: auto;
}


.detail-thumb-button {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: .5rem;
}

.detail-thumb-button.is-active {
    outline: 3px solid rgba(111, 78, 55, .45);
    outline-offset: 2px;
}

.detail-main-photo-wrap {
    position: relative;
}

.detail-cover {
    cursor: zoom-in;
}

.detail-photo-arrow {
    z-index: 10;
    pointer-events: auto;
}

.detail-photo-arrow.disabled,
.detail-photo-arrow:disabled {
    opacity: .35;
    cursor: default;
}


.book-list-photo a {
    display: inline-block;
}

.book-list-photo a:hover img,
.book-list-title-link:hover {
    opacity: .78;
}

.book-list-title-link {
    color: var(--ink);
    text-decoration: none;
}

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


.book-list-row {
    transition:
        background-color .18s ease,
        transform .18s ease,
        box-shadow .18s ease,
        filter .18s ease;
}

.book-list-row:hover {
    background-color: #e8dccb;
    box-shadow: 0 10px 24px rgba(40, 30, 20, .10);
    transform: translateY(-1px);
    filter: brightness(.97);
}

@media (hover: none) {
    .book-list-row:hover {
        background-color: var(--panel);
        box-shadow: 0 4px 16px rgba(40, 30, 20, .04);
        transform: none;
        filter: none;
    }
}
