@import url('../vendor_assets/css/fonts.css');
:root {
    --bg-body: #f4f7fb;
    --bg-card: #ffffff;
    --bg-surface: #f8fafc;
    --bg-surface-strong: #eef4ff;
    --text-main: #1a202c;
    --text-muted: #718096;
    --text-light: #a0aec0;
    --primary: #4f46e5; /* Indigo/Blue */
    --primary-light: #e0e7ff;
    --secondary: #0ea5e9; /* Light Blue */
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-red: #ef4444;
    --accent-cyan: #06b6d4;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 15px rgba(0,0,0,0.03);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.08);
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --table-surface: rgba(255, 255, 255, 0.98);
    --table-head-bg: #ffffff;
    --table-row-hover: #f8fbff;
    --table-row-stripe: #fbfcff;
    --table-divider: rgba(226, 232, 240, 0.92);
    --table-header-text: #0f172a;
    --table-muted-text: #7c8da5;

    /* Global fallback variables to align legacy and new styles */
    --primary-color: var(--primary);
    --accent-color: var(--primary);
    --bg-color: var(--bg-body);
    --text-color: var(--text-main);
    --top-navbar-height: 60px;
    --mobile-header-height: 82px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    display: flex;
    min-height: 100vh;
    padding: 0;
    margin: 0;
}

body:not(.auth-ready) .dashboard-wrapper {
    opacity: 0;
}

body.auth-ready .dashboard-wrapper {
    opacity: 1;
    transition: opacity 0.12s ease-in;
}

body.ui-theme-skydash {
    --bg-body: #f3f5fb;
    --bg-card: #ffffff;
    --bg-surface: #f8faff;
    --bg-surface-strong: #eef2ff;
    --text-main: #1f2937;
    --text-muted: #7b8798;
    --text-light: #9aa7ba;
    --primary: #4b49ac;
    --primary-light: rgba(75, 73, 172, 0.12);
    --secondary: #98bdff;
    --border-color: #edf1f7;
    --shadow-sm: 0 4px 18px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 18px 42px rgba(15, 23, 42, 0.1);
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 26px;
    --table-surface: #ffffff;
    --table-head-bg: #ffffff;
    --table-row-hover: #f5f7ff;
    --table-row-stripe: #fbfcff;
    --table-divider: #edf1f7;
    --table-header-text: #111827;
    --table-muted-text: #7b8798;
    background:
        radial-gradient(circle at top left, rgba(152, 189, 255, 0.16), transparent 28%),
        linear-gradient(180deg, #f5f7ff 0%, #f1f4fb 100%);
}

body.ui-theme-skydash .dashboard-grid {
    gap: 24px;
    padding-top: calc(var(--top-navbar-height) + 22px);
}

body.ui-theme-skydash .sidebar {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,255,0.98));
    color: var(--text-main);
    box-shadow: 12px 0 32px rgba(15, 23, 42, 0.06);
    border-right: 1px solid rgba(226, 232, 240, 0.75);
    border-left: 0;
}

body.ui-theme-skydash .brand {
    justify-content: flex-start;
    padding: 0 20px;
}

body.ui-theme-skydash .brand-icon {
    background: linear-gradient(135deg, rgba(75, 73, 172, 0.14), rgba(152, 189, 255, 0.3));
    border-radius: 14px;
    box-shadow: none;
}

body.ui-theme-skydash .nav-item {
    color: #6b7280;
    border-left: 0;
    border-radius: 14px;
    margin: 0 12px;
    padding: 12px 16px;
}

body.ui-theme-skydash .nav-item:hover {
    background: rgba(75, 73, 172, 0.08);
    color: var(--primary);
}

body.ui-theme-skydash .nav-item.active {
    background: linear-gradient(90deg, rgba(75, 73, 172, 0.14), rgba(152, 189, 255, 0.18));
    color: var(--primary);
    border-left: 0;
    box-shadow: inset 3px 0 0 var(--primary);
}

body.ui-theme-skydash .sidebar .nav-menu li[data-section] {
    color: #9aa7ba !important;
    letter-spacing: 0.08em;
    padding-left: 28px !important;
}

