:root {
    --brand-primary: #c2185b;
    --brand-secondary: #111827;
    --brand-surface: #f8fafc;
    --text-main: #111827;
    --text-soft: #64748b;
    --border-soft: #e5e7eb;
    --shadow-soft: 0 18px 48px rgba(15, 23, 42, 0.10);
    --radius-xl: 22px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: Inter, Arial, Helvetica, sans-serif;
    color: var(--text-main);
    background: linear-gradient(180deg, #ffffff 0%, var(--brand-surface) 100%);
}

body.viewer-body {
    min-height: 100vh;
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: #fff;
}

body.embed-body {
    height: 100dvh;
    overflow: hidden;
}

code {
    padding: 0.15rem 0.4rem;
    border-radius: 8px;
    background: #eef2f7;
}

.topbar,
.viewer-topbar,
.embed-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.85);
}

.viewer-topbar,
.embed-toolbar {
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(14px);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-logo {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.4rem;
}

.eyebrow {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-primary);
    font-weight: 600;
}

.viewer-topbar .eyebrow,
.viewer-topbar h1,
.embed-toolbar .embed-title {
    color: #fff;
}

.topbar h1,
.viewer-topbar h1,
.panel h2,
.card h3 {
    margin: 0;
    font-weight: 700;
}

.topbar-note,
.muted,
.meta-row,
.empty-state,
.page-indicator {
    color: var(--text-soft);
}

.viewer-topbar .page-indicator,
.embed-toolbar .page-indicator {
    color: rgba(255, 255, 255, 0.85);
}

.container {
    width: min(1180px, calc(100% - 2rem));
    margin: 2rem auto 3rem;
    display: grid;
    gap: 1.5rem;
}

.panel,
.card {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-soft);
}

.panel {
    padding: 1.4rem;
}

.panel-tight {
    padding-bottom: 1.1rem;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1.2fr 1.2fr auto auto;
    gap: 1rem;
    align-items: end;
}

.upload-grid label {
    display: grid;
    gap: 0.45rem;
}

label span,
.embed-label {
    font-size: 0.92rem;
    font-weight: 600;
}

input[type="text"],
input[type="file"],
textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

.inline-check {
    display: inline-flex !important;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
}

.btn {
    appearance: none;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: #fff;
    color: var(--text-main);
    border-radius: 999px;
    padding: 0.8rem 1rem;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
    border-color: rgba(148, 163, 184, 0.55);
}

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

.btn-success {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
}

.btn-success:hover {
    border-color: #15803d;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}

.btn-danger:hover {
    border-color: #b91c1c;
}

.btn-secondary {
    background: #fff;
    color: var(--text-main);
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: 14px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.alert-success {
    background: #ecfdf5;
    color: #166534;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
}

.alert-warning {
    background: #fff7ed;
    color: #9a3412;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-head-stack {
    align-items: flex-start;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: #eef2ff;
    color: #4338ca;
    font-weight: 700;
}

.inline-form {
    margin: 0;
}

.badge-success {
    background: #ecfdf5;
    color: #166534;
}

.badge-warning {
    background: #fff7ed;
    color: #9a3412;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
    gap: 1.1rem;
    justify-content: start;
}

.card {
    overflow: hidden;
    width: 100%;
    max-width: 340px;
}

.cover-box {
    aspect-ratio: 4 / 5;
    background: linear-gradient(180deg, #e2e8f0 0%, #cbd5e1 100%);
    display: grid;
    place-items: center;
}

.cover-box canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-body {
    padding: 1.15rem;
    display: grid;
    gap: 0.85rem;
}

.meta-row,
.action-row,
.toggle-form,
.viewer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.viewer-actions {
    justify-content: flex-end;
}

.viewer-actions .page-indicator {
    min-width: 110px;
}

.embed-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.83rem;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius-lg);
}

.viewer-shell,
.embed-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.embed-shell {
    height: 100dvh;
    overflow: hidden;
}

.viewer-main,
.embed-shell {
    width: 100%;
}

.flipbook-stage {
    width: min(1500px, calc(100vw - 2rem));
    min-height: calc(100vh - 120px);
    margin: 1rem auto 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    overflow: hidden;
}

.flipbook-stage.embedded {
    width: min(1400px, calc(100vw - 1rem));
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0.75rem;
}

.flipbook-stage.is-zoomed {
    overflow: auto;
}

.flipbook-zoom-box {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 0 0 auto;
}

.flipbook-shell {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    display: block;
    flex: 0 0 auto;
    transform-origin: center center;
}

.flipbook-stage .stf__parent {
    margin: 0 auto;
}

.flipbook-page {
    background: #fff;
    display: flex;
    align-items: stretch;
    justify-content: center;
    overflow: hidden;
}

.flipbook-page img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}

