/* ── Variables ───────────────────────────────────────────── */
:root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --sidebar-bg: #1e2a3a;
    --sidebar-w: 240px;
    --topbar-h: 56px;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
}

/* ── Reset y base ────────────────────────────────────────── */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}

.topbar .brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .5rem;
    white-space: nowrap;
}

.topbar .brand:hover {
    color: var(--primary-dark);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1020;
    transition: transform .25s ease;
}

.sidebar .nav-section {
    padding: .5rem 1rem .25rem;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6b7a8d;
    margin-top: .5rem;
}

.sidebar .nav-link {
    color: #c9d1d9;
    padding: .5rem 1rem;
    border-radius: 6px;
    margin: 1px 8px;
    font-size: .88rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.sidebar .nav-link.active {
    background: var(--primary);
    color: #fff;
}

.sidebar .nav-link .icon {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Contenido principal ─────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    margin-top: var(--topbar-h);
    padding: 1.5rem;
    min-height: calc(100vh - var(--topbar-h));
}

/* Layout sin sidebar (login, catálogo público) */
.no-sidebar .main-content {
    margin-left: 0;
}

/* ── Tarjetas ────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: .85rem 1.25rem;
    border-radius: 10px 10px 0 0 !important;
}

/* ── Stats cards ─────────────────────────────────────────── */
.stat-card {
    border-radius: 10px;
    padding: 1.25rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    font-size: 2rem;
    opacity: .85;
}

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

.stat-card .stat-label {
    font-size: .8rem;
    opacity: .85;
}

/* ── Badges de estado ────────────────────────────────────── */
.badge-active {
    background: #d1fae5;
    color: #065f46;
}

.badge-blocked-n1 {
    background: #fef3c7;
    color: #92400e;
}

.badge-suspended {
    background: #fee2e2;
    color: #991b1b;
}

.badge-available {
    background: #d1fae5;
    color: #065f46;
}

.badge-loaned {
    background: #dbeafe;
    color: #1e40af;
}

.badge-lost {
    background: #fee2e2;
    color: #991b1b;
}

.badge-damaged {
    background: #fef3c7;
    color: #92400e;
}

.badge-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.badge-returned {
    background: #f3f4f6;
    color: #374151;
}

.badge-pending {
    background: #fef3c7;
    color: #92400e;
}

.badge-approved {
    background: #d1fae5;
    color: #065f46;
}

.badge-rejected {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Tablas ──────────────────────────────────────────────── */
.table th {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: #f8f9fa;
}

.table td {
    vertical-align: middle;
    font-size: .9rem;
}

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

/* ── Formularios ─────────────────────────────────────────── */
.form-label {
    font-weight: 500;
    font-size: .9rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .15);
}

/* ── Botones ─────────────────────────────────────────────── */
.btn {
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 500;
}

.btn-sm {
    padding: .25rem .6rem;
    font-size: .8rem;
}

/* ── HTMX loading indicator ──────────────────────────────── */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

/* ── Spinner inline ──────────────────────────────────────── */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: .15em;
}

/* ── Toast / alertas flotantes ───────────────────────────── */
#toast-container {
    position: fixed;
    top: calc(var(--topbar-h) + 1rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.toast-msg {
    padding: .75rem 1.25rem;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
    animation: slideIn .25s ease;
    min-width: 280px;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.toast-msg.success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid #10b981;
}

.toast-msg.error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}

.toast-msg.info {
    background: #dbeafe;
    color: #1e40af;
    border-left: 4px solid #3b82f6;
}

.toast-msg.warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid #f59e0b;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Login page ──────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #0d6efd 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
    border: none;
}

.login-logo {
    font-size: 2.5rem;
    margin-bottom: .5rem;
}

/* ── Paginación ──────────────────────────────────────────── */
.pagination .page-link {
    color: var(--primary);
    border-radius: 6px;
    margin: 0 2px;
    font-size: .875rem;
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* ── Catálogo público ────────────────────────────────────── */
.catalog-hero {
    background: linear-gradient(135deg, #1e3a5f 0%, #0d6efd 100%);
    color: #fff;
    padding: 3rem 1.5rem;
    text-align: center;
}

.catalog-card {
    transition: transform .2s, box-shadow .2s;
    height: 100%;
}

.catalog-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}

.catalog-card .material-type-badge {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }
}

/* ── Portadas del catálogo ───────────────────────────────── */
.catalog-cover-wrapper {
    position: relative;
    transition: transform .2s ease;
}

.catalog-card:hover .catalog-cover-wrapper {
    transform: scale(1.02);
}

.catalog-cover-img {
    transition: opacity .3s ease;
}

.catalog-cover-img[style*="display:none"]+.catalog-cover-placeholder {
    display: flex !important;
}

/* Badge digital en catálogo */
.badge-digital {
    background: rgba(13, 110, 253, 0.12);
    color: #0d6efd;
    border: 1px solid rgba(13, 110, 253, 0.25);
}