:root {
    --bg: #f4f7f5;
    --bg-2: #eaf2ee;
    --card: rgba(255, 255, 255, .88);
    --text: #171b1c;
    --muted: #66706d;
    --primary: #006747;
    --primary-dark: #004d35;
    --primary-soft: #e5f3ee;
    --primary-ring: rgba(0, 103, 71, .16);
    --grey: #4f5157;
    --grey-soft: #eef0f1;
    --danger: #b42318;
    --border: rgba(24, 31, 29, .10);
    --surface-2: rgba(255, 255, 255, .72);
    --shadow: 0 18px 45px rgba(0, 39, 27, .10);
    --shadow-soft: 0 10px 26px rgba(0, 39, 27, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(0,103,71,.12), transparent 34rem),
        linear-gradient(135deg, #fbfcfb 0%, var(--bg) 48%, var(--bg-2) 100%);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }

.topbar {
    height: 76px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 10px 28px rgba(0, 39, 27, .06);
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    min-width: 210px;
}
.brand img {
    display: block;
    height: 34px;
    width: auto;
    object-fit: contain;
}
.brand-text {
    color: var(--grey);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .18em;
    padding-left: 14px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}
nav {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    flex-wrap: wrap;
    justify-content: flex-end;
}
nav a, .nav-user {
    border-radius: 999px;
    padding: 10px 13px;
    font-weight: 700;
    font-size: 14px;
}
nav a:hover {
    color: var(--primary);
    background: var(--primary-soft);
}
.nav-user {
    color: var(--text);
    background: var(--grey-soft);
}

.container { max-width: 1180px; margin: 0 auto; padding: 34px 20px 64px; }
.hero {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 32px;
    padding: 48px;
    background:
        linear-gradient(135deg, rgba(0,103,71,.95), rgba(0,76,53,.93)),
        radial-gradient(circle at 85% 20%, rgba(255,255,255,.26), transparent 18rem);
    color: white;
    margin-bottom: 22px;
    box-shadow: 0 26px 70px rgba(0, 103, 71, .22);
}
.hero:after {
    content: "";
    position: absolute;
    width: 360px;
    height: 360px;
    right: -110px;
    bottom: -170px;
    border-radius: 50%;
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.18);
}
.eyebrow {
    display: inline-flex;
    margin-bottom: 14px;
    color: rgba(255,255,255,.80);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .22em;
    text-transform: uppercase;
}
.hero h1 { margin: 0 0 10px; font-size: clamp(34px, 5vw, 58px); line-height: 1.02; }
.hero p { max-width: 720px; margin: 0; color: rgba(255,255,255,.86); font-size: 17px; line-height: 1.65; }

.filter-card, .auth-card, .form-card, .access-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(14px);
}
.filter-card {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 240px 128px;
    gap: 12px;
    margin-bottom: 24px;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 15px;
    font-size: 15px;
    background: rgba(255,255,255,.92);
    color: var(--text);
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(0,103,71,.42);
    box-shadow: 0 0 0 5px var(--primary-ring);
}
label { font-weight: 800; color: #27302d; }
button, .button {
    border: 0;
    background: var(--primary);
    color: white;
    border-radius: 16px;
    padding: 14px 18px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 10px 22px rgba(0, 103, 71, .18);
    transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}
button:hover, .button:hover { background: var(--primary-dark); transform: translateY(-1px); }
.button.secondary, .toolbar button {
    background: rgba(255,255,255,.92);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(265px, 1fr)); gap: 18px; }
