/* =====================================================
   Mi Biblioteca - 7 temas
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

/* =============== TEMA OSCURO (default) =============== */
:root,
[data-theme="dark"] {
    --bg: #14110f;
    --bg-elev: #1c1916;
    --bg-elev-2: #252119;
    --surface: #1f1c19;
    --border: #2e2a25;
    --border-soft: #26221e;

    --text: #f0ece4;
    --text-soft: #a8a098;
    --text-muted: #6e665d;

    --accent: #8b1e3f;
    --accent-hover: #a52749;
    --accent-soft: rgba(139, 30, 63, 0.15);
    --accent-glow: rgba(165, 39, 73, 0.4);

    --star: #d4a437;
    --star-empty: rgba(212, 164, 55, 0.18);
    --success: #4a7c59;
    --danger: #a83232;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.7);
    --shadow-cover: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.4);

    --bg-gradient: radial-gradient(ellipse at top, rgba(139, 30, 63, 0.08), transparent 50%);
    --header-bg: rgba(20, 17, 15, 0.85);

    --font-serif: 'Fraunces', Georgia, serif;
    --font-sans: 'Inter', -apple-system, system-ui, sans-serif;
}

/* =============== TEMA CLARO =============== */
[data-theme="light"] {
    --bg: #faf7f2;
    --bg-elev: #ffffff;
    --bg-elev-2: #f1ede5;
    --surface: #ffffff;
    --border: #e3ddd1;
    --border-soft: #ede7da;

    --text: #1d1714;
    --text-soft: #5a5048;
    --text-muted: #8a7f74;

    --accent: #8b1e3f;
    --accent-hover: #6e1731;
    --accent-soft: rgba(139, 30, 63, 0.10);
    --accent-glow: rgba(139, 30, 63, 0.25);

    --star: #c08418;
    --star-empty: rgba(192, 132, 24, 0.22);
    --success: #2d6a3e;
    --danger: #b53030;

    --shadow-sm: 0 1px 3px rgba(20, 17, 15, 0.08);
    --shadow-md: 0 4px 16px rgba(20, 17, 15, 0.10);
    --shadow-lg: 0 16px 48px rgba(20, 17, 15, 0.18);
    --shadow-cover: 0 1px 3px rgba(20, 17, 15, 0.10), 0 8px 20px rgba(20, 17, 15, 0.08);

    --bg-gradient: radial-gradient(ellipse at top, rgba(139, 30, 63, 0.05), transparent 50%);
    --header-bg: rgba(250, 247, 242, 0.85);
}

/* =============== TEMA DOSTOIEVSKI (blanco + rojo sangre) =============== */
[data-theme="dostoievski"] {
    --bg: #f5f1eb;
    --bg-elev: #ffffff;
    --bg-elev-2: #ebe5da;
    --surface: #ffffff;
    --border: #c9c0b0;
    --border-soft: #d8d1c2;

    --text: #1a0e0e;
    --text-soft: #4a3838;
    --text-muted: #8a7878;

    --accent: #8b0000;
    --accent-hover: #a30000;
    --accent-soft: rgba(139, 0, 0, 0.10);
    --accent-glow: rgba(139, 0, 0, 0.30);

    --star: #b8860b;
    --star-empty: rgba(184, 134, 11, 0.22);
    --success: #4a7536;
    --danger: #c41e1e;

    --shadow-sm: 0 1px 3px rgba(26, 14, 14, 0.10);
    --shadow-md: 0 4px 16px rgba(26, 14, 14, 0.14);
    --shadow-lg: 0 16px 48px rgba(26, 14, 14, 0.22);
    --shadow-cover: 0 1px 3px rgba(26, 14, 14, 0.12), 0 8px 20px rgba(26, 14, 14, 0.10);

    --bg-gradient: radial-gradient(ellipse at top, rgba(139, 0, 0, 0.05), transparent 50%);
    --header-bg: rgba(245, 241, 235, 0.92);
}

