:root {
    --primary: #F9B32D;
    --primary-dark: #E5A020;
    --secondary: #585f66;
    --background: #f3f5f8;
    --surface: #ffffff;
    --text: #1a1a2e;
    --muted: #6c757d;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --border: #e5e9f0;
    --shadow: 0 8px 24px rgba(26, 26, 46, 0.08);
    --radius: 14px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
    text-decoration: none;
}

.portal-shell {
    min-height: 100vh;
}

.portal-sidebar-desktop {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #2f3439 0%, var(--secondary) 100%);
    color: #fff;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    flex-direction: column;
    overflow-y: auto;
}

.portal-offcanvas {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #2f3439 0%, var(--secondary) 100%);
    color: #fff;
}

.portal-offcanvas .offcanvas-header,
.portal-offcanvas .offcanvas-body {
    background: transparent;
    color: #fff;
}

.portal-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.portal-brand-offcanvas {
    flex: 1;
    min-width: 0;
}

.portal-brand img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    flex-shrink: 0;
}

.portal-brand-text {
    min-width: 0;
}

.portal-brand h1,
.portal-brand h2 {
    font-size: 0.95rem;
    margin: 0;
    font-weight: 700;
    line-height: 1.2;
}

.portal-brand p,
.portal-brand small {
    display: block;
    margin: 0.15rem 0 0;
    font-size: 0.72rem;
    opacity: 0.75;
    line-height: 1.2;
}

.portal-nav {
    list-style: none;
    margin: 0;
    padding: 1rem 0;
}

.portal-nav li a,
.portal-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.5rem;
    color: rgba(255, 255, 255, 0.88);
    border-left: 3px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.portal-nav li a:hover,
.portal-nav li a.active,
.portal-nav-link:hover,
.portal-nav-link.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-left-color: var(--primary);
}

.portal-nav-section {
    padding: 0.85rem 1.5rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
    list-style: none;
}

.portal-main {
    flex: 1;
    min-width: 0;
    margin-left: 0;
}

.portal-topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 2px 12px rgba(26, 26, 46, 0.04);
}

.portal-topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.portal-menu-toggle {
    border: 0;
    background: transparent;
    font-size: 1.25rem;
    color: var(--text);
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
}

.portal-menu-toggle:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.portal-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.portal-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.portal-moodle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 40px;
    min-width: 40px;
    padding: 0 0.85rem;
    border-radius: 999px;
    background: rgba(249, 179, 45, 0.12);
    color: var(--primary);
    border: 1px solid rgba(249, 179, 45, 0.35);
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.portal-moodle-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.portal-moodle-btn i {
    font-size: 1rem;
}

.portal-account-status {
    min-width: 0;
}

.portal-account-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    max-width: 100%;
    touch-action: manipulation;
}

