/* ══════════════════════════════════════════════════════════════
   IES Connect — hoja de estilos única (sin Bootstrap).

   Antes cada template traía su propio <style>; varias clases
   (.flash, .card, .btn, .field, .status-pill) estaban duplicadas
   con valores distintos. Ahora viven todas acá.

   Breakpoints (mobile-first en lo nuevo, max-width en lo heredado):
     767.98px → cambios de estructura (auth en columna, tabla → cards)
     599.98px → ajustes de padding/tipografía de teléfono
     419.98px → header: los links quedan solo con ícono
   ══════════════════════════════════════════════════════════════ */

/* ── Tokens ── */
:root {
    --brand: #860000;
    --brand-dark: #4a0000;
    --brand-hover: #6a0000;
    --ink: #1f2937;
    --ink-strong: #1a1a2e;
    --label: #374151;
    --muted: #6b7280;          /* 4.8:1 sobre blanco — mínimo para texto */
    --line: #e5e7eb;
    --line-soft: #f3f4f6;
    --canvas: #f8f9fb;
    --paper: #ffffff;
    --field-bg: #f9fafb;
    --ok: #15803d;
    --ok-text: #14532d;
    --ok-bg: #ecfdf3;
    --ok-border: #bbf7d0;
    --warn: #92400e;
    --warn-bg: #fef3c7;
    --warn-border: #fde68a;
    --danger: #b91c1c;
    --danger-text: #7f1d1d;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --focus-ring: 0 0 0 3px rgba(134, 0, 0, 0.2);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.06), 0 4px 6px rgba(0, 0, 0, 0.03);

    /* Texto sobre los fondos bordó (hero, panel izquierdo) */
    --on-brand-muted: rgba(255, 255, 255, 0.8);
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    min-height: 100%;
    font-family: 'Poppins', system-ui, sans-serif;
    background: #f0f4f8;
    color: var(--ink-strong);
}
/* Los controles no heredan la fuente por default (UA stylesheet). */
input, select, textarea, button { font-family: inherit; }
img { max-width: 100%; }

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* ══════════════ Familia auth (login, forgot, reset, authorize) ══════════════ */
.auth-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: stretch;
}
.auth-panel-left {
    flex: 0 0 50%;
    background: linear-gradient(145deg, #4a0000 0%, #680000 40%, #860000 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2.5rem;
    position: relative;
    overflow: hidden;
}
.auth-panel-left::before,
.auth-panel-left::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}
.auth-panel-left::before {
    top: -100px; right: -100px;
    width: 350px; height: 350px;
    border: 2px solid rgba(255, 255, 255, 0.07);
}
.auth-panel-left::after {
    bottom: -120px; left: -120px;
    width: 400px; height: 400px;
    border: 2px solid rgba(255, 255, 255, 0.05);
}
.auth-logo {
    height: 140px; width: auto;
    filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.35));
    position: relative; z-index: 1;
}
.auth-panel-tag {
    position: relative; z-index: 1;
    margin: 1.25rem 0 0; max-width: 22rem;
    font-size: 0.875rem; font-weight: 400; line-height: 1.4;
    color: rgba(255, 255, 255, 0.8); text-align: center;
}
.auth-panel-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    background: var(--paper);
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--ink-strong);
    margin: 0 0 0.375rem;
}
.auth-card-sub {
    font-size: 0.875rem;
    color: var(--muted);
    margin: 0 0 2rem;
}