/* =============== TEMA CAFÉ LITERARIO =============== */
[data-theme="cafe"] {
    --bg: #f0e6d2;
    --bg-elev: #faf3e0;
    --bg-elev-2: #e6d5b8;
    --surface: #faf3e0;
    --border: #c9b48a;
    --border-soft: #d9c5a0;

    --text: #3a2817;
    --text-soft: #6b4f33;
    --text-muted: #8f7757;

    --accent: #6b3410;
    --accent-hover: #8a4615;
    --accent-soft: rgba(107, 52, 16, 0.12);
    --accent-glow: rgba(107, 52, 16, 0.3);

    --star: #b8860b;
    --star-empty: rgba(184, 134, 11, 0.25);
    --success: #5a7544;
    --danger: #a04030;

    --shadow-sm: 0 1px 3px rgba(58, 40, 23, 0.10);
    --shadow-md: 0 4px 16px rgba(58, 40, 23, 0.12);
    --shadow-lg: 0 16px 48px rgba(58, 40, 23, 0.20);
    --shadow-cover: 0 2px 4px rgba(58, 40, 23, 0.12), 0 8px 20px rgba(58, 40, 23, 0.10);

    --bg-gradient: none;
    --header-bg: rgba(240, 230, 210, 0.92);
}

/* =============== TEMA VAN GOGH (azules profundos + amarillos) =============== */
[data-theme="vangogh"] {
    --bg: #1a3a5c;
    --bg-elev: #234970;
    --bg-elev-2: #2d5882;
    --surface: #2a5278;
    --border: #4a78a3;
    --border-soft: #3a6892;

    --text: #fff8d4;
    --text-soft: #e8dba0;
    --text-muted: #b5a872;

    --accent: #f4c430;
    --accent-hover: #ffd84d;
    --accent-soft: rgba(244, 196, 48, 0.15);
    --accent-glow: rgba(244, 196, 48, 0.40);

    --star: #ffd84d;
    --star-empty: rgba(255, 216, 77, 0.22);
    --success: #8fd14f;
    --danger: #ff7849;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.40);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
    --shadow-cover: 0 4px 12px rgba(0, 0, 0, 0.40), 0 12px 32px rgba(0, 0, 0, 0.30);

    --bg-gradient: radial-gradient(ellipse at top, rgba(244, 196, 48, 0.10), transparent 55%);
    --header-bg: rgba(26, 58, 92, 0.88);
}

/* =============== TEMA ROMANCE (rosados pasteles) =============== */
[data-theme="romance"] {
    --bg: #fce4ec;
    --bg-elev: #ffffff;
    --bg-elev-2: #f8d7e1;
    --surface: #fff5f8;
    --border: #e8b8c8;
    --border-soft: #f0c8d4;

    --text: #4a1f30;
    --text-soft: #7a3d54;
    --text-muted: #a87890;

    --accent: #c2185b;
    --accent-hover: #d63178;
    --accent-soft: rgba(194, 24, 91, 0.10);
    --accent-glow: rgba(194, 24, 91, 0.30);

    --star: #e91e63;
    --star-empty: rgba(233, 30, 99, 0.20);
    --success: #66bb6a;
    --danger: #d32f2f;

    --shadow-sm: 0 1px 3px rgba(74, 31, 48, 0.10);
    --shadow-md: 0 4px 16px rgba(74, 31, 48, 0.14);
    --shadow-lg: 0 16px 48px rgba(74, 31, 48, 0.22);
    --shadow-cover: 0 2px 4px rgba(74, 31, 48, 0.12), 0 8px 20px rgba(74, 31, 48, 0.10);

    --bg-gradient: radial-gradient(ellipse at top, rgba(233, 30, 99, 0.08), transparent 50%);
    --header-bg: rgba(252, 228, 236, 0.92);
}


/* =============== TEMA BOSQUE =============== */
[data-theme="forest"] {
    --bg: #f5f1e8;
    --bg-elev: #ffffff;
    --bg-elev-2: #ebe5d4;
    --surface: #ffffff;
    --border: #c9c3ad;
    --border-soft: #d6d0bc;

    --text: #1f2d1f;
    --text-soft: #4a5d4a;
    --text-muted: #7a8a7a;

    --accent: #2d5040;
    --accent-hover: #3a6450;
    --accent-soft: rgba(45, 80, 64, 0.10);
    --accent-glow: rgba(45, 80, 64, 0.30);

    --star: #b8860b;
    --star-empty: rgba(184, 134, 11, 0.22);
    --success: #4a7536;
    --danger: #b04535;

    --shadow-sm: 0 1px 3px rgba(31, 45, 31, 0.08);
    --shadow-md: 0 4px 16px rgba(31, 45, 31, 0.10);
    --shadow-lg: 0 16px 48px rgba(31, 45, 31, 0.18);
    --shadow-cover: 0 1px 3px rgba(31, 45, 31, 0.10), 0 8px 20px rgba(31, 45, 31, 0.08);

    --bg-gradient: radial-gradient(ellipse at top, rgba(45, 80, 64, 0.06), transparent 50%);
    --header-bg: rgba(245, 241, 232, 0.92);
}

