:root {
    --bg: #f3efe8;
    --bg-mid: #ece6dc;
    --paper: #fffdf8;
    --paper-2: #f7f1e7;
    --paper-edge: #d9ccb8;
    --accent: #7a2d1b;
    --accent-light: #9f4a2f;
    --accent-dark: #5b2114;
    --price-bg: linear-gradient(135deg, #fff9f2 0%, #fceede 100%);
    --price-border: #8a351f;
    --text: #1f1b17;
    --muted: #5f564e;
    --shadow: rgba(39, 27, 20, 0.18);
    --shadow-paper: 0 10px 28px rgba(84, 66, 52, 0.18), 0 1px 0 rgba(255, 255, 255, 0.7) inset;
    --font-ui: "DM Sans", system-ui, -apple-system, sans-serif;
    --font-display: "DM Serif Display", Georgia, serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-ui);
    background: radial-gradient(ellipse 120% 100% at 50% 0%, var(--bg-mid) 0%, var(--bg) 70%);
    color: var(--text);
}

.catalogo-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0.35rem 0.35rem 0.45rem;
    box-sizing: border-box;
}

/* Lista: usa toda a largura e altura útil (mobile/tablet) */
body.catalogo-modo-lista .catalogo-wrap {
    padding: 0;
    min-height: 100dvh;
}

body.catalogo-modo-lista .catalogo-top {
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 0.65rem 0.75rem;
}

body.catalogo-modo-lista #fallback-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    padding: 0.65rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0));
    margin: 0;
    gap: 0.85rem;
    align-content: start;
}

.catalogo-top {
    width: 100%;
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    flex-shrink: 0;
    padding: 0.5rem 0.65rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(249, 244, 235, 0.96) 100%);
    border: 1px solid rgba(142, 117, 90, 0.24);
    border-radius: 12px;
    backdrop-filter: blur(8px);
}

.catalogo-top h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.15rem, 2.8vw, 1.5rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    color: #3a2a21;
    text-shadow: none;
}

.catalogo-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.catalogo-controls input,
.catalogo-controls select {
    padding: 0.5rem 0.75rem;
    border: 1px solid rgba(132, 105, 77, 0.35);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    color: #2f261f;
    font-size: 0.875rem;
    min-width: 160px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.catalogo-controls input::placeholder {
    color: rgba(86, 66, 47, 0.55);
}

.catalogo-controls input:focus,
.catalogo-controls select:focus {
    outline: none;
    border-color: rgba(196, 92, 38, 0.6);
    box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.25);
}

.catalogo-controls button {
    padding: 0.45rem 0.85rem;
    border: none;
    border-radius: 6px;
    background: linear-gradient(180deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}

.catalogo-controls button:hover {
    filter: brightness(1.08);
}

.book-stage {
    position: relative;
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

#book-wrapper {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Só quando cai no fallback (ex.: lib não carregou) */
body.catalogo-modo-lista .book-stage {
    display: none !important;
    min-height: 0;
}

body.catalogo-modo-lista .nav-arrows {
    display: none !important;
}

body.catalogo-modo-lista #fallback-grid {
    display: grid !important;
    min-height: 40vh;
}

@media (max-width: 767px) {
    .catalogo-wrap {
        padding: 0.25rem 0.35rem 0.5rem;
    }

    .book-stage {
        width: 100%;
        max-width: 100vw;
    }

    .nav-arrows {
        margin-top: 0.5rem;
    }
}

.lista-vazia-msg {
    text-align: center;
    color: #ccc;
    padding: 2rem 1rem;
    width: 100%;
    max-width: 1100px;
}

#book {
    box-shadow: var(--shadow-paper);
    border-radius: 12px;
    filter: drop-shadow(0 8px 26px rgba(86, 66, 47, 0.25));
}