.catalog-card {
    position: relative;
    overflow: hidden;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 24px;
    box-shadow: var(--shadow-soft);
    min-height: 276px;
    display: flex;
    flex-direction: column;
    gap: 13px;
    backdrop-filter: blur(14px);
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.catalog-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: rgba(0,103,71,.25); }
.catalog-card:before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 5px;
    background: linear-gradient(90deg, var(--primary), #4f5157);
}
.pdf-badge {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 900;
    display: grid;
    place-items: center;
    border: 1px solid rgba(0,103,71,.14);
}
.catalog-card h3 { margin: 0; font-size: 21px; line-height: 1.25; }
.catalog-card p { color: var(--muted); flex: 1; line-height: 1.55; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.meta span { background: var(--grey-soft); padding: 7px 10px; border-radius: 999px; font-weight: 700; }

.viewer-header, .admin-header { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 18px; }
.viewer-header h1, .admin-header h1 { margin: 0 0 6px; }
.viewer-header p, .admin-header p { margin: 0; color: var(--muted); }
.viewer-actions, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: center; margin-bottom: 18px; flex-wrap: wrap; }
.book-shell {
    background:
        radial-gradient(circle at 50% 0%, rgba(0,103,71,.16), transparent 25rem),
        linear-gradient(135deg, #ecf3ef, #dce8e3);
    border-radius: 28px;
    min-height: 700px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    overflow: hidden;
}
.book { margin: 0 auto; }
.book-page { background: white; overflow: hidden; box-shadow: 0 15px 42px rgba(0,0,0,.14); }
.book-page canvas { width: 100%; height: 100%; object-fit: contain; display: block; }

.auth-card, .form-card { max-width: 560px; margin: 56px auto; }
.auth-card h1, .form-card h1 { margin: 0 0 8px; font-size: 32px; }
.auth-card p, .form-card p, .muted { color: var(--muted); }
.auth-card form, .form-card form { display: grid; gap: 12px; margin-top: 20px; }
.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0 18px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.auth-logo img { max-width: min(360px, 100%); height: auto; display: block; }
.alert { background: #fdecec; color: #9f1f1f; border-radius: 14px; padding: 12px 14px; margin: 12px 0; border: 1px solid rgba(180,35,24,.10); }
.success { background: #e6f4ea; color: #166534; border-radius: 14px; padding: 12px 14px; margin: 12px 0; border: 1px solid rgba(22,101,52,.10); }

.table { width: 100%; border-collapse: collapse; background: white; border-radius: 20px; overflow: hidden; box-shadow: var(--shadow-soft); }
.table th, .table td { padding: 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #f5f8f6; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { display: inline; }
.mini { padding: 8px 11px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-dark); border: 0; font-size: 13px; font-weight: 800; }
.mini.danger { background: #fdecec; color: var(--danger); }
.empty { text-align: center; padding: 50px; color: var(--muted); }
.field-validation-error { color: var(--danger); font-size: 13px; }

.full-page-body { background: #e7f0ec; overflow: hidden; }
.full-page-container { width: 100vw; height: 100vh; margin: 0; padding: 0; }
.viewer-page { width: 100vw; height: 100vh; position: relative; }
.viewer-page:before {
    content: "";
    position: fixed;
    left: 18px;
    top: 18px;
    width: 138px;
    height: 24px;
    background: url('/img/mejuso-wordmark.png') center/contain no-repeat;
    opacity: .85;
    z-index: 3;
}
.floating-toolbar {
    position: fixed;
    right: 18px;
    bottom: 18px;
    left: auto;
    transform: none;
    z-index: 50;
    background: rgba(255,255,255,.76);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255,255,255,.78);
    border-radius: 20px;
    padding: 8px;
    box-shadow: 0 16px 42px rgba(0,39,27,.14);
    margin: 0;
    opacity: .82;
    transition: opacity .2s ease, transform .2s ease;
}
.floating-toolbar:hover, .floating-toolbar:focus-within { opacity: 1; transform: translateY(-2px); }
.compact-toolbar { gap: 6px; }
.tool-button, .floating-toolbar .button.tool-button, .floating-toolbar button.tool-button {
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 900;
    line-height: 1;
}
.tool-back { min-width: 42px; font-size: 20px; }
.page-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 14px;
    border-radius: 14px;
    background: rgba(255,255,255,.86);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 800;
    font-size: 14px;
    white-space: nowrap;
}
.full-book-shell { width: 100vw; height: 100vh; min-height: 100vh; border-radius: 0; padding: 18px; }

.access-list { display: grid; gap: 10px; margin: 18px 0; }
.access-item {
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255,255,255,.88);
}
.access-item input { width: auto; margin-top: 3px; }
.access-item small { display: block; color: var(--muted); margin-top: 4px; }

@media (max-width: 720px) {
    .topbar { height: auto; min-height: 72px; padding: 14px 16px; align-items: flex-start; flex-direction: column; }
    .brand { min-width: 0; }
    .brand img { height: 28px; }
    .brand-text { font-size: 10px; letter-spacing: .12em; }
    nav { width: 100%; gap: 6px; justify-content: flex-start; }
    nav a, .nav-user { font-size: 13px; padding: 8px 10px; }
    .container { padding: 22px 14px 54px; }
    .hero { padding: 30px 24px; border-radius: 24px; }
    .filter-card { grid-template-columns: 1fr; }
    .viewer-header, .admin-header { flex-direction: column; align-items: flex-start; }
    .book-shell { padding: 16px; min-height: 520px; }
    .table { display: block; overflow-x: auto; }
    .floating-toolbar { right: 10px; bottom: 10px; padding: 7px; max-width: calc(100vw - 20px); border-radius: 16px; }
    .page-indicator { padding: 0 10px; font-size: 12px; }
    .tool-button, .floating-toolbar .button.tool-button, .floating-toolbar button.tool-button { min-width: 38px; height: 38px; font-size: 16px; }
    .viewer-page:before { left: 12px; top: 12px; width: 104px; height: 18px; }
}