/* =============== TEMA ESMERALDA =============== */
[data-theme="emerald"] {
    --bg: #0f1a14;
    --bg-elev: #182620;
    --bg-elev-2: #20322a;
    --surface: #1d2c25;
    --border: #324a3e;
    --border-soft: #283b32;

    --text: #e8f0ea;
    --text-soft: #a8baad;
    --text-muted: #6e8275;

    --accent: #2dd47c;
    --accent-hover: #3eeb8d;
    --accent-soft: rgba(45, 212, 124, 0.15);
    --accent-glow: rgba(45, 212, 124, 0.35);

    --star: #f4c430;
    --star-empty: rgba(244, 196, 48, 0.20);
    --success: #2dd47c;
    --danger: #e35c5c;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.7);
    --shadow-cover: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.4);

    --bg-gradient: radial-gradient(ellipse at top, rgba(45, 212, 124, 0.08), transparent 50%);
    --header-bg: rgba(15, 26, 20, 0.85);
}

:root {
    --radius: 6px;
    --radius-lg: 12px;
    --font-serif: 'Fraunces', Georgia, serif;
    --font-sans: 'Inter', -apple-system, system-ui, sans-serif;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body {
    background: var(--bg-gradient), var(--bg);
}

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

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

/* HEADER */
.header {
    border-bottom: 1px solid var(--border);
    padding: 32px 0 0;
    background: var(--header-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-family: var(--font-serif);
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}
.logo-icon { color: var(--accent); font-size: 28px; }

.logo-img {
    height: 32px;
    width: auto;
    display: block;
}
.logo-img-sm {
    height: 22px;
    width: auto;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}
.admin-header h1 .logo-img-sm {
    height: 24px;
    margin-right: 6px;
}

.user-tag {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-muted);
}
.user-tag a { color: var(--accent); }

.tabs {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}
.tab {
    padding: 14px 22px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 2px solid transparent;
    transition: color 0.25s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}
.tab:hover { color: var(--text-soft); }
.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
.count {
    background: var(--bg-elev-2);
    color: var(--text-muted);
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 20px;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}
.tab.active .count { background: var(--accent); color: white; }

/* GRID DE LIBROS */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    padding: 36px 0 60px;
}
@media (min-width: 540px)  { .grid { grid-template-columns: repeat(3, 1fr); gap: 22px; } }
@media (min-width: 800px)  { .grid { grid-template-columns: repeat(4, 1fr); gap: 26px; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(5, 1fr); gap: 30px; } }

.book {
    cursor: pointer;
    position: relative;
}

.cover-wrap {
    position: relative;
    aspect-ratio: 2/3;
    background: var(--bg-elev);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-cover);
    transition: box-shadow 0.3s ease;
    background-image:
        linear-gradient(135deg, rgba(255,255,255,0.015) 0%, transparent 50%, rgba(0,0,0,0.15) 100%),
        radial-gradient(ellipse at center, var(--bg-elev) 0%, var(--bg) 100%);
}

@media (hover: hover) {
    .book:hover .cover-wrap {
        box-shadow:
            0 8px 20px rgba(0, 0, 0, 0.4),
            0 24px 60px rgba(0, 0, 0, 0.3),
            0 0 0 1px var(--accent-glow),
            0 0 32px var(--accent-glow);
    }
}

.cover-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.no-cover {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    font-family: var(--font-serif);
    font-weight: 600;
    color: var(--text-soft);
    font-size: 14px;
    line-height: 1.3;
    background: linear-gradient(135deg, var(--bg-elev-2), var(--bg));
    position: relative;
}
.no-cover::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.5;
}

