@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ===========================
   Variables
   =========================== */
:root {
    --primary-color: #2563eb;
    --accent-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --text-color: #1f2937;
    --heading-color: #111827;
    --card-bg: rgba(255, 255, 255, 0.96);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.07);
    --border-radius: 14px;
    --transition: all 0.25s ease;
}

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

body {
    margin: 0;
    padding: 20px;
    font-family: 'Inter', sans-serif;
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    background: transparent;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Imagen de fondo desenfocada */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url('../images/escuela-background.jpeg');
    background-size: cover;
    background-position: center;
    filter: blur(2px);
    transform: scale(1.02);
    z-index: -2;
}

/* Overlay blanco para legibilidad */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.83);
    z-index: -1;
}

/* ===========================
   Layout
   =========================== */
.container, .admin-container {
    max-width: 960px;
    margin: 20px auto;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 2em;
}

/* ===========================
   Header
   =========================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2em;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 1em;
}

.header h2 {
    color: var(--heading-color);
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
    font-size: 1.5rem;
}

.user-profile {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
    flex-shrink: 0;
}

.user-profile span {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

/* ===========================
   Buttons
   =========================== */
button, .btn {
    display: inline-block;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: #fff !important;
    min-height: 40px;
    text-align: center;
    text-decoration: none;
    line-height: 1.4;
    background: var(--primary-color);
    font-family: 'Inter', sans-serif;
}

button:hover, .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary  { background: var(--primary-color); }
.btn-primary:hover  { background: #1d4ed8; }
.btn-success  { background: var(--accent-color); }
.btn-success:hover  { background: #059669; }
.btn-danger   { background: var(--error-color); }
.btn-danger:hover   { background: #dc2626; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; }

.btn-anim {
    transition: transform .12s, box-shadow .12s;
    display: inline-block;
    text-decoration: none;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 14px;
    font-weight: 600;
    background: var(--primary-color);
    color: #fff !important;
    border: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}

.btn-anim:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

/* ===========================
   Forms & Inputs
   =========================== */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
textarea,
select,
.form-control,
.form-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    font-size: 15px;
    transition: var(--transition);
    background-color: #fff;
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    box-sizing: border-box;
    margin-bottom: 0.75rem;
    display: block;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
    background-color: #fff;
    outline: none;
}

label {
    display: block;
    font-size: 0.9rem;
    color: #374151;
    margin-bottom: 0.3rem;
    font-weight: 500;
}

/* ===========================
   Tables
   =========================== */
table {
    width: 100%;
    border-collapse: collapse;
    border-radius: var(--border-radius);
    overflow: hidden;
    margin-bottom: 2em;
}

th {
    background: var(--primary-color);
    color: #fff !important;
    padding: 13px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
}

td {
    padding: 12px 14px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    color: var(--text-color) !important;
    font-size: 14px;
}

tbody tr:hover td {
    background: #f3f4f6;
}

.overdue td {
    background-color: #fee2e2 !important;
    color: #991b1b !important;
}

/* ===========================
   Table Sections
   =========================== */
.table-section {
    margin-bottom: 2.5em;
}

.table-section h3 {
    color: var(--heading-color);
    border-left: 5px solid var(--primary-color);
    padding-left: 12px;
    margin-bottom: 1.2em;
    font-weight: 700;
}

/* ===========================
   Flash Messages
   =========================== */
.flash-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.flash-success {
    background: #f0fdf4;
    color: #166534 !important;
    border-color: #dcfce7;
}

.flash-error {
    background: #fef2f2;
    color: #991b1b !important;
    border-color: #fecaca;
}

/* ===========================
   Login
   =========================== */
.login-container {
    max-width: 420px;
    margin: 60px auto;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    padding: 2.5em;
    text-align: center;
}

.login-container h2,
.login-container p,
.login-container label,
.login-container small {
    color: var(--text-color) !important;
    margin-bottom: 0.75rem;
}

.escudo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 1rem;
}

/* ===========================
   Search Forms
   =========================== */
.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin: 0.75rem 0 1.25rem 0;
}

.search-form input,
.search-form select {
    flex: 1;
    min-width: 120px;
    margin-bottom: 0;
}

.search-form button,
.search-form .btn-anim {
    flex-shrink: 0;
}

.search-form-extended {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 1em;
}

.search-form-extended input[type='text'] {
    flex: 1 1 200px;
    min-width: 0;
    margin-bottom: 0;
}

.search-form-extended select {
    flex: 0 0 auto;
    width: auto;
    min-width: 160px;
    padding: 0.6em 1em;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background-color: #fff;
    font-size: 14px;
    color: var(--text-color);
    cursor: pointer;
    margin-bottom: 0;
}

.search-form-extended select:hover {
    border-color: #888;
}

.search-form-extended select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.search-form-extended button,
.search-form-extended .btn,
.search-form-extended .btn-secondary {
    flex-shrink: 0;
    white-space: nowrap;
}

/* ===========================
   Document Cards
   =========================== */