/* Campos con ícono (auth + perfil) */
.auth-field { margin-bottom: 1.25rem; }
.auth-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--label);
    margin-bottom: 0.5rem;
}
.auth-input-wrap { position: relative; }
.auth-input-icon {
    position: absolute;
    left: 1rem; top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.875rem;
    pointer-events: none;
}
/* 1rem (16px): con menos, iOS hace zoom al enfocar el campo. */
.auth-input {
    width: 100%;
    height: 48px;
    padding: 0 1rem 0 2.75rem;
    border: 1.5px solid var(--line);
    border-radius: 0.75rem;
    font-size: 1rem;
    color: var(--ink-strong);
    background: var(--field-bg);
    transition: border-color 150ms, box-shadow 150ms;
    outline: none;
}
.auth-input:focus {
    border-color: var(--brand);
    background: var(--paper);
    box-shadow: var(--focus-ring);
}
.auth-input[readonly] { color: var(--muted); cursor: not-allowed; }
.auth-input--toggle { padding-right: 3.25rem; }
.auth-pass-toggle {
    position: absolute;
    right: 0.25rem; top: 50%;
    transform: translateY(-50%);
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: var(--muted);
    border-radius: 0.5rem;
}
.auth-pass-toggle:hover { color: var(--ink); }

.auth-btn {
    width: 100%; height: 50px;
    background: var(--brand); border: none; border-radius: 0.75rem;
    color: #fff;
    font-size: 0.9375rem; font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    box-shadow: 0 4px 14px rgba(134, 0, 0, 0.4);
    transition: background 180ms, transform 120ms, box-shadow 180ms;
    margin-bottom: 1.25rem;
}
.auth-btn:hover { background: var(--brand-hover); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(134, 0, 0, 0.5); }
.auth-btn:active { transform: translateY(0); }
.auth-link,
.auth-link-muted {
    display: block;
    text-align: center;
    font-size: 0.8125rem;
    text-decoration: none;
    padding: 0.5rem 0;
}
.auth-link { color: var(--brand); font-weight: 500; }
.auth-link:hover { text-decoration: underline; }
.auth-link-muted { color: var(--muted); }
.auth-link-muted:hover { color: var(--ink); }
.auth-link-muted i { font-size: 0.75rem; }
.auth-hint {
    font-size: 0.75rem;
    color: var(--muted);
    margin: -0.5rem 0 1rem;
}