/* FRANJA "LEÍDO" */
.read-strip {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.96) 0%, rgba(0,0,0,0.85) 70%, rgba(0,0,0,0) 100%);
    color: #fff;
    padding: 18px 10px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    z-index: 2;
}
.read-strip-label { color: #fff; }
.read-strip-divider { color: rgba(255,255,255,0.5); margin: 0 2px; }
.read-strip-stars {
    color: var(--star);
    font-size: 13px;
    letter-spacing: 1px;
    line-height: 1;
}
.read-strip-stars .off { color: rgba(255, 255, 255, 0.25); }

@media (max-width: 540px) {
    .read-strip-label, .read-strip-divider { display: none; }
    .read-strip { padding: 16px 8px 7px; }
    .read-strip-stars { font-size: 14px; }
}
.read-strip.no-stars .read-strip-divider { display: none; }

/* MODAL */
.modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: fadeIn 0.25s ease;
}
.modal.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 780px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 16px; right: 16px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    width: 36px; height: 36px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    color: var(--text);
    line-height: 1;
    z-index: 10;
    transition: all 0.2s ease;
}
.modal-close:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.modal-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 32px;
    padding: 32px;
}
@media (max-width: 640px) {
    .modal-grid { grid-template-columns: 1fr; padding: 24px; gap: 20px; }
}

.modal-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    background: var(--bg-elev-2);
}
.modal-content h2 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin-bottom: 6px;
}
.modal-author {
    color: var(--text-soft);
    font-size: 17px;
    margin-bottom: 16px;
    font-style: italic;
}
.stars-big {
    font-size: 24px;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-bottom: 20px;
}
.stars-big .on { color: var(--star); }

.modal-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 24px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.modal-meta-item { font-size: 13px; }
.modal-meta-label {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
}
.modal-meta-value { color: var(--text); }

/* EMPTY / FOOTER */
.empty {
    text-align: center;
    padding: 100px 20px;
    color: var(--text-muted);
}
.empty p {
    font-family: var(--font-serif);
    font-size: 22px;
    margin-bottom: 24px;
    color: var(--text-soft);
}

.footer {
    margin-top: 80px;
    padding: 32px 0;
    border-top: 1px solid var(--border);
    text-align: center;
}
.footer a {
    color: var(--text-muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin: 0 8px;
}
.footer a:hover { color: var(--accent); }

/* BOTONES */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    background: var(--accent);
    color: white;
    border-radius: var(--radius);
    text-decoration: none;
    border: 1px solid var(--accent);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}
.btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-soft);
}
.btn-secondary {
    background: var(--bg-elev-2);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--surface);
    border-color: var(--text-muted);
    box-shadow: none;
    color: var(--text);
}
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-ghost {
    background: transparent;
    color: var(--text-soft);
    border-color: var(--border);
}
.btn-ghost:hover {
    background: var(--bg-elev-2);
    color: var(--text);
    box-shadow: none;
}

/* PANEL ADMIN */
.admin-header {
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    padding: 18px 0;
}
.admin-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}
.admin-header h1 {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}
.admin-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.admin-nav a {
    color: var(--text-soft);
    font-size: 13px;
    padding: 8px 14px;
    border-radius: var(--radius);
    transition: all 0.2s ease;
    font-weight: 500;
}
.admin-nav a:hover, .admin-nav a.active {
    color: var(--text);
    background: var(--bg-elev-2);
}

.admin-main { padding: 32px 0 60px; }

.page-title {
    font-family: var(--font-serif);
    font-size: 26px;
    font-weight: 600;
    margin: 0 0 22px;
    color: var(--text);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* CARDS */
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 24px;
}
.card h2 {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 18px;
    letter-spacing: -0.01em;
}

/* STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    padding: 24px;
    border-radius: var(--radius-lg);
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}
.stat::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.25s ease;
}
.stat:hover {
    border-color: var(--text-muted);
    transform: translateY(-2px);
}
.stat:hover::before { opacity: 1; }

.stat-num {
    font-family: var(--font-serif);
    font-size: 38px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1;
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

/* GRÁFICO MENSUAL */
.month-chart {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 8px;
    align-items: end;
    height: 180px;
    padding: 16px 0 0;
}
.month-bar {
    /*
        Cada columna se compone de:
          1) un "track" que ocupa todo el alto del grid y donde la barra
             se posiciona en absoluto, anclada al inferior — esto evita que
             el espacio del label (que va FUERA del track) afecte al cálculo del %.
          2) el label (mes), debajo del track, con altura propia.
        El gap del grid se respeta y la altura del track es 100% del .month-chart.
    */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    height: 100%;
}
.month-bar-track {
    position: relative;
    flex: 1;
    min-height: 0;
}
.month-bar-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, var(--accent), var(--accent-hover));
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}
.month-bar-fill:hover { filter: brightness(1.15); }
.month-bar-fill.zero {
    background: var(--bg-elev-2);
    min-height: 3px;
    opacity: 0.5;
}
.month-bar-num {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    font-family: var(--font-serif);
    white-space: nowrap;
}
.month-bar-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.year-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.year-pill {
    padding: 5px 12px;
    background: var(--bg-elev-2);
    color: var(--text-soft);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-weight: 500;
    font-family: inherit;
}
.year-pill:hover { color: var(--text); border-color: var(--text-muted); }
.year-pill.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ===========================
   FORMULARIO - inputs estilizados
   =========================== */
.form-row { margin-bottom: 16px; }
.form-row label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 7px;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.form-row input,
.form-row textarea,
.form-row select,
.input-styled {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
    line-height: 1.5;
}
.form-row select,
.input-styled[as="select"],
select.input-styled {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 9L1.5 4.5h9z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}
.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus,
.input-styled:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-row input::placeholder,
.form-row textarea::placeholder,
.input-styled::placeholder { color: var(--text-muted); }
.form-row textarea { resize: vertical; min-height: 90px; }
.form-row input[type="file"] {
    padding: 10px;
    cursor: pointer;
    background: var(--bg-elev-2);
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

/* Evita que inputs (sobre todo type=date en iOS Safari) se salgan del grid.
   El min-width:0 permite que los grid items respeten el ancho de su columna,
   y el max-width:100% en inputs evita que crezcan más allá del padre.
   El box-sizing asegura que padding y border cuenten dentro del 100%. */
.form-grid > .form-row,
.form-grid .form-row {
    min-width: 0;
    max-width: 100%;
}
.form-row input,
.form-row select,
.form-row textarea {
    box-sizing: border-box;
    max-width: 100%;
}
.form-row input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
}

/* En móvil, el grid pasa a una sola columna sin minmax para evitar overflow */
@media (max-width: 700px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* TOOLBAR (header de cards con título + botones de acción) */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.toolbar h2 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
}

/* BUSCADOR del admin */
.search-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.search-bar input,
.search-bar select {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
    line-height: 1.5;
}
.search-bar input { flex: 1; min-width: 220px; }
.search-bar select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 9L1.5 4.5h9z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    min-width: 160px;
    cursor: pointer;
}
.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* LISTA ADMIN */
.book-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.book-row {
    display: grid;
    grid-template-columns: 60px 1fr auto;
    gap: 16px;
    align-items: center;
    background: var(--bg-elev-2);
    border: 1px solid var(--border-soft);
    padding: 12px 14px;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}