.page:not(.page-cover) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.page {
    background: linear-gradient(145deg, var(--paper) 0%, var(--paper-2) 48%, #e8e0d4 100%);
    border: 1px solid var(--paper-edge);
}

.page-inner {
    height: 100%;
    min-height: 0;
    padding: clamp(0.75rem, 2vw, 1.5rem);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-content: start;
}

.page-inner--dupla {
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    padding: 0.55rem 0.65rem;
}

/* Página de produto no flip: ocupa 100% da folha; texto rola sem cortar */
.page-inner.page-inner--prod {
    display: grid;
    grid-template-columns: minmax(150px, 36%) minmax(0, 1fr);
    gap: 0.65rem;
    align-items: stretch;
    padding: 0.6rem 0.65rem;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
}

.folha-prod.page-inner--prod {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.35rem 0.45rem;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.page-inner--prod .prod-img-wrap {
    width: 100%;
    height: 100%;
    max-height: none;
    min-height: 0;
    aspect-ratio: 3 / 4;
    margin: 0 auto;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.page-inner--prod .prod-meta {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.1rem 0.1rem 0.2rem 0.15rem;
    font-size: 0.78rem;
    gap: 0.32rem;
}

.page-inner--prod .bloco-nome .label,
.page-inner--prod .bloco-preco .label,
.page-inner--prod .bloco-codigo .label {
    display: block;
    margin-bottom: 0.12rem;
}

.page-inner--prod .prod-meta .desc {
    font-size: 0.68rem;
    line-height: 1.35;
    color: #3d3835;
    display: block;
    overflow: visible;
    max-height: none;
    white-space: pre-wrap;
}

.ficha-tecnica-full {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
}

.ficha-tecnica-full .ft-section {
    border: 1px solid rgba(135, 111, 84, 0.2);
    border-radius: 10px;
    padding: 0.35rem 0.45rem;
    background: rgba(255, 255, 255, 0.45);
}

.ficha-tecnica-full .ft-section-title {
    margin: 0 0 0.28rem;
    font-size: 0.56rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6d5743;
}

.ficha-tecnica-full .ft-section-body {
    display: grid;
    gap: 0.2rem;
}

.ficha-tecnica-full .ft-row {
    display: grid;
    grid-template-columns: minmax(78px, auto) 1fr;
    gap: 0.35rem;
    align-items: start;
}

.ficha-tecnica-full .ft-label {
    font-size: 0.56rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 700;
}

.ficha-tecnica-full .ft-val {
    font-size: 0.66rem;
    line-height: 1.3;
    color: #2f2722;
    word-break: break-word;
}

.ficha-tecnica-full .ft-row--aplicacao .ft-val {
    white-space: pre-wrap;
}

.page-inner--prod .prod-meta .nome {
    font-family: var(--font-ui);
    font-family: var(--font-display);
    font-size: clamp(0.84rem, 1.1vw, 1.02rem);
    line-height: 1.2;
    font-weight: 400;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.page-inner--prod .preco-wrap {
    display: block;
    padding: 0.35rem 0.5rem;
    background: var(--price-bg);
    border-radius: 8px;
    border-left: 4px solid var(--price-border);
    box-shadow: 0 2px 8px rgba(196, 92, 38, 0.15);
}

.page-inner--prod .prod-meta .preco {
    font-family: var(--font-ui);
    font-size: clamp(0.86rem, 1.15vw, 1.02rem);
    font-weight: 700;
    color: var(--accent-dark);
    letter-spacing: 0.02em;
}

.page-inner--prod .codigo-val {
    font-weight: 600;
    font-family: ui-monospace, monospace;
    font-size: 0.72rem;
    color: #3d3835;
}

.page-inner--prod .prod-meta .label {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--muted);
    text-transform: uppercase;
}

.page-inner--prod .ficha-tecnica-wrap {
    margin: 0.25rem 0 0;
}

.page-inner--prod .ficha-tecnica-link {
    font-size: 0.67rem;
    font-weight: 600;
    padding: 0.2rem 0;
    display: inline-block;
}

.page-inner--prod .bloco-preco {
    display: none !important;
}

@media (max-width: 900px) {
    .page-inner.page-inner--prod {
        grid-template-columns: 1fr;
        padding: 0.55rem;
    }
}

@media (max-width: 700px) {
    .page-inner:not(.page-inner--prod) {
        grid-template-columns: 1fr;
    }
}

.page-cover {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    background: linear-gradient(160deg, #3d3530 0%, #1f1c1a 100%);
    color: #f5efe6;
}

.page-cover h2 {
    margin: 0 0 0.5rem;
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page-cover p {
    margin: 0;
    opacity: 0.85;
    font-size: 0.95rem;
}

.prod-img-wrap {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(160deg, #e8e6e2 0%, #d8d4cc 100%);
    aspect-ratio: 4 / 5;
    cursor: zoom-in;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    -webkit-tap-highlight-color: transparent;
}

.prod-img-wrap img,
.prod-img-wrap img.prod-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

@media (max-width: 700px) {
    .fallback-card .prod-img-wrap {
        aspect-ratio: 1;
        max-height: min(48vh, 360px);
        width: 100%;
        margin: 0 auto;
    }
}

.prod-meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.prod-meta .nome {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text);
}

.prod-meta .preco {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.prod-meta .label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.prod-meta .desc {
    line-height: 1.45;
    color: #444;
    flex: 1;
    overflow: visible;
    max-height: none;
    white-space: pre-wrap;
}

.nav-arrows {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.35rem;
    justify-content: center;
    flex-shrink: 0;
}

.nav-arrows button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(180deg, #2e3440 0%, #1e2229 100%);
    color: #f5f0e8;
    font-size: 1.35rem;
    cursor: pointer;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.nav-arrows button:hover:not(:disabled) {
    transform: scale(1.06);
    border-color: rgba(196, 92, 38, 0.5);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.nav-arrows button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.loading, .erro-msg {
    text-align: center;
    padding: 2rem;
    color: #ccc;
}

.erro-msg {
    color: #f88;
}

/* Zoom modal */
.zoom-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.zoom-modal[hidden] {
    display: none !important;
}

.zoom-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    cursor: zoom-out;
}

.zoom-content {
    position: relative;
    max-width: min(96vw, 900px);
    max-height: 90vh;
    z-index: 1;
}

.zoom-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.zoom-close {
    position: absolute;
    top: -2.5rem;
    right: 0;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.fallback-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    max-width: 1100px;
    width: 100%;
}

body.catalogo-modo-lista .fallback-grid {
    max-width: 100%;
    grid-template-columns: 1fr;
}

.fallback-card {
    background: linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--paper-edge);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.fallback-card .bloco-preco .preco-wrap {
    display: inline-block;
    padding: 0.4rem 0.65rem;
    background: var(--price-bg);
    border-radius: 8px;
    border-left: 4px solid var(--price-border);
    margin-top: 0.25rem;
}

.fallback-card .bloco-preco {
    display: none !important;
}

.fallback-card .nome {
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: clamp(0.9rem, 3.5vw, 1.05rem);
    line-height: 1.28;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.fallback-card .preco {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.prod-meta--card .codigo-val {
    font-family: ui-monospace, monospace;
    font-weight: 600;
}

.fallback-card .prod-img-wrap {
    cursor: zoom-in;
    aspect-ratio: 1;
    max-height: none;
}

@media (max-width: 700px) {
    .fallback-card .prod-img-wrap {
        max-height: min(42vh, 280px);
    }
}

.fallback-card .prod-meta {
    padding: 1rem;
}

.ficha-tecnica-wrap {
    margin: 0.75rem 0 0;
}

.ficha-tecnica-link {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    font-family: system-ui, sans-serif;
}

.ficha-tecnica-link:hover {
    text-decoration: underline;
}