body.ui-theme-skydash .top-navbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
    color: var(--text-main);
}

body.ui-theme-skydash .top-navbar-left h1,
body.ui-theme-skydash .top-navbar-right,
body.ui-theme-skydash .sidebar-toggle-btn,
body.ui-theme-skydash .user-greeting,
body.ui-theme-skydash .notification-bell {
    color: var(--text-main);
}

body.ui-theme-skydash .notification-bell:hover {
    background: rgba(75, 73, 172, 0.08);
}

body.ui-theme-skydash .notification-bell .badge {
    background: var(--primary);
    border-color: #ffffff;
}

body.ui-theme-skydash .mobile-header {
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-main);
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

body.ui-theme-skydash .mobile-header-title,
body.ui-theme-skydash .mobile-header .sidebar-toggle-btn {
    color: var(--text-main);
}

body.ui-theme-skydash .card,
body.ui-theme-skydash .app-card,
body.ui-theme-skydash .table-shell,
body.ui-theme-skydash .config-panel,
body.ui-theme-skydash .filters-panel,
body.ui-theme-skydash .academic-toolbar,
body.ui-theme-skydash .filter-bar,
body.ui-theme-skydash .app-card-toolbar,
body.ui-theme-skydash .preview-toolbar,
body.ui-theme-skydash .action-toolbar {
    border-color: rgba(226, 232, 240, 0.72);
    box-shadow: var(--shadow-md);
}

body.ui-theme-skydash .card,
body.ui-theme-skydash .app-card,
body.ui-theme-skydash .table-shell,
body.ui-theme-skydash .config-panel {
    border-radius: 24px;
}

body.ui-theme-skydash .app-card-toolbar,
body.ui-theme-skydash .filters-panel,
body.ui-theme-skydash .academic-toolbar,
body.ui-theme-skydash .filter-bar,
body.ui-theme-skydash .action-toolbar,
body.ui-theme-skydash .preview-toolbar {
    background: linear-gradient(180deg, #ffffff, #f9fbff);
}

body.ui-theme-skydash .page-title,
body.ui-theme-skydash .section-title,
body.ui-theme-skydash .hero-text {
    color: #111827;
}

body.ui-theme-skydash .btn,
body.ui-theme-skydash button.btn,
body.ui-theme-skydash a.btn {
    border-radius: 12px;
    font-weight: 700;
    box-shadow: none;
}

body.ui-theme-skydash .btn-primary {
    background: linear-gradient(135deg, #4b49ac, #7978e9);
    border-color: transparent;
}

body.ui-theme-skydash .btn-outline,
body.ui-theme-skydash .btn-ghost {
    background: #ffffff;
    border-color: #dbe4f0;
    color: #4b5563;
}

body.ui-theme-skydash .form-control,
body.ui-theme-skydash .form-select,
body.ui-theme-skydash select.form-control,
body.ui-theme-skydash input.form-control,
body.ui-theme-skydash textarea.form-control {
    border-radius: 14px;
    border-color: #e2e8f0;
    background: #ffffff;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.02);
}

body.ui-theme-skydash .form-control:focus {
    border-color: #4b49ac;
    box-shadow: 0 0 0 4px rgba(75, 73, 172, 0.12);
}

body.ui-theme-skydash .table-container,
body.ui-theme-skydash .app-table-wrap,
body.ui-theme-skydash .students-table-wrap,
body.ui-theme-skydash .admin-table-wrap {
    background: transparent;
}

body.ui-theme-skydash :is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) {
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

body.ui-theme-skydash :is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) thead th {
    font-size: 0.9rem;
    color: #111827;
}

body.ui-theme-skydash :is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody td {
    color: #4b5563;
}

body.ui-theme-skydash .badge,
body.ui-theme-skydash .status-badge,
body.ui-theme-skydash .type-badge,
body.ui-theme-skydash .status-pill,
body.ui-theme-skydash .access-badge {
    border-radius: 999px;
    font-weight: 700;
}

body.ui-theme-skydash .modal,
body.ui-theme-skydash .modal-content {
    border-radius: 24px;
    border: 1px solid rgba(226, 232, 240, 0.72);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

body.ui-theme-skydash .modal-header {
    background: linear-gradient(180deg, #ffffff, #f8fbff);
}

body.ui-theme-skydash .preview-shell {
    border-radius: 24px;
}

.mgp-pdf-viewer {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.76);
    z-index: 12000;
    padding: 18px;
    align-items: center;
    justify-content: center;
}

.mgp-pdf-viewer.show {
    display: flex;
}

.mgp-pdf-viewer__dialog {
    width: min(1280px, 100%);
    height: min(92vh, 920px);
    background: #fff;
    border-radius: 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.35);
}

.mgp-pdf-viewer__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.mgp-pdf-viewer__title {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.mgp-pdf-viewer__title strong {
    font-size: 1rem;
    color: #0f172a;
}

.mgp-pdf-viewer__title span {
    color: #64748b;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mgp-pdf-viewer__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.mgp-pdf-viewer__body {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #334155;
}

.mgp-pdf-viewer__frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #525659;
}

.mgp-pdf-viewer__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    color: #fff;
    background:
        radial-gradient(circle at top, rgba(255,255,255,0.08), transparent 30%),
        rgba(15, 23, 42, 0.24);
    text-align: center;
    padding: 24px;
    transition: opacity 0.2s ease;
}

