:root {
    --font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: "Lora", Georgia, serif;
    --cream: #fcfaf5;
    --paper: #ffffff;
    --green: #354d3e;
    --green-dark: #283b2f;
    --muted: #778077;
    --rust: #b9684c;
    --rust-soft: #f7ebe6;
    --line: #e5e5d9;
    --danger: #b43c3c;
    --danger-bg: #fdf0f0;
    --success-bg: #edf5ef;
    --warn-bg: #fdf6e7;
    --warn: #8a5a14;
    --radius: 16px;
    --shadow: 0 8px 24px rgba(53, 77, 62, 0.06);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    color: var(--green);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3 {
    font-family: var(--font-serif);
    margin: 0 0 0.4rem;
    color: var(--green);
}

.container {
    width: min(1160px, 92vw);
    margin: 0 auto;
}

/* Brand Logo (extraído dos modelos Imaginocional) */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-serif);
    font-size: 32px;
    letter-spacing: -1.4px;
    line-height: 1;
    color: #3e5744;
    flex-shrink: 0;
}

.brand-compact {
    font-size: 26px;
}

.brand-symbol {
    width: 38px;
    color: #9c7654;
    display: inline-flex;
}

.brand-symbol svg {
    width: 100%;
    height: 40px;
}

.brand-warm {
    color: #b97b5c;
}

.brand-caption {
    font-family: var(--font-sans);
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 1.45px;
    display: block;
    padding-top: 6px;
    text-align: center;
    color: var(--muted);
}

/* Topbar */
.topbar {
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}

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

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links a {
    padding: 8px 14px;
    border-radius: 99px;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--muted);
    transition: background 0.15s, color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--cream);
    color: var(--green);
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-greeting {
    font-size: 0.9rem;
    color: var(--muted);
}

.logout-form {
    margin: 0;
}

.main-content {
    padding: 28px 0 48px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 99px;
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--green-dark);
}

.btn-warm {
    background: var(--rust);
    color: #fff;
}

.btn-warm:hover:not(:disabled) {
    background: #a3573d;
}

.btn-outline {
    background: transparent;
    border-color: var(--line);
    color: var(--green);
}

.btn-outline:hover:not(:disabled) {
    background: var(--cream);
    border-color: var(--green);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #f3caca;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

/* Login */
.login-wrapper {
    min-height: calc(100vh - 80px);
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(440px, 100%);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
}

.login-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.login-card h1 {
    font-size: 1.55rem;
    text-align: center;
}

.login-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0 0 24px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--green);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--cream);
    color: var(--green);
    font-family: var(--font-sans);
    font-size: 0.95rem;
}

.form-control:focus {
    outline: 2px solid var(--rust);
    border-color: transparent;
    background: var(--paper);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}

/* Alerts & Badges */
.alert {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    font-size: 0.92rem;
}

.alert-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #f3caca;
}

.alert-success {
    background: var(--success-bg);
    color: var(--green);
    border: 1px solid #cde2d2;
}

.alert-warn {
    background: var(--warn-bg);
    color: var(--warn);
    border: 1px solid #f0ddb8;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-active { background: var(--success-bg); color: var(--green); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warm { background: var(--rust-soft); color: var(--rust); }

/* Page Header & Cards */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-subtitle {
    color: var(--muted);
    margin: 0;
}

.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

/* Subscription Banner */
.sub-banner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
}

.sub-stat-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 4px;
}

.sub-stat-value {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 22px;
}

.book-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}

.book-card:hover:not(.book-locked) {
    transform: translateY(-3px);
}

.book-cover {
    height: 180px;
    background: linear-gradient(135deg, #f3ece0 0%, #e7efe9 100%);
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-cover-fallback {
    padding: 20px;
    text-align: center;
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--green);
}

.book-week-pill {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--green);
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.78rem;
    font-weight: 700;
}

.book-body {
    padding: 18px 20px 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-title {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    margin: 0 0 4px;
}

.book-subtitle {
    color: var(--rust);
    font-size: 0.88rem;
    font-weight: 600;
    margin: 0 0 10px;
}

.book-desc {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0 0 16px;
    flex: 1;
}

.book-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
}

.book-locked {
    opacity: 0.82;
}

.book-locked .book-cover {
    filter: grayscale(0.45);
}

.lock-overlay {
    position: absolute;
    inset: 0;
    background: rgba(40, 59, 47, 0.42);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    padding: 12px;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

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

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 45, 36, 0.5);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 60;
}

.modal-box {
    width: min(640px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--paper);
    border-radius: 20px;
    padding: 26px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

/* Book Reader */
.reader-shell {
    position: fixed;
    inset: 0;
    background: #1e1629;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.reader-bar {
    height: 56px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.reader-title {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #fff;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
}

.center-loading {
    display: grid;
    place-items: center;
    min-height: 50vh;
    color: var(--muted);
}

.validation-message {
    color: var(--danger);
    font-size: 0.82rem;
    margin-top: 4px;
}

/* Editor de história */
.editor-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-top: 12px;
}

.editor-row > * { min-width: 0; }

.editor-thumb {
    display: block;
    width: 120px;
    max-width: 120px;
    height: 90px;
    max-height: 90px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
    flex: 0 0 120px;
}

@media (max-width: 640px) {
    .editor-row { flex-direction: column; }
    .editor-thumb { flex: 0 0 auto; }
}

.login-forgot {
    text-align: center;
    margin: 4px 0 16px;
    font-size: 0.9rem;
}

.login-forgot a {
    color: var(--rust);
    font-weight: 600;
}

.cf-turnstile {
    min-height: 65px;
}
