:root {
    --color-primary: #0f172a;
    --color-secondary: #334155;
    --color-accent: #0369a1;
    --color-accent-hover: #075985;
    --color-background: #f8fafc;
    --color-surface: #ffffff;
    --color-muted: #e8ecf1;
    --color-muted-text: #475569;
    --color-border: #dbe3ec;
    --color-text: #0f172a;
    --color-danger: #b91c1c;
    --color-success: #166534;
    --color-warning: #92400e;
    --shadow: 0 12px 30px rgb(15 23 42 / 8%);
    --radius: 14px;
    --focus: 0 0 0 3px rgb(3 105 161 / 28%);
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--color-text);
    background: var(--color-background);
    font-size: 16px;
    line-height: 1.5;
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { min-width: 320px; background: var(--color-background); }
body { margin: 0; min-height: 100dvh; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.skip-link { position: fixed; left: 16px; top: -80px; z-index: 1000; padding: 12px 16px; background: var(--color-primary); color: white; border-radius: 8px; }
.skip-link:focus { top: 16px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.75rem, 3vw, 2.25rem); line-height: 1.15; letter-spacing: -.03em; }
h2 { margin-bottom: 4px; font-size: 1.15rem; }
.muted { color: var(--color-muted-text); margin-bottom: 0; }
.eyebrow { margin-bottom: 6px; color: var(--color-accent); font-weight: 750; font-size: .76rem; letter-spacing: .1em; text-transform: uppercase; }
.brand-mark { display: inline-grid; place-items: center; width: 88px; height: 88px; border: 2px solid rgb(255 255 255 / 45%); border-radius: 24px; font-weight: 850; font-size: 1.65rem; letter-spacing: .08em; }
.brand-mark-small { width: 48px; height: 48px; border-radius: 13px; font-size: .95rem; border-color: rgb(255 255 255 / 35%); }