.mgp-pdf-viewer__overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.mgp-pdf-viewer__spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    animation: mgp-pdf-spin 0.8s linear infinite;
}

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

.mgp-pdf-viewer__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 14px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    font-size: 0.83rem;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .mgp-pdf-viewer {
        padding: 10px;
    }

    .mgp-pdf-viewer__dialog {
        height: 90vh;
        border-radius: 18px;
    }

    .mgp-pdf-viewer__header,
    .mgp-pdf-viewer__footer {
        padding-left: 14px;
        padding-right: 14px;
    }

    .mgp-pdf-viewer__actions {
        width: 100%;
        justify-content: stretch;
    }

    .mgp-pdf-viewer__actions .btn {
        flex: 1;
    }
}

/* Mobile tables: convert data tables into readable cards.
   Tables used for print/boletas can opt out with .no-mobile-cards. */
@media (max-width: 768px) {
    .dashboard-wrapper .table-container,
    .dashboard-wrapper .table-wrap,
    .dashboard-wrapper [class*="table-wrap"],
    .dashboard-wrapper [class*="table-container"] {
        max-width: 100%;
    }

    table.mgp-mobile-card-table,
    table.mgp-mobile-card-table thead,
    table.mgp-mobile-card-table tbody,
    table.mgp-mobile-card-table tr,
    table.mgp-mobile-card-table th,
    table.mgp-mobile-card-table td {
        display: block;
        width: 100% !important;
    }

    table.mgp-mobile-card-table {
        border-collapse: separate !important;
        border-spacing: 0 !important;
        min-width: 0 !important;
    }

    table.mgp-mobile-card-table thead {
        display: none !important;
    }

    table.mgp-mobile-card-table tbody {
        display: grid;
        gap: 12px;
    }

    table.mgp-mobile-card-table tr {
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: 16px;
        padding: 12px;
        margin: 0 !important;
        box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
    }

    table.mgp-mobile-card-table td,
    table.mgp-mobile-card-table th {
        border: 0 !important;
        border-bottom: 1px solid #eef2f7 !important;
        padding: 10px 0 !important;
        text-align: left !important;
        background: transparent !important;
        white-space: normal !important;
        min-width: 0 !important;
    }

    table.mgp-mobile-card-table td:last-child,
    table.mgp-mobile-card-table th:last-child {
        border-bottom: 0 !important;
    }

    table.mgp-mobile-card-table td::before,
    table.mgp-mobile-card-table th::before {
        content: attr(data-mobile-label);
        display: block;
        color: #64748b;
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        margin-bottom: 5px;
    }

    table.mgp-mobile-card-table td[data-mobile-label=""]::before,
    table.mgp-mobile-card-table th[data-mobile-label=""]::before {
        display: none;
    }

    table.mgp-mobile-card-table td:first-child,
    table.mgp-mobile-card-table th:first-child {
        color: #94a3b8;
        font-size: 0.78rem;
        font-weight: 800;
    }

    table.mgp-mobile-card-table input:not([type="checkbox"]):not([type="radio"]),
    table.mgp-mobile-card-table select,
    table.mgp-mobile-card-table textarea {
        max-width: 100%;
    }

    table.mgp-mobile-card-table .btn,
    table.mgp-mobile-card-table button,
    table.mgp-mobile-card-table a.btn {
        white-space: normal;
        margin: 3px 0;
    }

    .dashboard-wrapper .table-container,
    .dashboard-wrapper .table-wrap,
    .app-container .table-container,
    .app-container .table-wrap,
    .dashboard-wrapper [class*="table-wrap"],
    .dashboard-wrapper [class*="table-container"] {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    .mgp-horizontal-scroll-hint {
        position: relative;
    }

    .mgp-horizontal-scroll-hint::after {
        content: '← desliza →';
        position: sticky;
        left: 50%;
        bottom: 6px;
        transform: translateX(-50%);
        display: block;
        width: max-content;
        margin: 8px auto 0;
        padding: 5px 10px;
        border-radius: 999px;
        background: rgba(15, 23, 42, 0.78);
        color: white;
        font-size: 0.72rem;
        font-weight: 700;
        pointer-events: none;
    }
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 600;
    color: var(--text-main);
}
.text-muted { color: var(--text-muted); }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(226, 232, 240, 0.9);
}