.book-row:hover {
    border-color: var(--text-muted);
    background: var(--surface);
}
.book-row img,
.book-row .no-cover-sm {
    width: 60px;
    height: 90px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--bg);
    box-shadow: var(--shadow-sm);
}
.book-row .no-cover-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-muted);
}
.book-row-info .title {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 4px;
}
.book-row-info .meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.book-row-info .meta-stars {
    color: var(--star);
    font-size: 13px;
    letter-spacing: 1px;
    margin-top: 4px;
    line-height: 1;
}
.book-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.tag {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.tag-read {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

/* RATING INPUT - estrellas con borde */
.rating-input {
    display: inline-flex;
    flex-direction: row-reverse;
    gap: 2px;
    align-items: center;
}
.rating-input input { display: none; }
.rating-input label {
    cursor: pointer;
    font-size: 32px;
    line-height: 1;
    color: transparent;
    -webkit-text-stroke: 1.5px var(--text-muted);
    text-stroke: 1.5px var(--text-muted);
    transition: all 0.15s ease;
    margin: 0;
}
.rating-input label:hover,
.rating-input label:hover ~ label {
    color: var(--star);
    -webkit-text-stroke-color: var(--star);
}
.rating-input input:checked ~ label {
    color: var(--star);
    -webkit-text-stroke-color: var(--star);
}
.rating-input:hover input:checked ~ label {
    color: transparent;
    -webkit-text-stroke-color: var(--text-muted);
}
.rating-input:hover label:hover,
.rating-input:hover label:hover ~ label {
    color: var(--star);
    -webkit-text-stroke-color: var(--star);
}

/* ===========================================================
   STAR RATING NUEVO (orden natural 1→5, robusto en móvil)
   =========================================================== */
.star-rating {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.star-btn {
    background: none;
    border: none;
    padding: 6px 4px;
    margin: 0;
    cursor: pointer;
    font-size: 32px;
    line-height: 1;
    color: transparent;
    -webkit-text-stroke: 1.5px var(--text-muted);
    text-stroke: 1.5px var(--text-muted);
    transition: color 0.15s ease, -webkit-text-stroke-color 0.15s ease;
    font-family: inherit;
    /* Ampliar área táctil sin afectar visualmente */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.star-btn.on {
    color: var(--star);
    -webkit-text-stroke-color: var(--star);
}
.star-btn:focus { outline: none; }
.star-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.star-clear {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    margin-left: 12px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    transition: all 0.15s ease;
    font-family: inherit;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.star-clear:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* CHECKBOX */
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* TOGGLE SWITCH */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 26px;
    cursor: pointer;
    transition: all 0.25s ease;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: var(--text-soft);
    border-radius: 50%;
    transition: all 0.25s ease;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: white;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-soft);
    gap: 20px;
}
.setting-row:last-child { border-bottom: none; }

/* ALERTAS */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid;
}
.alert-success {
    background: rgba(74, 124, 89, 0.15);
    color: var(--success);
    border-color: rgba(74, 124, 89, 0.4);
}
.alert-error {
    background: rgba(168, 50, 50, 0.15);
    color: var(--danger);
    border-color: rgba(168, 50, 50, 0.4);
}
.alert-info {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

/* LOGIN / REGISTRO */
.login-box {
    max-width: 420px;
    margin: 80px auto;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    padding: 40px 36px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    position: relative;
}
.login-box::before {
    content: '';
    position: absolute;
    top: 0; left: 30%; right: 30%;
    height: 1px;
}
.login-box h1 {
    font-family: var(--font-serif);
    text-align: center;
    margin-bottom: 28px;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.login-link {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-muted);
}
.login-link a { color: var(--accent); font-weight: 500; }

/* TURNSTILE */
.cf-turnstile {
    margin: 14px 0;
    display: flex;
    justify-content: center;
}

/* SPINNER */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SCROLLBAR */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
    background: var(--bg-elev-2);
    border-radius: 10px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border); }

::selection {
    background: var(--accent);
    color: white;
}

/* ==========================================================
   AJUSTES RESPONSIVE - MÓVIL
   ========================================================== */

@media (max-width: 700px) {

    /* HEADER ADMIN ====================================
       Para que el nav nunca se salga del viewport en móvil:
       - container con overflow:hidden contiene el nav
       - nav con overflow-x:auto permite scroll horizontal interno
       - el padding-left/right del scroll va al contenido, no al border
       - max-width: 100% asegura que el nav nunca exceda el container */
    .admin-header {
        overflow: hidden;
    }
    .admin-header .container {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        max-width: 100%;
        overflow: hidden;
    }
    .admin-header h1 {
        text-align: left;
        font-size: 17px;
        word-break: break-word;
        line-height: 1.3;
    }
    .admin-nav {
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 4px;
        margin: 0;
        max-width: 100%;
        /* Indicador visual de que hay más contenido al hacer scroll */
        mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
        -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
    }
    .admin-nav::-webkit-scrollbar { height: 0; display: none; }
    .admin-nav a {
        font-size: 12px;
        padding: 6px 12px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* STATS COMPACTAS ==================================
       En vez de cada stat ocupar ancho completo, mostramos 2x3
       para que la zona ocupe menos altura. */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 18px;
    }
    .stat {
        padding: 14px 14px;
    }
    .stat-num {
        font-size: 24px;
    }
    .stat-label {
        font-size: 10px;
        margin-top: 4px;
        letter-spacing: 0.06em;
    }

    /* CARDS más compactas en móvil */
    .card { padding: 18px; }
    .card h2 { font-size: 18px; margin-bottom: 14px; }

    /* GRÁFICO MENSUAL más pequeño */
    .month-chart {
        height: 130px;
        gap: 4px;
    }
    .month-bar-label { font-size: 9px; }
    .month-bar-num { font-size: 10px; top: -16px; }

    /* TARJETA DE COMPARTIR (admin) reorganizada vertical */
    .share-card {
        padding: 16px 18px;
        gap: 12px;
    }
    .share-icon { font-size: 24px; }
    .share-title { font-size: 14px; }
    .share-url { font-size: 11px; padding: 5px 8px; }
    .share-actions { width: 100%; justify-content: flex-start; }

    /* LISTA DE LIBROS (admin) ===========================
       En móvil: ocultar botón eliminar, apilar leído/editar
       en columna a la derecha. */
    .book-row {
        grid-template-columns: 50px 1fr auto;
        gap: 12px;
        padding: 10px 12px;
    }
    .book-row img,
    .book-row .no-cover-sm {
        width: 50px;
        height: 75px;
    }
    .book-row-info .title {
        font-size: 14px;
        line-height: 1.25;
    }
    .book-row-info .meta {
        font-size: 11px;
        gap: 6px;
    }
    .book-row-actions {
        flex-direction: column;
        gap: 5px;
    }
    .book-row-actions .btn {
        padding: 6px 10px;
        font-size: 11px;
        min-width: 56px;
    }
    /* Ocultar botón eliminar en móvil. Sigue accesible desde la edición. */
    .book-row-actions .btn-danger {
        display: none;
    }

    /* TOOLBAR del admin (título + botón añadir) */
    .toolbar {
        gap: 10px;
        margin-bottom: 16px;
    }
    .toolbar h2 { font-size: 18px; }

    /* SEARCH BAR: que el filtro vaya debajo en móvil */
    .search-bar {
        flex-direction: column;
        gap: 8px;
    }
    .search-bar input,
    .search-bar select {
        min-width: 0;
        width: 100%;
    }
}

/* ==========================================================
   PAGINACIÓN PÚBLICA - botón "Cargar más"
   ========================================================== */
.load-more-wrap {
    text-align: center;
    padding: 24px 0 60px;
}
.load-more-btn {
    padding: 14px 32px;
    font-size: 14px;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.load-more-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-1px);
}
.load-more-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}
.load-more-info {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}