.doc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.doc-card {
    background: #fff;
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    border: 1px solid #f1f5f9;
    transition: transform .18s, box-shadow .18s;
    width: calc(33.333% - 0.68rem);
    box-sizing: border-box;
}

.doc-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

/* ===========================
   Book Form (admin_libros)
   =========================== */
.book-form {
    background: #fff;
    padding: 1.25rem;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
    margin-bottom: 1.25rem;
}

.book-form .form-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: flex-start;
}

.book-form .field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-form .field.small {
    flex: 0 0 110px;
}

.book-form label {
    font-size: 0.85rem;
    color: #334155;
    margin-bottom: 0.35rem;
    font-weight: 500;
}

.book-form input,
.book-form textarea,
.book-form select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #e6e9ef;
    border-radius: 8px;
    background: #fff;
    color: var(--text-color);
    box-sizing: border-box;
    margin-bottom: 0;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
}

.book-form textarea { resize: vertical; }

.book-form .form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.book-form .btn-anim {
    padding: 0.55rem 1rem;
    border-radius: 8px;
}

/* ===========================
   Book Detail & Prestar layout
   =========================== */
.book-header, .prestar-main {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.book-header .cover,
.prestar-main .cover-col {
    width: 160px;
    flex-shrink: 0;
}

.book-header .cover img,
.prestar-main .cover-col img {
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.book-header .meta,
.prestar-main .meta-col {
    flex: 1;
    min-width: 0;
}

/* ===========================
   Upload Form (admin bib virtual)
   =========================== */
.upload-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 0.6rem;
}

.upload-form-row input[type="text"],
.upload-form-row input[name="titulo"] {
    flex: 1 1 160px;
    min-width: 0;
    margin-bottom: 0;
}

.upload-form-row input[type="file"] {
    flex: 0 1 auto;
    margin-bottom: 0;
    border-radius: 8px;
    border: 1px solid #e6e9ef;
    padding: 6px 8px;
    background: #fff;
    font-size: 13px;
}

.upload-form-row button {
    flex-shrink: 0;
}

.upload-form-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-start;
    margin-bottom: 0.6rem;
}

.upload-form-meta input {
    flex: 1 1 110px;
    min-width: 0;
    margin-bottom: 0;
}

.upload-form-meta textarea {
    flex: 2 1 180px;
    min-width: 0;
    margin-bottom: 0;
    resize: vertical;
}

/* ===========================
   Admin UI
   =========================== */
.admin-back {
    display: inline-flex;
    gap: .6rem;
    align-items: center;
    padding: .45rem .75rem;
    background: #f8fafc;
    border-radius: 10px;
    color: #0f172a !important;
    text-decoration: none;
    border: 1px solid #e6e9ef;
    font-weight: 600;
    font-size: 14px;
}

.admin-back:hover {
    background: #fff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
    transform: translateY(-2px);
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.doc-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem;
    border-bottom: 1px solid #f1f5f9;
    flex-wrap: wrap;
}

.doc-row .meta {
    flex: 1;
    min-width: 0;
}

.doc-row .meta .title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-row .meta .desc {
    color: #64748b;
    font-size: .9rem;
    margin-top: .25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.admin-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

.admin-actions .btn-anim {
    padding: .35rem .6rem;
    font-size: .85rem;
    border-radius: 8px;
}

.admin-actions .btn-danger {
    background: #ef4444;
    color: #fff !important;
    border: none;
}

/* ===========================
   Cards (genérico)
   =========================== */
.card {
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5em;
    margin-bottom: 1.5em;
}

/* ===========================
   Recommendations (dashboard)
   =========================== */
.recommendations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5em;
    margin-bottom: 2em;
}

.recommendation-section {
    background: #fff;
    padding: 1.5em;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.recommendation-section h3 {
    margin-top: 0;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5em;
    margin-bottom: 1em;
}

.reco-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.75em;
}

.reco-card {
    display: block;
    padding: 0.85em 1em;
    background-color: #f8f9fa;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-color) !important;
    transition: background-color 0.3s, transform 0.2s;
}

.reco-card:hover {
    background-color: #e9ecef;
    transform: translateY(-2px);
}

.reco-card-title {
    font-weight: bold;
    margin: 0 0 0.2em 0;
    font-size: 0.95rem;
    color: var(--text-color) !important;
}

.reco-card-author {
    font-size: 0.85em;
    color: #666 !important;
    margin: 0;
}

.reco-card-stat {
    font-size: 0.8em;
    color: var(--primary-color) !important;
    font-weight: bold;
    margin-top: 0.4em;
}

/* ===========================
   Progress bar
   =========================== */
.upload-progress {
    height: 8px;
    background: #eee;
    border-radius: 6px;
    overflow: hidden;
    margin-top: .5rem;
}

.upload-progress > i {
    display: block;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #06b6d4);
    transition: width .2s linear;
}

/* ===========================
   Scroll to top
   =========================== */
.scroll-to-top-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
}