.page-header {
    grid-column: span 12;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 4px;
}

.page-header-title {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.page-title {
    font-size: clamp(1.45rem, 2vw, 1.9rem);
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.section-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}

.section-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.app-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: var(--shadow-lg);
}

.app-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.app-card-header.stack {
    flex-direction: column;
    align-items: flex-start;
}

.app-card-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.app-card-soft {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
}

.app-card-hero {
    background: linear-gradient(135deg, rgba(79,70,229,0.12), rgba(14,165,233,0.10), rgba(16,185,129,0.10));
    border-color: rgba(79, 70, 229, 0.16);
}

.app-card-table {
    padding: 0;
}

.app-card-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.app-card-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
}

.hero-inline {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.hero-icon {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--primary);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    font-size: 1.2rem;
    flex: 0 0 auto;
}

.eyebrow {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 800;
    color: var(--text-muted);
}

.hero-text {
    font-size: 1.05rem;
    line-height: 1.55;
    color: var(--text-main);
    font-weight: 600;
}

.stat-grid {
    grid-column: span 12;
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 8px;
}

.app-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.list-block {
    margin-top: 4px;
}

.app-table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.table-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.app-alert {
    border-radius: 16px;
    padding: 14px 16px;
    border: 1px solid transparent;
}

.app-alert-info {
    color: #1e3a8a;
    background: rgba(59, 130, 246, 0.08);
    border-color: rgba(59, 130, 246, 0.18);
}

.app-alert-success {
    color: #065f46;
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.18);
}

.app-alert-warning {
    color: #92400e;
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
}

.app-alert-danger {
    color: #991b1b;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

/* Sidebar (Desktop Default) */
.sidebar {
    width: 280px;
    height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    background: var(--color-sidebar);
    color: #ffffff;
    z-index: 999;
    box-shadow: 2px 0 15px rgba(0,0,0,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 20px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 30px;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: 0;
    padding: 0;
    opacity: 0;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 14px;
    min-height: 48px;
}
.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 10px;
    overflow: hidden;
    white-space: nowrap;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-weight: 500;
    border-radius: 0;
    transition: all 0.2s;
    font-size: 0.95rem;
    border-left: 3px solid transparent;
    overflow: hidden;
    white-space: nowrap;
}

body.sidebar-mini .sidebar {
    width: 70px;
}
body.sidebar-mini .brand h2,
body.sidebar-mini .nav-item span {
    display: none;
    opacity: 0;
}
body.sidebar-mini .sidebar .nav-menu li[data-section] {
    display: none;
}
body.sidebar-mini .nav-item {
    padding: 12px 26px;
}
body.sidebar-mini .brand {
    justify-content: center;
    padding: 10px 0;
}
body.sidebar-mini .brand-icon {
    width: 34px;
    height: 34px;
}
body.sidebar-mini .dashboard-grid {
    width: calc(100% - 70px);
}
body.sidebar-mini .top-navbar {
    left: 70px;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #ffffff;
}

.nav-item.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border-left: 3px solid #ffffff;
}