.login-layout { min-height: 100dvh; display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 560px); }
.login-brand { padding: clamp(40px, 8vw, 110px); display: flex; flex-direction: column; justify-content: center; background: linear-gradient(145deg, #0f172a, #164e63); color: white; }
.login-brand h2 { max-width: 560px; margin: 48px 0 16px; font-size: clamp(2rem, 5vw, 4rem); line-height: 1.04; letter-spacing: -.045em; }
.login-brand p { max-width: 560px; color: #dbeafe; }
.login-card { width: min(420px, calc(100% - 40px)); align-self: center; justify-self: center; padding: 40px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 22px; box-shadow: var(--shadow); }
.login-card form { margin-top: 30px; }

.app-shell { min-height: 100dvh; padding-left: 272px; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; padding: 24px 18px; background: var(--color-primary); color: white; display: flex; flex-direction: column; z-index: 40; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; border-bottom: 1px solid rgb(255 255 255 / 12%); }
.sidebar-brand div { display: grid; }
.sidebar-brand span { color: #cbd5e1; font-size: .76rem; }
.main-nav { display: grid; gap: 6px; margin-top: 24px; }
.main-nav button { min-height: 48px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: #cbd5e1; text-align: left; font-weight: 650; }
.main-nav button:hover { background: rgb(255 255 255 / 8%); color: white; }
.main-nav button[aria-current="page"] { background: #0c4a6e; color: white; box-shadow: inset 3px 0 #38bdf8; }
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid rgb(255 255 255 / 12%); }
.user-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.user-summary > div { min-width: 0; display: grid; }
.user-summary strong, .user-summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-summary span { color: #cbd5e1; font-size: .8rem; }
.avatar { flex: 0 0 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: #0c4a6e; color: white; font-size: .8rem; font-weight: 800; }
.mobile-header, .mobile-nav { display: none; }

main { width: min(1440px, 100%); margin: 0 auto; padding: 40px clamp(24px, 4vw, 64px) 80px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric { min-height: 122px; padding: 20px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: 0 3px 12px rgb(15 23 42 / 4%); }
.metric strong { display: block; margin: 12px 0 2px; font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.metric span { color: var(--color-muted-text); font-size: .88rem; }
.panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: 0 3px 12px rgb(15 23 42 / 4%); overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px; border-bottom: 1px solid var(--color-border); }

.toolbar { display: flex; align-items: end; gap: 12px; padding: 16px; margin-bottom: 18px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.toolbar label, .field { display: grid; gap: 6px; color: var(--color-secondary); font-size: .84rem; font-weight: 700; }
.toolbar .search-field { flex: 1; min-width: 220px; }
input, select, textarea { width: 100%; min-height: 44px; padding: 9px 11px; color: var(--color-text); background: white; border: 1px solid #94a3b8; border-radius: 9px; }
textarea { min-height: 88px; resize: vertical; }
input::placeholder { color: #64748b; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-full { grid-column: 1 / -1; }
.check-field { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check-field input { width: 20px; min-height: 20px; }
.helper { color: var(--color-muted-text); font-size: .8rem; font-weight: 400; }
.form-error { margin: 14px 0 0; padding: 10px 12px; color: #7f1d1d; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; overflow-wrap: anywhere; }

.button { min-height: 44px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 720; transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { color: white; background: var(--color-accent); }
.button-primary:hover:not(:disabled) { background: var(--color-accent-hover); }
.button-secondary { color: var(--color-primary); background: white; border-color: #94a3b8; }
.button-secondary:hover:not(:disabled) { background: #f1f5f9; border-color: #64748b; }
.button-danger { color: white; background: var(--color-danger); }
.button-ghost { color: inherit; background: transparent; border-color: currentColor; }
.button-block { width: 100%; }
.button-small { min-height: 36px; padding: 6px 10px; font-size: .82rem; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
th { color: var(--color-secondary); background: #f8fafc; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
.cell-main { display: grid; gap: 2px; }
.cell-main span { color: var(--color-muted-text); font-size: .78rem; }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--color-border); color: var(--color-muted-text); font-size: .84rem; }
.status { display: inline-flex; align-items: center; min-height: 28px; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.status-disponible, .status-devuelto, .status-activo { color: var(--color-success); background: #dcfce7; }
.status-prestado, .status-vencido { color: var(--color-warning); background: #fef3c7; }
.status-baja, .status-inactivo { color: #64748b; background: #e2e8f0; }
.status-admin { color: #5b21b6; background: #ede9fe; }
.status-encargado { color: #075985; background: #e0f2fe; }
.status-estudiante { color: #166534; background: #dcfce7; }
.empty-state { padding: 48px 24px; text-align: center; }
.empty-state h3 { margin-bottom: 6px; }

dialog { width: min(720px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 28px 80px rgb(15 23 42 / 35%); }
dialog::backdrop { background: rgb(15 23 42 / 68%); }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 22px 24px; background: white; border-bottom: 1px solid var(--color-border); }
.dialog-header h2 { font-size: 1.35rem; }
.dialog-body { padding: 24px; overflow-y: auto; }
#dialog-error { margin: 0 24px 18px; }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; background: white; border-top: 1px solid var(--color-border); }
.timeline { display: grid; gap: 16px; }
.timeline-item { padding-left: 18px; border-left: 3px solid #7dd3fc; }
.timeline-item p { margin-bottom: 4px; }
.timeline-item time { color: var(--color-muted-text); font-size: .8rem; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: min(420px, calc(100% - 32px)); padding: 13px 16px; color: white; background: var(--color-primary); border-radius: 10px; box-shadow: var(--shadow); }

@media (max-width: 1000px) {
    .metric-grid { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
}

@media (max-width: 760px) {
    .login-layout { grid-template-columns: 1fr; }
    .login-brand { min-height: 250px; padding: 34px 24px; justify-content: flex-start; }
    .login-brand h2 { margin: 28px 0 10px; font-size: 2rem; }
    .login-card { margin: -32px auto 32px; z-index: 1; padding: 28px 22px; }
    .app-shell { padding-left: 0; padding-top: 64px; }
    .sidebar { display: none; }
    .mobile-header { position: fixed; inset: 0 0 auto; z-index: 50; height: 64px; padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; color: white; background: var(--color-primary); }
    .mobile-nav { position: fixed; z-index: 45; top: 64px; left: 0; right: 0; padding: 12px 16px 18px; display: grid; gap: 6px; background: var(--color-primary); box-shadow: var(--shadow); }
    .mobile-nav button { min-height: 46px; padding: 0 12px; border: 0; border-radius: 8px; text-align: left; color: white; background: rgb(255 255 255 / 8%); }
    main { padding: 28px 16px 72px; }
    .page-header { display: grid; }
    .page-actions { justify-content: flex-start; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .toolbar { align-items: stretch; flex-direction: column; }
    .toolbar .search-field { min-width: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .field-full { grid-column: auto; }
    .table-wrap { overflow: visible; }
    table, thead, tbody, tr, td { display: block; width: 100%; }
    thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
    tbody tr { padding: 14px 16px; border-bottom: 1px solid var(--color-border); }
    tbody tr:last-child { border-bottom: 0; }
    td { display: grid; grid-template-columns: minmax(96px, .42fr) 1fr; gap: 10px; padding: 7px 0; border: 0; }
    td::before { content: attr(data-label); color: var(--color-muted-text); font-size: .74rem; font-weight: 750; text-transform: uppercase; }
    .row-actions { justify-content: flex-start; }
    .pagination { justify-content: space-between; flex-wrap: wrap; }
    .dialog-body { padding: 20px 18px; }
    .dialog-header, .dialog-actions { padding-left: 18px; padding-right: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