.scroll-to-top-btn {
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 1.4em;
    line-height: 1;
    padding: 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===========================
   Animations & Utilities
   =========================== */
.page-fade { animation: fadeIn 400ms ease-out both; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid #eee;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.skeleton {
    background: linear-gradient(90deg, #efefef 25%, #f6f6f6 50%, #efefef 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
    border-radius: 6px;
}

[x-cloak] { display: none !important; }

/* ===========================
   RESPONSIVE — Tablet (≤ 992px)
   =========================== */
@media (max-width: 992px) {
    body { padding: 14px; }

    .container, .admin-container {
        max-width: 100%;
        padding: 1.5em;
    }

    .header h2 { font-size: 1.3rem; }

    .doc-card { width: calc(50% - 0.5rem); }

    .admin-content {
        grid-template-columns: 1fr !important;
    }

    .book-form .form-row { flex-direction: column; gap: 0.5rem; }
    .book-form .field.small { flex: 1; width: 100%; }
}

/* ===========================
   RESPONSIVE — Móvil grande (≤ 768px)
   =========================== */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        padding: 8px;
        overflow-x: hidden;
    }

    .container, .admin-container, .login-container {
        padding: 1.1em;
        margin: 8px auto;
        border-radius: 10px;
    }

    /* ---- Header ---- */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
    }

    .user-profile {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .user-profile span {
        width: 100%;
        max-width: 100%;
        font-size: 0.82rem;
        color: #4b5563;
    }

    .header .btn,
    .header a.btn {
        font-size: 13px;
        padding: 8px 12px;
        min-height: 36px;
    }

    /* ---- Tables → tarjetas ---- */
    table, thead, tbody, th, td, tr { display: block; }

    thead { display: none; }

    tr {
        margin-bottom: 0.85rem;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        padding: 0.6rem 0.75rem;
        background: #fff;
    }

    .overdue tr {
        border-color: #fca5a5 !important;
    }

    td {
        border: none;
        border-bottom: 1px solid #f3f4f6;
        padding: 7px 0;
        display: flex;
        align-items: flex-start;
        gap: 0.5rem;
        background: transparent !important;
    }

    td:last-child { border-bottom: none; }

    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #374151;
        min-width: 110px;
        flex-shrink: 0;
        font-size: 13px;
        padding-top: 1px;
    }

    /* Overdue mobile */
    .overdue td { color: #991b1b !important; }

    /* ---- Book header / prestar → apilado ---- */
    .book-header, .prestar-main {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .book-header .cover,
    .prestar-main .cover-col {
        width: 130px;
        margin: 0 auto 0.75rem;
    }

    .book-header .meta,
    .prestar-main .meta-col {
        width: 100%;
        text-align: left;
    }

    /* ---- Search forms ---- */
    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form input,
    .search-form button,
    .search-form .btn-anim {
        width: 100%;
        min-width: 0;
        margin-bottom: 0;
    }

    .search-form-extended {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form-extended input,
    .search-form-extended select,
    .search-form-extended button,
    .search-form-extended .btn,
    .search-form-extended .btn-secondary {
        width: 100%;
        min-width: 0;
        margin-bottom: 0;
    }

    /* ---- Upload form ---- */
    .upload-form-row,
    .upload-form-meta {
        flex-direction: column;
        align-items: stretch;
    }

    .upload-form-row input,
    .upload-form-row input[type="file"],
    .upload-form-meta input,
    .upload-form-meta textarea {
        width: 100%;
        flex: none;
    }

    /* ---- Doc cards ---- */
    .doc-card { width: 100%; }

    .doc-list { flex-direction: column; }

    /* ---- Admin doc row ---- */
    .doc-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

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

    /* ---- Form submit buttons ---- */
    form button[type="submit"],
    .book-form .btn-anim,
    .loan-form-container .btn {
        width: 100%;
    }

    .book-form .form-actions {
        flex-direction: column;
    }

    /* ---- Flash ---- */
    .flash-message {
        font-size: 0.9rem;
        padding: 10px 12px;
    }

    /* ---- Login ---- */
    .login-container {
        margin-top: 20px;
    }

    /* ---- Recommendations grid ---- */
    .recommendations-grid {
        grid-template-columns: 1fr;
        gap: 1em;
    }

    /* ---- Scroll to top ---- */
    .scroll-to-top-container {
        bottom: 1rem;
        right: 1rem;
    }
}

/* ===========================
   RESPONSIVE — Móvil pequeño (≤ 480px)
   =========================== */
@media (max-width: 480px) {
    body { padding: 5px; }

    h1 { font-size: 1.45rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.05rem; }

    .container, .admin-container {
        padding: 0.85em;
        border-radius: 8px;
    }

    .header h2 { font-size: 1.1rem; }

    .login-container {
        padding: 1.5em 1em;
        margin: 12px 0;
    }

    .escudo { width: 64px; height: 64px; }

    td::before {
        min-width: 95px;
        font-size: 12px;
    }

    .scroll-to-top-btn {
        width: 42px;
        height: 42px;
        min-height: 42px;
        font-size: 1.2em;
    }

    .btn, button {
        font-size: 13px;
        padding: 9px 14px;
    }
}
