/* Adaptación de los lienzos HTML al viewport real. Tokens y componentes originales intactos. */
:root {
    --bs-primary: #1f6f9b;
    --bs-body-bg: var(--fondo);
    --bs-body-color: var(--texto);
    --bs-border-color: var(--borde);
    --bs-border-radius: 10px;
    --bs-border-radius-lg: 12px;
    --bs-font-sans-serif: var(--font-sans);
}
html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--fondo);
}
[hidden] {
    display: none !important;
}
.sg button,
.sg input,
.sg select,
.sg textarea {
    font-family: var(--font-sans);
}
.sg h1,
.sg h2,
.sg h3,
.sg p {
    margin: 0;
}
.sg a.sg-btn,
.sg a.sg-side-a,
.sg a.sg-link {
    text-decoration: none;
}
.sg a.sg-btn-primary {
    color: var(--texto-sobre-oscuro);
}
.sg a.sg-side-a {
    color: #e6ebf2;
}
.sg a.sg-side-a[aria-current] {
    color: #fff;
}
.sg-err:empty {
    display: none;
}
.sg i.fa-solid {
    flex: none;
}
.sg-search > i {
    position: absolute;
    left: 14px;
    top: 16px;
    color: var(--texto-secundario);
}
.sg-side-a > i {
    width: 18px;
    font-size: 16px;
    color: var(--texto-sobre-oscuro-2);
}
.sg-check input {
    width: 22px;
    height: 22px;
    accent-color: var(--azul-oscuro);
    flex: none;
}
.sg-label > .sg-input,
.sg-label > .sg-select {
    margin-top: 6px;
}
fieldset {
    border: 0;
    padding: 0;
    margin: 0;
}
legend {
    float: none;
    width: auto;
}
dialog::backdrop {
    background: var(--velo);
}
.auth-shell {
    min-height: 100dvh;
    display: flex;
}
.auth-brand {
    width: 640px;
    display: flex;
    flex-direction: column;
    padding: 56px 64px;
    min-height: 100dvh;
}
.auth-brand .sg-auth-logo {
    height: 64px;
    max-width: 100%;
    width: auto;
    align-self: flex-start;
    object-fit: contain;
}
.auth-brand-text {
    position: relative;
    margin-top: auto;
    max-width: 420px;
}
.auth-university {
    font-size: 12px;
    line-height: 16px;
    color: #d6e6f1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.auth-brand-text h2 {
    font-size: 36px;
    line-height: 42px;
    font-weight: 700;
    margin-top: 12px;
    letter-spacing: -0.01em;
}
.auth-description {
    margin-top: 12px !important;
    color: #d6e6f1;
    font-size: 16px;
    line-height: 24px;
}
.auth-brand-foot {
    position: relative;
    margin-top: 48px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #d6e6f1;
}
.auth-brand-foot img {
    background: #fff;
    border-radius: 50%;
    padding: 2px;
}
.auth-right {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--superficie);
}
.auth-content {
    width: 440px;
    max-width: 100%;
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 64px 0;
}
.auth-title {
    font-size: 28px;
    line-height: 34px;
}
.auth-recovery {
    display: flex;
    justify-content: flex-end;
    margin-top: -8px;
}
.auth-footer {
    justify-content: center;
    padding: 20px;
}
.auth-footer img {
    display: none;
}
.sg-auth-band .geo {
    height: 100%;
    width: 100%;
}
.app-shell {
    min-height: 100dvh;
}
.app-sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
}
.app-sidebar .sg-side-nav {
    overflow: auto;
}
.app-nav-group > .app-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    margin: 0;
    padding: 0 10px;
    border-radius: var(--radius-md);
    list-style: none;
    cursor: pointer;
}
.app-nav-toggle::-webkit-details-marker {
    display: none;
}
.app-nav-toggle:hover {
    background: var(--gris-institucional-2);
}
.app-nav-group.is-current > .app-nav-toggle {
    color: #fff;
    background: var(--gris-institucional-2);
    font-weight: 700;
}
.app-nav-group[open] > .app-nav-toggle .fa-chevron-down {
    transform: rotate(180deg);
}
.app-sidebar .who {
    overflow-wrap: anywhere;
}
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
}
.app-page {
    overflow: visible;
}
.mobile-only {
    display: none;
}
.future-menu {
    font-size: 13px;
    color: var(--texto-sobre-oscuro-2);
    padding: 0 10px;
}
.future-menu summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.future-menu ul {
    padding-left: 22px;
    line-height: 26px;
}
.skip-link {
    position: fixed;
    top: -100px;
    left: 16px;
    z-index: 100;
    background: white;
    padding: 12px;
}
.skip-link:focus {
    top: 8px;
}
.dashboard-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 20px;
    align-items: start;
}
.catalog-filters {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--borde);
    flex-wrap: wrap;
}
.catalog-filters .sg-search {
    flex: 1;
    min-width: 160px;
}
.catalog-filters > .sg-select {
    width: auto;
    max-width: 100%;
}
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--borde);
    flex-wrap: wrap;
}
.pagination-bar nav {
    display: flex;
    gap: 8px;
}
.table-actions {
    white-space: nowrap;
}
.empty-state {
    text-align: center;
    padding: 48px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: var(--texto-secundario);
}
.empty-state > i {
    font-size: 28px;
    color: var(--azul-oscuro);
}
.sg-table td {
    overflow-wrap: anywhere;
}
.sg-table {
    table-layout: auto;
}
.app-dialog {
    border: 0;
    padding: 0;
    background: var(--superficie);
    border-radius: var(--radius-lg);
    box-shadow: var(--sombra-panel);
    width: min(520px, calc(100vw - 32px));
    max-height: 90dvh;
    overflow: auto;
    color: var(--texto);
}
.app-dialog > .sg-sheet-h {
    padding: 16px;
    border-bottom: 1px solid var(--borde);
}
.dialog-body {
    padding: 20px 24px;
    overflow: auto;
    min-height: 0;
}
.editor-dialog {
    position: fixed;
    inset: 0 0 0 auto;
    margin: 0;
    height: 100dvh;
    max-height: 100dvh;
    width: 420px;
    max-width: 100vw;
    border-radius: 0;
}
.wide-editor {
    width: 560px;
}
.editor-form {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.editor-form > .sg-sheet-h {
    flex: none;
    padding: 16px 20px;
    border-bottom: 1px solid var(--borde);
    min-height: 64px;
}
.editor-form > .dialog-body {
    flex: 1;
}
.editor-footer {
    padding: 12px 24px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--borde);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex: none;
}
.app-toast {
    position: fixed;
    left: auto;
    right: 16px;
    bottom: 16px;
    max-width: calc(100vw - 32px);
    z-index: 100;
}
.plain-page {
    max-width: 640px;
    padding: 24px;
    margin: 10vh auto;
}
.sg-pagehead {
    flex-wrap: wrap;
}
.assignment-areas {
    max-height: 250px;
    overflow: auto;
}
.sg-topbar .sg-ctx-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
}
.sg-kpi-top {
    gap: 8px;
}
.form-message {
    overflow-wrap: anywhere;
}
@media (min-width: 768px) and (max-width: 1199px) {
    .auth-shell {
        display: block;
    }
    .auth-brand {
        width: 100%;
        min-height: 200px;
        height: 200px;
        padding: 24px;
    }
    .auth-brand .sg-auth-logo {
        height: 40px;
    }
    .auth-brand-text {
        margin-top: 12px;
    }
    .auth-brand-text h2 {
        font-size: 22px;
        line-height: 28px;
        margin: 0;
    }
    .auth-university,
    .auth-description,
    .auth-brand-foot {
        display: none;
    }
    .auth-right {
        max-width: 520px;
        margin: -32px auto 24px;
        position: relative;
        border-radius: 12px;
        box-shadow: var(--sombra-1);
    }
    .auth-content {
        width: 100%;
        padding: 32px;
    }
    .auth-footer img {
        display: block;
    }
}
@media (max-width: 1199px) {
    .mobile-only {
        display: inline-flex;
    }
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        z-index: 30;
        width: min(var(--menu-lateral), 86vw);
        visibility: hidden;
    }
    .menu-open .app-sidebar {
        transform: translateX(0);
        visibility: visible;
    }
    .mobile-scrim {
        position: fixed;
        inset: 0;
        background: var(--velo);
        z-index: 29;
    }
    .app-page {
        padding: 24px;
    }
    .app-topbar {
        padding: 0 16px;
    }
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
    }
    .app-sidebar .sg-side-brand img {
        max-width: 180px;
        height: auto;
    }
    .menu-open {
        overflow: hidden;
    }
}
@media (max-width: 767px) {
    .auth-shell {
        display: block;
    }
    .auth-brand {
        width: 100%;
        min-height: 124px;
        height: auto;
        padding: 14px 20px 18px;
        padding-top: calc(14px + env(safe-area-inset-top));
    }
    .auth-brand .sg-auth-logo {
        height: 40px;
    }
    .auth-brand-text {
        margin-top: 12px;
        display: flex;
        flex-direction: column;
        max-width: none;
    }
    .auth-brand-text h2 {
        order: -1;
        font-size: 15px;
        line-height: 20px;
        margin: 0;
        letter-spacing: 0;
    }
    .auth-university {
        font-size: 13px;
        line-height: 18px;
        text-transform: none;
        letter-spacing: 0;
    }
    .auth-description,
    .auth-brand-foot {
        display: none;
    }
    .auth-content {
        width: 100%;
        margin: 0;
        padding: 20px 16px;
        gap: 16px;
    }
    .auth-title {
        font-size: 22px;
        line-height: 28px;
    }
    .auth-right {
        min-height: calc(100dvh - 124px);
    }
    .auth-footer {
        margin-top: auto;
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .auth-footer img {
        display: block;
    }
    .keyboard-open .auth-brand {
        min-height: 64px;
        padding: 12px 20px;
    }
    .keyboard-open .auth-brand-text {
        display: none;
    }
    .app-page {
        padding: 20px 16px;
        gap: 16px;
    }
    .app-topbar {
        height: calc(var(--barra-superior) + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 4px 0;
        gap: 4px;
    }
    .desktop-cycle {
        display: none;
    }
    .personal-link span {
        display: none;
    }
    .personal-link {
        padding: 0 12px;
    }
    .app-topbar .sg-ctx-chip {
        min-width: 0;
    }
    .dashboard-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .responsive-table,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table td {
        display: block;
        width: 100%;
    }
    .responsive-table thead {
        display: none;
    }
    .responsive-table tr {
        padding: 12px 16px;
        border-bottom: 1px solid var(--borde);
    }
    .responsive-table td {
        padding: 4px 0;
        border: 0;
        display: flex;
        justify-content: space-between;
        gap: 12px;
        align-items: center;
    }
    .responsive-table td:before {
        content: attr(data-label);
        font-size: 13px;
        color: var(--texto-secundario);
        flex: none;
    }
    .responsive-table td:first-child {
        font-size: 15px;
    }
    .responsive-table .table-actions {
        justify-content: flex-end;
    }
    .responsive-table td[colspan] {
        display: block;
    }
    .responsive-table td[colspan]:before {
        display: none;
    }
    .catalog-filters {
        gap: 8px;
    }
    .catalog-filters .sg-search {
        flex-basis: 100%;
    }
    .catalog-filters > .sg-select {
        flex: 1;
        width: calc(50% - 8px);
        min-width: 0;
    }
    .editor-dialog {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
    }
    .dialog-body {
        padding: 16px;
    }
    .editor-footer {
        padding-left: 16px;
        padding-right: 16px;
    }
    .app-dialog:not(.editor-dialog) {
        width: 100vw;
        max-width: 100vw;
        position: fixed;
        inset: auto 0 0;
        margin: 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 88dvh;
    }
    .t-display {
        font-size: 22px;
        line-height: 28px;
    }
    .sg-quick {
        grid-template-columns: 1fr 1fr;
    }
    .sg-btn {
        white-space: normal;
    }
    .sg-pagehead .sg-btn {
        padding: 8px 14px;
    }
    .sg-seg.compact button {
        white-space: normal;
    }
    .editor-form > .sg-sheet-h {
        padding-top: calc(16px + env(safe-area-inset-top));
    }
}
@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
@media (max-width: 359px) {
    .auth-content .sg-seg.compact button {
        min-width: 0;
        flex: 1 1 auto;
    }
    .auth-content #tab-alumno {
        flex-direction: column;
        gap: 0;
    }
}

.swal2-popup {
    font-family: var(--font-sans);
    border-radius: var(--radius-lg);
    color: var(--texto);
}
.swal2-actions {
    gap: var(--space-2);
}

/* ---------------------------------------------------------------------------------------------
   Grupos y horarios (etapa 2). Solo composición y adaptación; colores y medidas de los tokens.
   --------------------------------------------------------------------------------------------- */
.page-subtitle {
    margin-top: 4px !important;
    color: var(--texto-secundario-fondo);
    font-size: 14px;
    line-height: 20px;
}
.pagehead-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}
.crumb-link {
    min-height: 32px;
}
.grupos-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grupo-clave {
    font-weight: 700;
    color: var(--azul-oscuro);
    text-decoration: none;
}
.grupo-clave:hover {
    text-decoration: underline;
}
.grupos-meter {
    min-width: 170px;
}
.grupo-avance {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.grupo-tabs {
    background: none;
    padding: 0;
}
.assign-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.assign-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.texto-error,
.accion-destructiva .sg-item-t {
    color: var(--error-texto);
}

/* Cuadrícula semanal */
.semana-card {
    overflow-x: auto;
}
.semana-fila {
    display: contents;
}
button.sg-ev {
    display: block;
    text-align: left;
    font: inherit;
    font-size: 12px;
    line-height: 16px;
    cursor: pointer;
    color: var(--texto);
}
button.sg-ev:focus-visible {
    outline: 2px solid var(--foco);
    outline-offset: 2px;
    z-index: 3;
}
.sg-ev.ajeno {
    cursor: default;
}
.sg-ev .flag-warn {
    color: var(--advertencia-texto);
}
.semana-leyenda {
    color: var(--texto-secundario-fondo);
}
.key-completa {
    background: var(--azul-tenue);
    border: 1px solid #bfddee;
}
.key-pendiente {
    border: 1px dashed var(--borde-control);
}
.key-ajeno {
    background: #f2f4f7;
    border: 1px solid #d5dae1;
}
.horario-fecha-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.horario-fecha {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Agenda por día (celular) */
.agenda-dias {
    display: none;
    flex-direction: column;
    gap: 12px;
}
.agenda-vacia {
    padding: 12px 16px;
    color: var(--texto-secundario);
    font-size: 14px;
}
.agenda-clase {
    border-bottom: 1px solid var(--borde);
}
.agenda-clase:last-child {
    border-bottom: 0;
}
.agenda-clase .sg-badge {
    margin-top: 6px;
}
.agenda-editar {
    margin-top: 4px;
    padding-left: 0;
}

/* Profesores */
.profesores-h {
    flex-wrap: wrap;
}
.profesores-vacio {
    padding: 12px 16px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 14px;
}
.ocupante {
    flex-wrap: wrap;
}
.ocupante .sg-badge {
    margin-top: 4px;
}
.ocupante-acciones {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* Paneles de edición */
.asistente-pasos {
    padding: 12px 20px 0;
    flex: none;
}
.asistente-contador {
    padding: 6px 20px 0;
    flex: none;
}
.dias-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.sg-slot-chip {
    cursor: pointer;
}
.horas-campos,
.vigencia-campos {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.vigencia-detalle summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--azul-oscuro);
    font-weight: 600;
    font-size: 14px;
}
.vigencia-detalle[open] summary {
    margin-bottom: 8px;
}
.tipo-opcion,
.profesor-opcion {
    cursor: pointer;
}
.tipo-opcion input,
.profesor-opcion input {
    width: 20px;
    height: 20px;
    accent-color: var(--azul-oscuro);
    flex: none;
    margin: 0;
}
.sg-opt:has(input:checked) {
    border-color: var(--azul-oscuro);
    background: var(--azul-tenue);
    box-shadow: inset 0 0 0 1px var(--azul-oscuro);
}
.sg-pick:has(input:checked) {
    border-color: var(--azul-oscuro);
    box-shadow: inset 0 0 0 1px var(--azul-oscuro);
    background: var(--azul-tenue);
}
.sg-pick .sg-item-t,
.sg-pick .sg-item-s,
.acciones-lista .sg-item-t,
.acciones-lista .sg-item-s {
    display: block;
}
.lista-conflictos {
    margin: 6px 0 0;
    padding-left: 18px;
}
.acciones-lista .accion {
    width: 100%;
    background: none;
    border: 0;
    text-align: left;
    font: inherit;
    cursor: pointer;
    color: var(--texto);
}
.acciones-lista .accion:hover {
    background: var(--fondo);
}
.editor-footer {
    flex-wrap: wrap;
}
.mobile-actionbar {
    display: none;
}

/* Sesiones independientes: cada una con su día, horario y espacio */
.sesiones-lista {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sesion-fila {
    border: 1px solid var(--borde);
    border-radius: var(--radius-md);
    padding: 10px 12px 6px;
    background: var(--superficie);
}
.sesion-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 32px;
    font-size: 14px;
}
.sesion-campos {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
}
.sesion-dia,
.sesion-espacio {
    grid-column: 1 / -1;
}
.sesion-libres {
    padding-left: 0;
}
.sesiones-resumen {
    margin-top: 4px;
}

@media (max-width: 1199px) {
    .grupos-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 767px) {
    .semana-card,
    .semana-leyenda {
        display: none;
    }
    .agenda-dias {
        display: flex;
    }
    .desktop-assign {
        display: none;
    }
    .mobile-actionbar {
        display: block;
        position: sticky;
        bottom: 0;
        margin: 0 -16px -20px;
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        background: var(--superficie);
        border-top: 1px solid var(--borde);
        box-shadow: var(--sombra-panel);
        z-index: 4;
    }
    .pagehead-actions {
        justify-content: flex-start;
    }
    .grupos-meter {
        min-width: 0;
    }
    .grupos-filtros > .sg-select {
        flex: 1 1 calc(50% - 4px);
    }
    .grupos-filtros > .sg-btn {
        flex: 1 1 calc(50% - 4px);
    }
    .responsive-table td.grupos-meter {
        display: block;
    }
    .responsive-table td.grupos-meter:before {
        display: none;
    }
    .horas-campos,
    .vigencia-campos {
        grid-template-columns: 1fr 1fr;
    }
    .editor-footer .sg-btn {
        flex: 1 1 auto;
    }
}

/* =============================================================================================
   Profesores y bitácora docente (migración 005). Solo usa tokens existentes.
   ============================================================================================= */
.bitacora-lista {
    list-style: none;
    margin: 0;
    padding: 0;
}
.bitacora-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--borde);
}
.bitacora-item:last-child {
    border-bottom: 0;
}
.bitacora-obs {
    margin: 6px 0 2px;
    padding: 8px 10px;
    border-left: 3px solid var(--borde-control);
    background: var(--fondo);
    color: var(--texto);
    font-size: 14px;
    line-height: 20px;
    white-space: pre-line;
    overflow-wrap: anywhere;
}
.bitacora-captura {
    margin-top: 2px;
}
.bitacora-carga {
    border-top: 1px solid var(--borde);
}
.bitacora-carga summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    cursor: pointer;
    color: var(--azul-oscuro);
    font-weight: 600;
    font-size: 14px;
}
.bitacora-carga summary .n {
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--fondo);
    color: var(--texto-secundario-fondo);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}
.areas-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
}
.areas-opciones {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 4px 16px;
    border: 0;
    margin: 0;
    padding: 0;
}
@media (max-width: 767px) {
    .profesores-filtros > .sg-select,
    .profesores-filtros > .sg-btn {
        flex: 1 1 calc(50% - 4px);
    }
    .areas-opciones {
        grid-template-columns: 1fr;
    }
}
.sg-kpi-v.profesor-tiempo {
    font-size: 22px;
    line-height: 30px;
}