/* ===========================================================
   BARRA DE PROGRESO DE LECTURA
   =========================================================== */
.progress-track {
    width: 100%;
    height: 8px;
    background: var(--bg-elev-2);
    border-radius: 100px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--accent), var(--accent-hover));
    border-radius: 100px;
    transition: width 0.4s cubic-bezier(0.2, 0.9, 0.3, 1);
    width: 0%;
    min-width: 0;
}

/* ===========================================================
   SECCIÓN "ACTUALMENTE LEYENDO" - destacada arriba del listado
   =========================================================== */
.reading-now-section {
    margin-bottom: 24px;
}
.reading-now-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 14px;
}
.reading-now-header h2 {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
    margin: 0;
}
.reading-now-count {
    color: var(--text-muted);
    font-size: 13px;
}

/* Cards horizontales de "actualmente leyendo" en el admin */
.reading-now-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}
.reading-now-card {
    background: var(--bg-elev-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 14px;
    display: grid;
    grid-template-columns: 50px 1fr;
    gap: 12px;
    align-items: center;
    transition: all 0.2s ease;
}
.reading-now-card:hover {
    border-color: var(--accent);
    background: var(--surface);
}
.reading-now-card img,
.reading-now-card .no-cover-sm {
    width: 50px;
    height: 75px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--bg);
    box-shadow: var(--shadow-sm);
}
.reading-now-card .no-cover-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--text-muted);
}
.reading-now-info {
    min-width: 0;
}
.reading-now-info .title {
    font-family: var(--font-serif);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
    margin-bottom: 2px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.reading-now-info .author {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reading-now-info .progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 11px;
    color: var(--text-muted);
}
.reading-now-info .progress-row .pct {
    color: var(--accent);
    font-weight: 700;
    font-family: var(--font-serif);
    font-size: 13px;
}

/* En la vista pública, el grid ya muestra portadas igual que biblioteca */