.portal-account-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.portal-account-detail {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.account-status-ok {
    background: rgba(25, 135, 84, 0.12);
    color: var(--success);
}

.account-status-pending {
    background: rgba(255, 193, 7, 0.18);
    color: #856404;
}

.account-status-debt {
    background: rgba(220, 53, 69, 0.12);
    color: var(--danger);
}

.portal-profile-dropdown {
    position: relative;
}

.portal-avatar-btn {
    border: 0;
    cursor: pointer;
    padding: 0;
}

.portal-avatar-btn.dropdown-toggle::after {
    display: none;
}

.portal-profile-menu {
    width: min(320px, calc(100vw - 2rem));
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.portal-profile-header {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    padding: 1rem 1rem 0.85rem;
    background: var(--background);
    border-bottom: 1px solid var(--border);
}

.portal-profile-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.portal-profile-body {
    padding: 1rem;
}

.portal-profile-footer {
    padding: 0 1rem 1rem;
}

.qr-output-wrap {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-output-wrap canvas,
.qr-output-wrap img {
    max-width: 100%;
    height: auto;
}

.tool-preview-wrap img {
    max-width: 100%;
    max-height: 420px;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.portal-user-meta {
    display: none;
}

.portal-content {
    padding: 1.25rem;
    position: relative;
    z-index: 1;
}

.constancias-table-wrap {
    position: relative;
    overflow: visible;
}

.page-header {
    margin-bottom: 1.25rem;
}

.page-header h2 {
    margin: 0 0 0.35rem;
    font-size: 1.6rem;
    font-weight: 700;
}

.page-header p {
    margin: 0;
    color: var(--muted);
}

.portal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
    height: 100%;
}

.portal-card h3,
.portal-card h4,
.portal-card h5 {
    margin-top: 0;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card .label {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.stat-card .value {
    font-size: 1.35rem;
    font-weight: 700;
}

.stat-card .hint {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.quick-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    color: var(--text);
}

.quick-link i {
    color: var(--primary);
}

.doc-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    width: 100%;
    max-width: 280px;
}

.table-portal .col-actions {
    width: 220px;
    min-width: 220px;
}

.doc-actions-mobile {
    max-width: none;
    margin-top: 0.75rem;
}

.doc-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 0.65rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    border-radius: 10px;
    white-space: nowrap;
    text-decoration: none;
    box-sizing: border-box;
    position: relative;
    z-index: 5;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(249, 179, 45, 0.2);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.doc-action-btn i {
    font-size: 0.875rem;
}

.doc-action-view {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
}

.doc-action-view:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.doc-action-download {
    background: #fff;
    color: var(--secondary);
    border: 1px solid var(--border);
}

.doc-action-download:hover {
    background: var(--background);
    color: var(--text);
    border-color: #cfd6df;
}

.resource-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}

.resource-link {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    min-height: 100%;
}

.resource-link:hover {
    border-color: rgba(249, 179, 45, 0.35);
    color: var(--text);
    box-shadow: var(--shadow);
}

.resource-link i {
    color: var(--primary);
    margin-top: 0.15rem;
}

.resource-link span {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
}

.authority-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

.authority-card {
    padding: 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.authority-card strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 0.35rem;
}

.authority-card span {
    color: var(--muted);
    font-size: 0.82rem;
}

.directivos-table-wrap {
    overflow-x: auto;
}

.table-portal {
    width: 100%;
    border-collapse: collapse;
}

.table-portal th,
.table-portal td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.table-portal th {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    background: #fafbfd;
}

.table-responsive-wrap {
    overflow-x: auto;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-approved {
    background: rgba(25, 135, 84, 0.12);
    color: var(--success);
}

.status-failed {
    background: rgba(220, 53, 69, 0.12);
    color: var(--danger);
}

.status-pending {
    background: rgba(255, 193, 7, 0.18);
    color: #856404;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}

.empty-state i {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.portal-footer {
    padding: 1rem 1.25rem 1.5rem;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}

.alert-portal {
    border-radius: 12px;
    border: 0;
    margin-bottom: 1rem;
}

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filters-bar .form-control,
.filters-bar .btn {
    min-height: 42px;
}

.mobile-card-list {
    display: none;
}

.mobile-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    position: relative;
    isolation: isolate;
}

.mobile-card-item .doc-actions {
    position: relative;
    z-index: 6;
    pointer-events: auto;
}

.mobile-card-item dt {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

.mobile-card-item dd {
    margin: 0;
    font-weight: 600;
}

/* Auth layout — estilo Moodle lambda2 */
.pagelayout-login {
    background-color: #c8d4e0;
    background-image: url('../../img/fondo_facet_dia.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.auth-page-moodle {
    min-height: 100vh;
}

.auth-page-moodle .auth-page-inner,
.auth-page-moodle .auth-region-main {
    min-height: 100vh;
}

.auth-page-moodle .login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.auth-page-moodle .login-container {
    width: 100%;
    max-width: 500px;
    background-color: #fff;
    padding: 3rem;
    box-shadow: 0 0.5rem 1rem rgb(0 0 0 / 0.15);
    border-radius: 0.25rem;
    margin-bottom: 2rem;
}

.auth-page-moodle .login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.auth-page-moodle .login-logo-img {
    max-width: 100%;
    height: auto;
    max-height: 88px;
    object-fit: contain;
}

.auth-page-moodle .login-form .form-control-lg {
    min-height: calc(1.5em + 1rem + 2px);
    padding: 0.5rem 1rem;
    font-size: 1.125rem;
    border-color: #ced4da;
    border-radius: 0.25rem;
}

.auth-page-moodle .login-form .form-control-lg:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.25rem rgb(249 179 45 / 0.25);
}

.auth-page-moodle .login-form-submit .btn-primary-portal {
    font-weight: 600;
    min-height: calc(1.5em + 1rem + 2px);
    font-size: 1.125rem;
}

.auth-page-moodle .login-divider {
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    border-top: 1px solid #dee2e6;
}

.auth-page-moodle .login-portal-note {
    color: #6c757d;
    font-size: 0.9375rem;
}

.auth-page-moodle .login-page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
    color: var(--text);
}

.auth-page-moodle .login-page-subtitle {
    color: #6c757d;
    font-size: 0.9375rem;
    margin: 0 0 1.25rem;
}

.auth-page-moodle .login-status-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
}

.auth-page-moodle .login-status-icon-error {
    background: rgba(220, 53, 69, 0.12);
    color: var(--danger);
}

.auth-page-moodle .alert-portal {
    margin-bottom: 1rem;
}

@media (max-width: 575px) {
    .auth-page-moodle .login-container {
        padding: 2rem 1.25rem;
    }
}

/* Legacy auth helpers kept for compatibility */
.auth-page {
    min-height: 100vh;
}

.auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: var(--background);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    border: 1px solid var(--border);
}

.btn-primary-portal {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
    min-height: 44px;
}

.btn-primary-portal:hover,
.btn-primary-portal:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-primary-portal:disabled {
    opacity: 0.7;
}

.password-toggle {
    cursor: pointer;
}

.loading-overlay {
    display: none !important;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.75);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    pointer-events: none !important;
    visibility: hidden;
}

.loading-overlay.show {
    display: flex !important;
    pointer-events: auto !important;
    visibility: visible;
}

.loading-overlay .spinner-border {
    color: var(--primary);
}

@media (min-width: 992px) {
    .portal-main {
        margin-left: var(--sidebar-width);
    }

    .portal-user-meta {
        display: block;
        text-align: right;
    }

    .portal-user-meta .name {
        font-weight: 600;
        font-size: 0.95rem;
    }

    .portal-user-meta .career {
        font-size: 0.8rem;
        color: var(--muted);
    }
}

@media (max-width: 991px) {
    .table-desktop {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    .mobile-card-list {
        display: block !important;
        position: relative;
        z-index: 2;
    }

    .doc-action-btn,
    .btn-primary-portal,
    .btn-outline-secondary,
    .btn-primary,
    .portal-menu-toggle,
    .portal-moodle-btn,
    .portal-avatar-btn {
        min-height: 48px;
        pointer-events: auto;
    }
}

@media (max-width: 767px) {
    .portal-content {
        padding: 1rem;
    }

    .portal-moodle-label {
        display: none;
    }

    .portal-moodle-btn {
        width: 44px;
        height: 44px;
        padding: 0;
        border-radius: 50%;
    }

    .portal-account-label {
        max-width: 140px;
    }

    .portal-account-detail {
        max-width: 180px;
    }

    .portal-avatar,
    .portal-avatar-btn {
        width: 44px;
        height: 44px;
    }

    .portal-menu-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .btn-primary-portal,
    .btn-outline-secondary,
    .filters-bar .btn {
        min-height: 44px;
        touch-action: manipulation;
    }
}

@media (min-width: 992px) {
    .mobile-card-list {
        display: none !important;
    }
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.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;
}