.nav-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Main Dashboard Grid */
.dashboard-grid {
    flex-grow: 1;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(min-content, max-content);
    gap: 20px;
    padding: calc(var(--top-navbar-height) + 15px) 15px 15px 15px;
    width: calc(100% - 280px);
    margin-left: auto;
    min-height: 100vh;
    align-content: start;
}

.top-navbar {
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    height: var(--top-navbar-height);
    background: var(--color-navbar);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 998;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.top-navbar-left { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 0; }
.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex; /* Now visible on desktop */
    align-items: center;
    justify-content: center;
    padding: 5px;
}
.sidebar-toggle-btn svg { width: 24px; height: 24px; }
.top-navbar-left h1 { font-size: 1.2rem; margin: 0; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-navbar-right { display: flex; align-items: center; gap: 20px; }
.notification-bell {
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    transition: background 0.2s;
}
.notification-bell:hover { background: rgba(255,255,255,0.1); }
.notification-bell .badge {
    position: absolute;
    top: 0px;
    right: 0px;
    background: #000; color: #fff;
    font-size: 0.65rem;
    padding: 2px 5px;
    border-radius: 10px;
    font-weight: bold;
    border: 2px solid var(--color-primary); /* matches the red header */
}
.user-profile { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.user-avatar { width: 35px; height: 35px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2); }
.user-greeting { font-size: 0.9rem; }

/* Utility Classes for Grid Spanning */
.col-span-12 { grid-column: span 12; }
.col-span-8 { grid-column: span 8; }
.col-span-6 { grid-column: span 6; }
.col-span-4 { grid-column: span 4; }
.col-span-3 { grid-column: span 3; }

/* Specific Card Layouts */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}


/* Editor Visual (Reemplazando el gráfico grande central) */
.editor-workspace {
    background-color: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-md);
    flex-grow: 1;
    min-height: 300px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}


.btn {
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.06);
}
.btn:active {
    transform: scale(0.97);
}
.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    border-color: rgba(79, 70, 229, 0.15);
}
.btn-primary:hover {
    filter: brightness(0.92);
}