.loading-box {
    min-height: 360px;
    width: min(560px, 100%);
    border-radius: 28px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255, 255, 255, 0.08);
    display: grid;
    place-items: center;
    padding: 2rem;
    text-align: center;
    color: rgba(255,255,255,0.92);
}

.page-input {
    width: 94px;
    min-width: 94px;
    text-align: center;
    padding: 0.8rem 0.9rem;
}

.btn.btn-iconish {
    min-width: 52px;
    text-align: center;
    padding-left: 0.9rem;
    padding-right: 0.9rem;
}

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

    .topbar,
    .viewer-topbar,
    .embed-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

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

    .card {
        max-width: none;
    }

    .flipbook-stage,
    .flipbook-stage.embedded {
        width: calc(100vw - 0.75rem);
        padding: 0.25rem;
    }
}


.builder-head {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
}

.embed-builder {
    display: grid;
    gap: 0.85rem;
    padding: 0.95rem;
    border-radius: 18px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.embed-builder-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.embed-builder-grid label,
.embed-link-row label {
    display: grid;
    gap: 0.42rem;
}

.embed-builder select,
.embed-builder input[type="number"] {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font: inherit;
    background: #fff;
}

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

.stat-box {
    display: grid;
    gap: 0.2rem;
    padding: 0.8rem 0.9rem;
    border-radius: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.stat-box strong {
    font-size: 1rem;
    line-height: 1.25;
}

.stat-box span {
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 700;
}

body.viewer-body.embed-theme-light,
.embed-theme-light {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    color: #0f172a;
}

.embed-theme-light .embed-toolbar {
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(148, 163, 184, 0.26);
}

.embed-theme-light .embed-title,
.embed-theme-light .page-indicator {
    color: #0f172a;
}

.embed-theme-light .flipbook-stage.embedded {
    background: linear-gradient(180deg, #ffffff 0%, #eef2f7 100%);
}

.embed-theme-light .loading-box {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(148, 163, 184, 0.25);
    color: #0f172a;
}

body.viewer-body.embed-theme-transparent,
.embed-theme-transparent {
    background: transparent;
}

.embed-theme-transparent .embed-toolbar {
    background: rgba(15, 23, 42, 0.45);
}

.embed-theme-transparent .flipbook-stage.embedded {
    background: transparent;
}

.embed-no-toolbar .embed-shell {
    grid-template-rows: minmax(0, 1fr);
}

.flipbook-stage.embedded.embedded-toolbarless {
    height: 100%;
    min-height: 0;
    margin: 0;
}

@media (max-width: 900px) {
    .embed-builder-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }
}


.cover-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #fff;
}

.viewer-body-light,
.viewer-body-light html,
.viewer-shell-light,
.embed-shell-light,
.flipbook-stage-light,
.viewer-topbar-light,
.embed-toolbar-light {
    background: #ffffff !important;
    color: #111827 !important;
}

.viewer-topbar-light,
.embed-toolbar-light {
    border-bottom: 1px solid #e5e7eb;
    backdrop-filter: none;
}

.viewer-topbar-light .eyebrow,
.viewer-topbar-light h1,
.embed-title-dark,
.page-indicator-dark,
.embed-label-dark {
    color: #111827 !important;
}

.btn-dark {
    background: #111827;
    color: #ffffff;
    border-color: #111827;
}

.btn-dark:hover {
    background: #1f2937;
    border-color: #1f2937;
}

.page-input-dark {
    background: #ffffff;
    color: #111827;
    border: 1px solid #cbd5e1;
}

.flipbook-stage-light {
    background: #ffffff !important;
}

body.viewer-body {
    background: #ffffff;
    color: #111827;
}

.viewer-topbar,
.embed-toolbar {
    background: #ffffff;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.password-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    align-items: end;
}

.password-grid label {
    display: grid;
    gap: 0.45rem;
}

.auth-body {
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(180deg, #ffffff 0%, var(--brand-surface) 100%);
}

.auth-shell {
    width: min(460px, 100%);
}

.auth-card {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-soft);
    padding: 1.6rem;
    display: grid;
    gap: 1rem;
}

.auth-card h1 {
    margin: 0;
    font-weight: 700;
}

.auth-intro {
    margin: -0.3rem 0 0;
}

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

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

.auth-form input[type="text"],
.auth-form input[type="password"] {
    min-height: 50px;
}

@media (max-width: 1100px) {
    .password-grid {
        grid-template-columns: 1fr;
    }
}

input[type="password"],
input[type="email"],
input[type="number"],
select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font: inherit;
    background: #fff;
}