.auth-alert {
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
}
.auth-alert i { margin-top: 0.125rem; flex-shrink: 0; }
.auth-alert-error   { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text); }
.auth-alert-success { background: #f0fdf4; border: 1px solid var(--ok-border); color: var(--ok-text); }
.auth-alert-warning { background: #fffbeb; border: 1px solid var(--warn-border); color: var(--warn); }

/* forgot_password: pantalla "email enviado" */
.auth-sent { text-align: center; padding: 1rem 0; }
.auth-sent-icon {
    width: 72px; height: 72px;
    background: #f0fdf4;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 2rem;
    color: var(--ok);
}
.auth-sent-text {
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.6;
    margin: 0 0 2rem;
}

/* authorize */
.auth-app-row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    background: #f8fafc;
    border: 1.5px solid var(--line);
    border-radius: 0.875rem;
    padding: 1rem 1.125rem;
    margin-bottom: 1.5rem;
}
.auth-app-icon {
    width: 42px; height: 42px;
    background: var(--brand);
    border-radius: 0.625rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.auth-app-icon i { color: #fff; font-size: 1.125rem; }
.auth-app-name { font-size: 0.9375rem; font-weight: 700; color: var(--ink-strong); margin: 0; overflow-wrap: anywhere; }
.auth-app-desc { font-size: 0.75rem; color: var(--muted); margin: 0.125rem 0 0; }
.auth-scope-label {
    font-size: 0.6875rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--muted); margin: 0 0 0.625rem;
}
.auth-scopes {
    list-style: none; padding: 0; margin: 0 0 1.5rem;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.auth-scopes li {
    display: flex; align-items: center; gap: 0.625rem;
    font-size: 0.875rem; color: var(--label);
}
.auth-scopes li i { color: var(--brand); font-size: 0.8125rem; width: 16px; flex-shrink: 0; }
.auth-user-badge {
    display: flex; align-items: center; gap: 0.625rem;
    background: var(--danger-bg); border: 1px solid var(--danger-border);
    border-radius: 0.75rem; padding: 0.75rem 1rem;
    margin-bottom: 1.5rem; font-size: 0.8125rem; color: var(--danger-text);
    overflow-wrap: anywhere;
}
.auth-user-badge i { flex-shrink: 0; }

@media (max-width: 767.98px) {
    .auth-wrapper { flex-direction: column; }
    /* Banner bajo y formulario pegado a él: sin aire muerto entre ambos. */
    .auth-panel-left { flex: 0 0 auto; padding: 1rem; }
    .auth-logo { height: 56px; }
    .auth-panel-tag { margin-top: 0.5rem; font-size: 0.75rem; }
    .auth-panel-right { flex: 1; align-items: flex-start; padding: 1.25rem 1.25rem 2rem; }
    .auth-card-title { font-size: 1.25rem; margin-bottom: 0.25rem; }
    .auth-card-sub { margin-bottom: 1.25rem; }
    .auth-field { margin-bottom: 1rem; }
    .auth-sent { padding: 0; }
    .auth-sent-icon { width: 56px; height: 56px; font-size: 1.5rem; margin-bottom: 1rem; }
    .auth-sent-text { margin-bottom: 1.25rem; }
}

/* ══════════════ Familia portal (home, perfil, admin, errores) ══════════════ */
.portal-shell {
    /* Tipografía del portal: distinta de la de auth (Poppins). */
    font-family: Tahoma, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--canvas);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Header */
.portal-header {
    background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand) 100%);
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.portal-brand { display: flex; align-items: center; text-decoration: none; flex-shrink: 0; }
.portal-brand-logo {
    height: 36px;
    width: auto;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}
.portal-header-links { display: flex; align-items: center; gap: 0.25rem; }
.portal-header-link {
    display: flex; align-items: center; gap: 0.375rem;
    min-height: 40px;
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background 150ms, color 150ms;
    color: rgba(255, 255, 255, 0.85);
}
.portal-header-link:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.portal-header-link-danger { color: rgba(255, 210, 210, 0.95); }
.portal-header-link-danger:hover { background: rgba(255, 100, 100, 0.15); color: #fecaca; }
/* "Volver" del header: siempre solo ícono; el texto queda sr-only y en title. */
.portal-header-link--volver { min-width: 44px; justify-content: center; }
.portal-header-link--volver .portal-header-link-text {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

/* Footer */
.portal-footer {
    text-align: center;
    padding: 1.25rem;
    font-size: 0.75rem;
    color: var(--muted);
    border-top: 1px solid var(--line);
}

/* Hero bordó (home, perfil, admin) */
.portal-hero {
    background: linear-gradient(135deg, #4a0000 0%, #860000 60%, #a00000 100%);
    padding: 3.5rem 2rem 4rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.portal-hero--compact { padding: 2.25rem 2rem 3rem; }
.portal-hero::before,
.portal-hero::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}
.portal-hero::before {
    top: -80px; right: -80px;
    width: 320px; height: 320px;
    border: 2px solid rgba(255, 255, 255, 0.06);
}
.portal-hero::after {
    bottom: -100px; left: -100px;
    width: 400px; height: 400px;
    border: 2px solid rgba(255, 255, 255, 0.04);
}
.portal-hero > * { position: relative; z-index: 1; }
.portal-hero-avatar {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 3px solid rgba(255, 255, 255, 0.25);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.25rem;
    overflow: hidden;
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.9);
}
.portal-hero-avatar img { width: 100%; height: 100%; object-fit: cover; }
.portal-hero-icon { width: 64px; height: 64px; font-size: 1.5rem; color: #fff; border-color: rgba(255, 255, 255, 0.3); margin-bottom: 1rem; }
.portal-hero-greeting {
    font-size: 1.75rem;
    font-weight: 800;
    color: #fff;
    margin: 0 0 0.5rem;
    overflow-wrap: anywhere;
}
.portal-hero--compact .portal-hero-greeting { font-size: 1.5rem; margin-bottom: 0.375rem; }
.portal-hero-sub {
    font-size: 0.9375rem;
    color: var(--on-brand-muted);
    margin: 0;
}
.portal-hero--compact .portal-hero-sub { font-size: 0.875rem; }

/* Contenedor de página */
.portal-body {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 3rem;
}
.portal-body--wide   { max-width: 1080px; }
.portal-body--medium { max-width: 860px; padding-top: 2rem; }
.portal-body--narrow { max-width: 740px; }
.portal-body--form   { max-width: 640px; padding-top: 2rem; }

/* ── Componentes compartidos ── */
.flash {
    display: flex; align-items: flex-start; gap: 0.6rem;
    padding: 0.8rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    line-height: 1.45;
}
.flash i { margin-top: 0.15rem; flex-shrink: 0; }
.flash-success { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); }
.flash-error   { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text); }

.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    padding: 2rem;
    margin-bottom: 1.5rem;
}
.card-title {
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--muted); margin: 0 0 1.5rem;
    display: flex; align-items: center; gap: 0.5rem;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-2 + .grid-2,
.grid-2 + .field { margin-top: 1.25rem; }

.field label {
    display: block; font-size: 0.8125rem; font-weight: 600;
    color: var(--ink); margin-bottom: 0.5rem;
}
.field input,
.field select {
    width: 100%; min-height: 44px;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--line); border-radius: 0.5rem;
    font-size: 1rem; color: var(--ink); background: var(--paper);
}
.field input:focus,
.field select:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
.field-hint { font-size: 0.75rem; color: var(--muted); margin: 0.35rem 0 0; line-height: 1.45; }
.grid-2 + .field-hint { margin-top: 0.9rem; }
.field-hint--lead { margin: 0 0 1.25rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
    min-height: 44px;
    padding: 0.65rem 1.15rem;
    border-radius: 0.5rem; border: 1px solid transparent;
    font-size: 0.9375rem; font-weight: 600;
    cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline { background: var(--paper); border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-warn { background: var(--paper); border-color: var(--warn); color: var(--warn); }
.btn-warn:hover { background: var(--warn-bg); }
.btn-ok { background: var(--paper); border-color: var(--ok); color: var(--ok); }
.btn-ok:hover { background: var(--ok-bg); }
.btn i.fa-chevron-right { font-size: 0.7rem; }
/* Botón solo ícono (ej. "Volver al listado"): cuadrado, texto sr-only + title. */
.btn-solo-icono { min-width: 44px; padding-left: 0.75rem; padding-right: 0.75rem; }

.card-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin-top: 1.5rem; }
/* Botonera fuera de una card (pie del formulario de la ficha) */
.card-actions--suelta { margin-top: 0; margin-bottom: 1.75rem; }
.card-title + .card-actions { margin-top: 0; }

.status-pill {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.25rem 0.625rem 0.25rem 0.5rem; border-radius: 999px;
    font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-pill.is-active   { background: var(--ok-bg); color: var(--ok); }
.status-pill.is-inactive { background: var(--danger-bg); color: var(--danger); }

/* ── Home ── */
.portal-section { margin-bottom: 2.75rem; }
.portal-section:last-child { margin-bottom: 0; }
.portal-section-title {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 0 0 1.25rem;
}
.portal-apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
    gap: 1.125rem;
}
.app-card {
    background: var(--paper);
    border-radius: 1rem;
    padding: 1.5rem;
    text-decoration: none;
    display: flex;
    align-items: flex-start;
    gap: 1.125rem;
    border: 1.5px solid var(--line);
    transition: border-color 160ms, box-shadow 160ms, transform 140ms;
    position: relative;
    overflow: hidden;
}
.app-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 160ms;
}
.app-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.app-card:hover::before { opacity: 1; }
.app-card-icon {
    width: 48px; height: 48px;
    border-radius: 0.75rem;
    background: var(--accent-bg);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    color: var(--accent);
    flex-shrink: 0;
}
.app-card-body { flex: 1; min-width: 0; }
.app-card-name { font-size: 0.9375rem; font-weight: 700; color: var(--ink-strong); margin: 0 0 0.25rem; }
.app-card-desc { font-size: 0.8125rem; color: var(--muted); line-height: 1.5; margin: 0; }
.app-card-arrow {
    color: #d1d5db;
    font-size: 0.8125rem;
    align-self: center;
    transition: color 160ms, transform 160ms;
    flex-shrink: 0;
}
.app-card:hover .app-card-arrow { color: var(--accent); transform: translateX(3px); }
.app-card-red   { --accent: #860000; --accent-bg: #fef2f2; }
.app-card-blue  { --accent: #2563eb; --accent-bg: #eff6ff; }
.app-card-green { --accent: #16a34a; --accent-bg: #f0fdf4; }

/* ── Perfil ── */
.profile-hero-avatar {
    width: 88px; height: 88px;
    margin-bottom: 1.125rem;
    border-color: rgba(255, 255, 255, 0.3);
    font-size: 2.25rem;
    padding: 0;
    position: relative;
    cursor: pointer;
    transition: border-color 160ms;
}
.profile-hero-avatar:hover,
.profile-hero-avatar:focus-visible { border-color: rgba(255, 255, 255, 0.7); outline: none; }
.profile-avatar-overlay {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 180ms;
    font-size: 1.25rem; color: #fff;
}
.profile-hero-avatar:hover .profile-avatar-overlay,
.profile-hero-avatar:focus-visible .profile-avatar-overlay { opacity: 1; }
.profile-avatar-hint {
    font-size: 0.75rem;
    color: var(--on-brand-muted);
    display: block;
    margin-bottom: 1rem;
}
.profile-hero-dni { font-size: 0.875rem; color: var(--on-brand-muted); margin: 0; }

.profile-card {
    background: var(--paper);
    border-radius: 1rem;
    border: 1.5px solid var(--line);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.profile-section { padding: 2rem 2.25rem; }
.profile-section + .profile-section { border-top: 1px solid var(--line-soft); }
.profile-section-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.375rem; }
.profile-section-desc {
    font-size: 0.8125rem;
    color: var(--muted);
    margin: 0 0 1.75rem;
    padding-left: 3rem;
}
.profile-section-icon {
    width: 36px; height: 36px;
    border-radius: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9375rem; flex-shrink: 0;
}
.profile-section-icon-red  { background: var(--danger-bg); color: var(--brand); }
.profile-section-icon-dark { background: var(--line-soft); color: var(--label); }
.profile-section-title { font-size: 1rem; font-weight: 700; color: var(--ink-strong); margin: 0; }
.profile-card .auth-input { height: 50px; padding-left: 2.875rem; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.profile-submit {
    min-height: 50px;
    border: none; border-radius: 0.75rem;
    font-size: 0.9375rem; font-weight: 700;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0 2rem;
    transition: background 160ms, transform 120ms, box-shadow 160ms;
    margin-top: 0.5rem;
}
.profile-submit-red { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(134, 0, 0, 0.35); }
.profile-submit-red:hover { background: var(--brand-hover); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(134, 0, 0, 0.45); }
.profile-submit-dark { background: var(--ink-strong); color: #fff; box-shadow: 0 4px 14px rgba(26, 26, 46, 0.25); }
.profile-submit-dark:hover { background: #111827; transform: translateY(-1px); }
.profile-submit:active { transform: translateY(0); }

/* ── Admin: listado de usuarios ── */
.admin-toolbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.75rem; flex-wrap: wrap; }
.admin-search { display: flex; gap: 0.5rem; flex: 1 1 260px; }
.admin-search-campo { position: relative; flex: 1 1 auto; min-width: 0; }
.admin-search-rol {
    flex: 0 0 auto; height: 46px; padding: 0 0.75rem;
    border: 1.5px solid var(--line); border-radius: 0.5rem;
    font-size: 0.9375rem; color: var(--ink); background: var(--paper);
}
.admin-search-rol:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
.admin-search-icon {
    position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 0.8125rem; pointer-events: none;
}
.admin-search input {
    width: 100%; height: 46px; padding: 0 2.75rem 0 2.5rem;
    border: 1.5px solid var(--line); border-radius: 0.5rem;
    font-size: 1rem; color: var(--ink);
    background: var(--paper);
    transition: border-color 140ms, box-shadow 140ms;
}
.admin-search input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
.admin-search-clear {
    position: absolute; right: 0.25rem; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 0.875rem; text-decoration: none;
    width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
}
.admin-search-clear:hover { background: var(--canvas); color: var(--ink); }
.admin-toolbar-count { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.admin-toolbar-count strong { color: var(--ink); font-weight: 700; }

.admin-table-wrap {
    background: var(--paper); border-radius: 1rem; border: 1.5px solid var(--line);
    overflow-x: auto; box-shadow: var(--shadow-xs);
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.admin-table th {
    text-align: left; padding: 1rem 1.25rem; background: var(--canvas);
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--label);
    font-weight: 600; border-bottom: 2px solid var(--line);
}
.admin-table th.col-acciones { text-align: right; }
.admin-table td { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr { transition: background 100ms; }
.admin-table tbody tr:hover td { background: rgba(134, 0, 0, 0.025); }
.admin-table td.col-acciones { text-align: right; }

.user-identity { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.user-avatar {
    flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
    background: var(--danger-bg); color: var(--brand);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
}
.user-name { font-weight: 600; color: var(--ink); line-height: 1.3; overflow-wrap: anywhere; }
.user-dni { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.badge-role {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 0.375rem;
    background: #eff6ff; color: #1d4ed8; font-size: 0.75rem; font-weight: 700; margin: 0 0.25rem 0.25rem 0;
}
.status-note { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.admin-empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.admin-empty i { font-size: 1.5rem; color: #d1d5db; margin-bottom: 0.75rem; display: block; }
.admin-empty p { margin: 0; font-size: 0.875rem; }

.pagination-bar {
    display: flex; justify-content: center; align-items: center; flex-wrap: wrap;
    gap: 0.375rem; margin-top: 1.5rem;
}
.pagination-bar a,
.pagination-bar span {
    min-width: 40px; height: 40px; padding: 0 0.5rem; border-radius: 0.5rem; font-size: 0.875rem;
    text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-variant-numeric: tabular-nums;
    transition: border-color 120ms, background 120ms;
}
.pagination-bar a:hover { border-color: var(--brand); color: var(--brand); }
.pagination-bar span.current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.pagination-bar span.ellipsis { border: none; background: none; color: var(--muted); min-width: 1.5rem; }
.pagination-bar a.nav-arrow { color: var(--muted); }
.pagination-bar a.disabled { pointer-events: none; opacity: 0.35; }

/* Tabla → tarjetas en teléfono: cada fila es una card con
   nombre arriba, roles abajo y estado + botón en la última línea. */
@media (max-width: 767.98px) {
    .admin-table-wrap { background: none; border: none; box-shadow: none; overflow: visible; border-radius: 0; }
    .admin-table thead {
        position: absolute; width: 1px; height: 1px;
        overflow: hidden; clip: rect(0, 0, 0, 0);
    }
    .admin-table,
    .admin-table tbody { display: block; }
    .admin-table tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.75rem 1rem;
        align-items: center;
        background: var(--paper);
        border: 1.5px solid var(--line);
        border-radius: 0.75rem;
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    .admin-table td,
    .admin-table tbody tr:hover td { padding: 0; border: none; background: none; }
    .admin-table td.col-usuario,
    .admin-table td.col-roles,
    .admin-table td.col-vacio { grid-column: 1 / -1; }
    .admin-table td.col-roles:empty { display: none; }
    .admin-table td.col-roles { margin-top: -0.25rem; }
}

/* ── Admin: ficha y alta ── */
.ficha-top { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.ficha-avatar {
    width: 56px; height: 56px; flex-shrink: 0;
    border-radius: 50%; background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    color: #fff; font-weight: 700; font-size: 1.125rem;
    display: flex; align-items: center; justify-content: center;
}
.ficha-head { flex: 1 1 200px; min-width: 0; }
.ficha-title { font-size: 1.375rem; font-weight: 700; color: var(--ink); margin: 0; overflow-wrap: anywhere; }
.ficha-title--solo { margin-bottom: 1.5rem; }
.ficha-sub { font-size: 0.875rem; color: var(--muted); margin: 0.25rem 0 0; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.roles { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.role-chip {
    display: inline-flex; align-items: center; gap: 0.45rem;
    min-height: 44px;
    padding: 0.5rem 0.85rem; border: 1px solid var(--line);
    border-radius: 2rem; font-size: 0.875rem; cursor: pointer; background: var(--paper);
}
.role-chip:hover { border-color: var(--brand); }
.role-chip input { accent-color: var(--brand); margin: 0; width: 18px; height: 18px; }

.admin-lock {
    display: flex; align-items: flex-start; gap: 0.5rem;
    margin-top: 0.9rem; padding: 0.7rem 0.85rem;
    background: var(--warn-bg); color: var(--warn);
    border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.45;
}
.admin-lock i { margin-top: 0.15rem; }
.admin-lock code { background: rgba(0, 0, 0, 0.06); padding: 0.05rem 0.3rem; border-radius: 0.375rem; overflow-wrap: anywhere; }

/* Permisos: acción a la izquierda, 3 opciones a la derecha; en teléfono
   la acción va arriba y las opciones debajo, en fila que puede cortar. */
.permiso-area { margin-bottom: 1.25rem; }
.permiso-area:last-child { margin-bottom: 0; }
.permiso-area-titulo { font-weight: 600; font-size: 0.875rem; color: var(--ink); margin-bottom: 0.5rem; }
.permiso-fila {
    display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem 1rem;
    padding: 0.4rem 0; font-size: 0.8125rem;
    border-bottom: 1px solid var(--line-soft);
}
.permiso-fila:last-child { border-bottom: none; }
.permiso-accion { flex: 0 0 140px; color: var(--muted); }
.permiso-opciones { display: flex; flex-wrap: wrap; gap: 0 1rem; }
.permiso-opcion { display: flex; align-items: center; gap: 0.35rem; min-height: 36px; cursor: pointer; }
.permiso-opcion input { accent-color: var(--brand); width: 18px; height: 18px; margin: 0; }
.permiso-opcion--si { color: var(--ok); }
.permiso-opcion--no { color: var(--danger); }

/* ── Páginas de error ── */
.error-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1rem;
}
.error-code {
    font-size: calc(1.475rem + 2.7vw);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.25rem;
}
.error-code--primary   { color: var(--brand); }
.error-code--warning   { color: #b45309; }
.error-code--danger    { color: var(--danger); }
.error-code--secondary { color: var(--muted); }
.error-title { font-size: 1.5rem; font-weight: 600; margin: 0 0 0.5rem; }
.error-text { color: var(--muted); max-width: 560px; margin: 0 0 1.5rem; }
.error-text--tight { margin-bottom: 0.5rem; }
.error-user { color: var(--muted); font-size: 0.875em; margin: 0 0 1.5rem; }
.error-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.error-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 150ms, color 150ms, border-color 150ms;
}
.error-btn--primary { background: var(--brand); border: 1px solid var(--brand); color: #fff; }
.error-btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.error-btn--outline { background: transparent; border: 1px solid var(--muted); color: var(--muted); }
.error-btn--outline:hover { background: var(--muted); color: #fff; }

@media (min-width: 1200px) {
    .error-code { font-size: 3.5rem; }
}

/* ── Monitores chicos de escritorio (19": 1366×768, 1440×900, 1280×1024) ──
   Misma regla que ies-gestion: base 15px y menos aire en header, hero,
   cuerpo y panel de login, para que todo entre sin scroll innecesario. */
@media (min-width: 768px) and (max-width: 1439.98px),
       (min-width: 768px) and (max-height: 820px) {
    html { font-size: 15px; }

    .portal-header { height: 52px; padding: 0 1.25rem; }
    .portal-brand-logo { height: 30px; }

    .portal-hero { padding: 1.75rem 2rem 2rem; }
    .portal-hero--compact { padding: 1.25rem 2rem 1.5rem; }
    .portal-hero-avatar { width: 56px; height: 56px; font-size: 1.5rem; margin-bottom: 0.75rem; }
    .portal-hero-icon { width: 48px; height: 48px; font-size: 1.25rem; margin-bottom: 0.625rem; }
    .portal-hero-greeting { font-size: 1.375rem; margin-bottom: 0.25rem; }
    .portal-hero--compact .portal-hero-greeting { font-size: 1.25rem; }
    .portal-hero-sub,
    .portal-hero--compact .portal-hero-sub { font-size: 0.875rem; }

    .portal-body { padding: 1.5rem 1.25rem 2rem; }
    .portal-body--medium,
    .portal-body--form { padding-top: 1.25rem; }
    .portal-section { margin-bottom: 1.75rem; }
    .portal-section-title { margin-bottom: 0.875rem; }
    .card { padding: 1.5rem; margin-bottom: 1rem; }
    .portal-footer { padding: 0.875rem; }

    .auth-panel-left { padding: 2rem 1.75rem; }
    .auth-logo { height: 100px; }
    .auth-panel-right { padding: 2rem 1.5rem; }
}

/* ── Teléfono ── */
@media (max-width: 599.98px) {
    .portal-header { padding: 0 1rem; }
    .portal-hero { padding: 2.5rem 1.25rem 3rem; }
    .portal-hero--compact { padding: 2rem 1.25rem 2.5rem; }
    .portal-hero-greeting { font-size: 1.375rem; }
    .portal-hero--compact .portal-hero-greeting { font-size: 1.25rem; }
    .portal-body { padding: 1.5rem 1rem 2.5rem; }

    .card { padding: 1.25rem; }
    .grid-2,
    .field-row { grid-template-columns: 1fr; }
    .grid-2 { gap: 1rem; }
    .field-row { gap: 0; }
    .card-actions .btn,
    .card-actions form,
    .card-actions form .btn { width: 100%; }

    .profile-section { padding: 1.5rem 1.25rem; }
    .profile-section-desc { padding-left: 0; margin-bottom: 1.25rem; }
    .profile-submit { width: 100%; padding: 0 1rem; }

    .admin-toolbar { gap: 0.75rem; }
    .admin-search { flex-basis: 100%; }
    .admin-search { flex-wrap: wrap; }
    .admin-search-rol { flex: 1 1 100%; }
    .admin-toolbar .btn { flex: 1; }

    .ficha-avatar { width: 48px; height: 48px; font-size: 1rem; }
    .ficha-title { font-size: 1.2rem; }
    .ficha-top .btn { width: 100%; }
    .ficha-top .btn-solo-icono { width: auto; }

    .permiso-fila { padding: 0.6rem 0; }
    .permiso-accion { flex-basis: 100%; color: var(--ink); font-weight: 500; }

    .error-actions { flex-direction: column; width: 100%; max-width: 320px; }
    .error-btn { width: 100%; }
}

/* Header muy angosto (≤ 419px): los links quedan solo con ícono;
   el texto pasa a sr-only para que el lector de pantalla lo siga leyendo. */
@media (max-width: 419.98px) {
    .portal-brand-logo { height: 30px; }
    .portal-header-link { min-width: 44px; min-height: 44px; justify-content: center; padding: 0.375rem 0.6rem; }
    .portal-header-link-text {
        position: absolute; width: 1px; height: 1px;
        overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
    }
    .portal-header-link i { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
    .app-card:hover, .auth-btn:hover, .profile-submit:hover { transform: none; }
}