.btn-secondary {
    background: #ffffff;
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: #f8fafc;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.btn-outline:hover {
    background-color: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

.cert-mockup {
    width: 80%;
    height: 80%;
    background: white;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    position: relative;
}

.drag-element {
    position: absolute;
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px dashed var(--primary);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: grab;
    user-select: none;
}
.drag-element:active {
    cursor: grabbing;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 15px;
}
.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}
.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0;
    background: var(--table-surface);
    border-radius: 24px;
    overflow: hidden;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) th,
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) td {
    padding: 18px 20px;
    text-align: left;
    border-bottom: 1px solid var(--table-divider);
    vertical-align: middle;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) thead th {
    background: var(--table-head-bg);
    font-weight: 800;
    font-size: 0.98rem;
    color: var(--table-header-text);
    text-transform: none;
    letter-spacing: -0.01em;
    white-space: nowrap;
    padding-top: 22px;
    padding-bottom: 22px;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody td {
    color: var(--text-main);
    font-weight: 500;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr:last-child td {
    border-bottom: none;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr {
    transition: transform 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr:nth-child(even) td {
    background: var(--table-row-stripe);
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr:hover td {
    background-color: var(--table-row-hover);
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) thead th:first-child {
    border-top-left-radius: 24px;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) thead th:last-child {
    border-top-right-radius: 24px;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr:last-child td:first-child {
    border-bottom-left-radius: 24px;
}
:is(.table, .students-table, .admin-table, .history-table, .finance-students-table, .teacher-table, #tramites-table, #history-table, #citas-table) tbody tr:last-child td:last-child {
    border-bottom-right-radius: 24px;
}

.preview-shell {
    padding: 0;
    background: #e5e7eb;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-toolbar {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-body);
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.preview-toolbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.preview-surface {
    height: calc(100vh - 250px);
    min-height: 500px;
}

.config-toggle-header {
    padding: 15px 25px;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
}

.config-toggle-header:hover {
    background-color: #f1f5f9;
}

.config-summary {
    font-size: 0.85rem;
    color: #64748b;
}

.config-panel-body {
    padding: 25px;
    display: block;
}

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.option-panel {
    background-color: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.option-checks {
    display: flex;
    gap: 30px;
    border-top: 1px solid #e2e8f0;
    padding-top: 15px;
    flex-wrap: wrap;
}

.check-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #475569;
}

.check-inline input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #004b93;
}

.config-grid.three-columns {
    grid-template-columns: repeat(3, 1fr);
}

.config-grid .span-2 {
    grid-column: span 2;
}

.filter-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
    background: #fff;
    padding: 12px 18px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.action-cluster {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.action-cluster.loose {
    gap: 12px;
}

.action-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    flex-wrap: wrap;
}

.admin-table-wrap,
.students-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.students-table,
.admin-table {
    width: 100%;
    min-width: 880px;
    font-size: 0.9rem;
    background: var(--table-surface);
}

.students-table thead th,
.admin-table thead th {
    border-bottom: 1px solid var(--table-divider);
}

.students-table td,
.admin-table td {
    vertical-align: middle;
}

.students-table tbody tr,
.admin-table tbody tr {
    transition: transform 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.students-table tbody tr:hover,
.admin-table tbody tr:hover {
    background-color: transparent;
}

.students-table tbody tr:nth-child(even),
.admin-table tbody tr:nth-child(even) {
    background-color: transparent;
}

.students-table tbody tr:nth-child(even):hover,
.admin-table tbody tr:nth-child(even):hover {
    background-color: transparent;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 350px;
}

.search-wrap input {
    width: 100%;
    padding-right: 28px;
}

.side-form-card {
    height: fit-content;
}

.config-panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 22px;
}

.config-title {
    margin: 0 0 16px;
    font-size: 1.08rem;
    color: var(--text-main);
    font-weight: 700;
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.weekly-agenda-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.weekly-phrase-list {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stats-row {
    grid-column: span 12;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 10px;
}

.stat-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-icon {
    font-size: 1.5rem;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 600;
}

.docente-nav-shell {
    grid-column: span 12;
    margin-bottom: 16px;
}

.academic-toolbar,
.filters-panel {
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 18px;
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.table-shell {
    background: #fff;
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 20px;
}

.section-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-strip {
    display: flex;
    gap: 4px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
}

.tab-strip button,
.panel-tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-strip button.active,
.panel-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.module-shell {
    grid-column: span 12;
}

.content-tabs,
.tabs {
    display: flex;
    align-items: center;
    gap: 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    overflow-x: auto;
}

.content-tabs .tab,
.tabs .tab {
    padding: 12px 16px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.content-tabs .tab.active,
.tabs .tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.module-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 20px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #94a3b8;
}

.empty-state.muted {
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 14px;
    color: #64748b;
}

.loading-block {
    text-align: center;
    padding: 32px;
    color: #64748b;
}

.soft-panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px;
}

.soft-panel.warning {
    background: #fffbeb;
    border-color: #fde68a;
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.mini-table th {
    padding: 8px 10px;
    text-align: left;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    color: #475569;
}

.mini-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
}
.filter-search {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 240px;
}

.filter-search input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 0.95rem;
    background: transparent;
    padding: 4px;
    color: var(--text-main);
}

.filter-separator {
    border-left: 1px solid #e2e8f0;
    padding-left: 15px;
}

.editor-stage {
    background: #e5e7eb;
    padding: 20px;
}

.token-panel {
    padding: 15px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 12px;
}

.token-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.85rem;
    color: #15803d;
}

.token-list code {
    background: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #bbf7d0;
}

.empty-preview {
    padding: 40px;
    color: #64748b;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Badge */
.badge {
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active { background-color: #d1fae5; color: #065f46; }

/* Responsive Design & Sidebar Toggle */
.mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    min-height: var(--mobile-header-height);
    padding: 14px 20px;
    box-shadow: var(--shadow-sm);
    z-index: 100;
    position: sticky;
    top: 0;
    width: 100%;
}

.mobile-header-title {
    font-weight: 700;
    color: #1e2f55;
    font-size: 1.12rem;
    line-height: 1.18;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
    max-width: calc(100% - 108px);
}

.mobile-header-logo {
    width: 38px;
    height: 38px;
    object-fit: contain;
    flex: 0 0 auto;
}

.mobile-header-name {
    display: block;
    overflow-wrap: anywhere;
}

.mobile-header .notification-bell {
    flex: 0 0 44px;
    color: #1e2f55;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 998;
    backdrop-filter: blur(2px);
}
body.sidebar-open .sidebar-overlay {
    display: block;
}

.dashboard-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0; /* fixes grid overflow */
    min-height: 100vh;
}

body {
    padding: 0;
    gap: 0;
    display: flex;
}

.dashboard-grid {
    padding: calc(var(--top-navbar-height) + 15px) 15px 15px 15px;
    gap: 15px;
    width: 100%;
}

@media (max-width: 992px) {
    .page-header,
    .app-card-header,
    .preview-toolbar,
    .option-row {
        flex-direction: column;
        align-items: stretch;
    }
    .config-grid {
        grid-template-columns: 1fr;
    }
    .config-grid.three-columns {
        grid-template-columns: 1fr;
    }
    .config-grid .span-2 {
        grid-column: span 1;
    }
    .option-checks {
        gap: 14px;
    }
    .filter-separator {
        border-left: 0;
        padding-left: 0;
        width: 100%;
    }
    .search-wrap {
        max-width: none;
    }
    .students-table,
    .admin-table {
        min-width: 700px;
        font-size: 0.82rem;
    }
    .students-table th,
    .students-table td,
    .admin-table th,
    .admin-table td {
        padding: 8px 10px;
    }
    .weekly-agenda-grid {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        left: -320px;
        top: 0;
        height: 100vh;
        z-index: 9999;
        transition: left 0.3s ease;
    }
    body.sidebar-open .sidebar {
        left: 0;
    }
    .top-navbar {
        display: none !important;
    }
    .sidebar-overlay {
        display: none;
        z-index: 9998;
    }
    body.sidebar-open .sidebar-overlay {
        display: block !important;
    }
    .dashboard-grid {
        padding: 15px !important;
        margin-left: 0 !important;
        width: 100% !important;
        gap: 15px;
        min-height: calc(100dvh - var(--mobile-header-height));
    }

    /* Grid collapses to 1 column */
    .col-span-12, .col-span-8, .col-span-6, .col-span-4, .col-span-3 {
        grid-column: span 12;
    }

    /* Editor adjustments */
    .editor-workspace {
        overflow-x: auto;
        justify-content: flex-start;
        align-items: flex-start;
        padding: 10px;
    }
    .cert-mockup {
        width: 880px !important;
        min-width: 880px !important;
        transform: scale(0.6);
        transform-origin: top left;
        margin-right: -350px;
    }
}

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: min(84vw, 300px) !important;
        max-width: 300px;
        height: 100vh;
        z-index: 9999;
        transform: translateX(-105%);
        transition: transform 0.3s ease;
        margin: 0 !important;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .sidebar-overlay {
        display: none;
        z-index: 9998;
    }
    body.sidebar-open .sidebar-overlay {
        display: block !important;
    }
    .top-navbar {
        display: none !important;
    }
    .mobile-header {
        display: flex !important;
    }
    .dashboard-grid {
        padding: 15px !important;
        margin-left: 0 !important;
        width: 100% !important;
        min-height: calc(100dvh - var(--mobile-header-height));
    }
}

@media (min-width: 993px) {
    .mobile-header {
        display: none !important;
    }
}

/* === ANIMATIONS & UTILITIES === */
@keyframes slideIn {
    from {
        transform: translateY(-20px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

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

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

/* Global loading spinner class */
.spinner-loader {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.fade-in-up {
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* === SCROLL-SAFE MODALS === */
.modal-overlay {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

.modal-overlay[style*="display: flex"],
.modal-overlay.active {
    align-items: flex-start !important;
}

.modal-overlay > .modal,
.modal-overlay > .modal-content,
.modal-overlay > .modal-box,
.modal-overlay > div {
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

[id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal),
[id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 16px !important;
    align-items: flex-start !important;
}

[id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
[id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
[id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
[id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > div,
[id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
[id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
[id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
[id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > div {
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-overlay .modal-body {
    min-height: 0;
}

@supports not (height: 100dvh) {
    .modal-overlay > .modal,
    .modal-overlay > .modal-content,
    .modal-overlay > .modal-box,
    .modal-overlay > div,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > div,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > div {
        max-height: calc(100vh - 32px);
    }
}

@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }

    .modal-overlay > .modal,
    .modal-overlay > .modal-content,
    .modal-overlay > .modal-box,
    .modal-overlay > div,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
    [id*="modal"][style*="position: fixed"]:not(#pdf-modal):not(#preview-modal) > div,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-content,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > .modal-box,
    [id*="modal"][style*="position:fixed"]:not(#pdf-modal):not(#preview-modal) > div {
        width: min(100%, 640px) !important;
        max-height: calc(100dvh - 20px);
    }
}

/* === CENTRALIZED PREMIUM MODALS === */
.modal-overlay-new {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
}

.modal-overlay-new.active {
    opacity: 1;
    visibility: visible;
}

.modal-box-new {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 600px;
    max-height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay-new.active .modal-box-new {
    transform: scale(1) translateY(0);
}

.modal-header-new {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header-new h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.modal-close-new {
    background: var(--bg-body);
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close-new:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.modal-body-new {
    padding: 24px;
    overflow-y: auto;
    flex-grow: 1;
}

.modal-footer-new {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: #fafbfc;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.uagro-container {
    background: #23385e;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 25px;
    color: white;
}
.uagro-header {
    padding: 20px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
}
.uagro-header-content {
    display: flex;
    align-items: center;
    gap: 20px;
}
.uagro-header img.student-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.2);
}
.uagro-header div.student-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    background: rgba(255,255,255,0.1);
}
.uagro-header h3 { margin: 0 0 5px 0; font-size: 1.4rem; font-weight: 600; color: white; }
.uagro-header p { margin: 0; color: rgba(255,255,255,0.8); font-size: 0.95rem; }

.btn-visualizar {
    background: white;
    color: #23385e;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.2s;
}
.btn-visualizar:hover {
    background: #f1f5f9;
}

.uagro-body {
    padding: 30px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}
.uagro-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}
.uagro-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    padding: 25px;
    border-top: 4px solid var(--card-theme, #4f46e5);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
.uagro-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}
.uagro-card-icon {
    font-size: 3rem;
    color: var(--card-theme, #4f46e5);
    margin-bottom: 15px;
}
.uagro-card-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: #1e293b;
    margin-bottom: 10px;
    text-align: center;
}
.uagro-card-desc {
    font-size: 0.85rem;
    color: #64748b;
    text-align: center;
    margin-bottom: 20px;
    flex-grow: 1;
}
.uagro-card-btn {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}
.uagro-card-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}
.uagro-card-btn[disabled] { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; border-color: #f1f5f9; }

.help-btn { display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:50%;border:2px solid var(--primary);color:var(--primary);font-weight:700;font-size:1rem;cursor:pointer;background:transparent;transition:0.2s;margin-left:10px;vertical-align:middle; }
.help-btn:hover { background:var(--primary);color:white; }