.dashboard-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
}

.dashboard-container {
    width: min(1260px, calc(100% - 2rem));
    margin: 1.25rem auto 2rem;
    gap: 1rem;
}

.dashboard-container > .panel {
    padding: 1rem 1.1rem;
}

.stats-grid,
.group-grid,
.customer-grid,
.detail-layout {
    display: grid;
    gap: 1rem;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-panel {
    min-height: 118px;
    display: grid;
    align-content: start;
    gap: 0.5rem;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1;
}

.stat-value.small {
    font-size: 1.5rem;
}

.form-grid {
    display: grid;
    gap: 0.9rem;
}

.form-grid label,
.stack-form label,
.auth-form label {
    display: grid;
    gap: 0.45rem;
}

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

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

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

.wrap-row {
    flex-wrap: wrap;
}

.group-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.customer-grid {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    margin-top: 1rem;
}

.customer-card,
.compact-form,
.soft-panel {
    box-shadow: none;
}

.soft-panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.customer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

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

.customer-create-form {
    margin-bottom: 1rem;
}

.customer-detail-panel {
    margin-bottom: 1rem;
}

.customer-delete-inline {
    margin-top: 0.85rem;
}

.customer-table-wrap {
    margin-top: 1rem;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    background: #fff;
}

.customer-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

.customer-table th,
.customer-table td {
    padding: 0.8rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
}

.customer-table th {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-soft);
    background: #f8fafc;
    font-weight: 700;
}

.customer-table tbody tr:hover {
    background: #fafcff;
}

.customer-table tbody tr.is-selected {
    background: #fdf2f8;
}

.customer-table-empty {
    text-align: center !important;
    color: var(--text-soft);
}

.customer-table-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.detail-layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
}

.detail-preview {
    position: sticky;
    top: 96px;
    display: grid;
    gap: 1rem;
}

.detail-cover,
.cover-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.detail-cover {
    aspect-ratio: 4 / 5;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #fff;
}

.detail-links {
    display: grid;
    gap: 0.75rem;
}

.detail-main {
    display: grid;
    gap: 1rem;
}

.meta-list {
    display: grid;
    gap: 0.55rem;
    color: var(--text-soft);
}

.compact-meta-list {
    gap: 0.35rem;
    font-size: 0.94rem;
}

.col-span-2 {
    grid-column: 1 / -1;
}

.align-end {
    align-self: end;
}

.fixed-cover-box {
    aspect-ratio: 4 / 5;
    min-height: 0;
}

.cards-uniform {
    grid-template-columns: repeat(auto-fit, minmax(260px, 300px));
}

.cover-card {
    display: grid;
    grid-template-rows: auto 1fr;
}

.card-actions-under {
    justify-content: flex-start;
}

.password-grid-wide {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-shell-centered {
    width: min(540px, 100%);
}

.auth-card-wide {
    width: 100%;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 24px;
    box-shadow: var(--shadow-soft);
    padding: 2rem;
}

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

.auth-footer-links {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    color: var(--text-soft);
}

.auth-footer-links a {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 700;
}

.limit-box {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #334155;
}

@media (max-width: 1100px) {
    .upload-form-grid,
    .customer-create-grid,
    .password-grid-wide,
    .two-col,
    .detail-layout {
        grid-template-columns: 1fr;
    }

    .detail-preview {
        position: static;
    }
}

@media (max-width: 700px) {
    .customer-grid,
    .group-grid,
    .stats-grid,
    .cards-uniform {
        grid-template-columns: 1fr;
    }

    .auth-card-wide,
    .panel {
        padding: 1.15rem;
    }
}
