/* PARCHE_PORTAL_PADRES_MOVIL_R12
 * Refinamientos exclusivos para pantallas pequenas del Portal de Padres.
 * No altera escritorio ni la logica academica.
 */

@media (max-width: 920px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body.portal-mobile-scroll-lock {
    overflow: hidden !important;
    touch-action: none;
  }

  #viewHost {
    min-width: 0;
    padding: 16px 14px calc(var(--tab-h) + 38px + env(safe-area-inset-bottom));
    overflow-x: clip;
  }

  #viewHost.portal-mobile-fullbleed {
    max-width: none;
    padding: 0 0 calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
  }

  .topbar {
    gap: 7px;
    padding: 0 10px;
  }

  .topbar > div:not(.spacer):not(.search) {
    min-width: 0;
    max-width: min(42vw, 180px);
  }

  .topbar h1 {
    max-width: 100%;
    overflow: hidden;
    font-size: 17px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .crumb {
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .icon-btn {
    flex: 0 0 40px;
  }

  .view-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

  .view-head h2 {
    font-size: clamp(28px, 9vw, 36px);
  }

  .view-head > .btn,
  .view-head > button.btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .grid > *,
  .card,
  .tramite,
  .subject,
  .grade-card {
    min-width: 0;
    max-width: 100%;
  }

  /* Identidad del estudiante: evita nombre comprimido junto al avatar/boton. */
  .student-hero-top {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
  }

  .student-avatar {
    width: 50px;
    height: 50px;
    flex: 0 0 50px;
    border-radius: 15px;
    font-size: 18px;
  }

  .student-meta {
    min-width: 0;
    flex: 1 1 calc(100% - 62px);
    padding-top: 1px;
  }

  .student-meta b {
    display: block;
    max-width: 100%;
    font-size: 18px;
    line-height: 1.16;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .student-meta span {
    display: block;
    margin-top: 4px;
    line-height: 1.3;
  }

  .student-switch {
    order: 3;
    width: 100%;
    min-height: 42px;
    margin: 0;
    justify-content: center;
  }

  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 8px;
  }

  .hero-stat {
    min-width: 0;
    padding: 12px 10px;
  }

  .hero-stat .k {
    font-size: 10px;
    line-height: 1.25;
  }

  .hero-stat .v {
    font-size: 20px;
  }

  /* Tabbar: respeta el safe-area del iPhone y no tapa el ultimo contenido. */
  .tabbar {
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  /* Drawer movil real para el boton Menu, que antes no tenia accion. */
  .sidebar {
    display: flex !important;
    position: fixed !important;
    z-index: 160;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 320px);
    height: 100dvh;
    max-height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translate3d(-104%, 0, 0);
    transition: transform .24s cubic-bezier(.2,.7,.2,1);
    box-shadow: 22px 0 60px rgba(15, 23, 42, .18);
    visibility: hidden;
  }

  .app.portal-mobile-menu-open .sidebar {
    transform: translate3d(0, 0, 0);
    visibility: visible;
  }

  .sidebar-toggle {
    display: none !important;
  }

  /* Si el usuario dejó la barra colapsada en escritorio, el drawer móvil debe abrir completo. */
  .app.collapsed .brand-text,
  .app.collapsed .nav-section,
  .app.collapsed .nav-item .label,
  .app.collapsed .nav-item .badge,
  .app.collapsed .sidebar-footer .meta {
    display: initial !important;
  }

  .app.collapsed .brand-text,
  .app.collapsed .sidebar-footer .meta {
    display: flex !important;
  }

  .app.collapsed .nav-section {
    display: block !important;
  }

  .app.collapsed .nav-item {
    justify-content: flex-start !important;
    padding: 10px 12px !important;
  }

  .sidebar-footer {
    flex: 0 0 auto;
    align-items: flex-start;
    gap: 11px;
    padding: 12px;
  }

  .sidebar-footer .avatar {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .sidebar-footer .meta {
    min-width: 0;
    flex: 1;
    line-height: 1.25;
  }

  .sidebar-footer .meta b {
    display: -webkit-box;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.25;
    overflow-wrap: anywhere;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .portal-mobile-menu-backdrop {
    position: fixed;
    z-index: 150;
    inset: 0;
    background: rgba(15, 23, 42, .38);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }

  .portal-mobile-menu-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* Asistencia: transforma la tabla en tarjetas legibles sin scroll horizontal. */
  .portal-mobile-attendance-wrap {
    overflow: visible !important;
  }

  table.portal-mobile-attendance-table {
    display: block;
    width: 100% !important;
  }

  .portal-mobile-attendance-table thead {
    display: none;
  }

  .portal-mobile-attendance-table tbody {
    display: grid;
    gap: 10px;
  }

  .portal-mobile-attendance-table tbody tr {
    display: block;
    padding: 11px 13px;
    border: 1px solid var(--line) !important;
    border-radius: 14px;
    background: var(--bg-elev);
  }

  .portal-mobile-attendance-table tbody td {
    display: grid;
    grid-template-columns: minmax(74px, 30%) minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    width: 100%;
    padding: 6px 0 !important;
    border: 0 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .portal-mobile-attendance-table tbody td::before {
    content: attr(data-label);
    color: var(--ink-3);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .05em;
    line-height: 1.35;
    text-transform: uppercase;
  }

  .portal-mobile-attendance-table tbody tr.portal-attendance-empty-row {
    padding: 22px 14px;
  }

  .portal-mobile-attendance-table tbody tr.portal-attendance-empty-row td {
    display: block;
    text-align: center !important;
  }

  .portal-mobile-attendance-table tbody tr.portal-attendance-empty-row td::before {
    display: none;
  }

  .portal-attendance-filters {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 9px !important;
  }

  .portal-attendance-filters select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .portal-attendance-summary {
    display: grid !important;
    gap: 4px;
    padding: 13px 14px !important;
  }

  .portal-attendance-summary span {
    float: none !important;
    display: block;
  }

  /* Modal de excusa: hoja movil estable, sin desbordes del selector de archivos. */
  #modalExcusa {
    z-index: 1000 !important;
    align-items: flex-start !important;
    justify-items: stretch !important;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }

  #modalExcusa > .card {
    width: 100% !important;
    max-width: 560px !important;
    max-height: none !important;
    margin: 0 auto;
    padding: 18px !important;
    border-radius: 20px !important;
    overflow: visible !important;
  }

  #modalExcusa form,
  #modalExcusa form > * {
    min-width: 0;
    max-width: 100%;
  }

  #modalExcusa form > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  #modalExcusa input,
  #modalExcusa select,
  #modalExcusa textarea {
    min-width: 0;
    max-width: 100%;
    font-size: 16px !important;
  }

  #modalExcusa input[type="file"] {
    display: block;
    width: 100% !important;
    min-height: 52px;
    padding: 7px !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  #modalExcusa input[type="file"]::file-selector-button {
    min-height: 38px;
    max-width: 58%;
    margin-right: 9px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-sunken);
    color: var(--ink);
    font: 600 13px/1 var(--font-sans);
  }

  #modalExcusa .portal-excusa-actions {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 9px !important;
  }

  #modalExcusa .portal-excusa-actions .btn {
    width: 100%;
    min-height: 46px;
    justify-content: center;
  }

  .portal-file-feedback {
    display: none;
    margin: -14px 0 16px;
    padding: 9px 11px;
    border: 1px solid color-mix(in srgb, var(--alert) 28%, var(--line));
    border-radius: 10px;
    background: color-mix(in srgb, var(--alert) 7%, transparent);
    color: var(--alert);
    font-size: 12px;
    line-height: 1.45;
  }

  .portal-file-feedback.is-visible {
    display: block;
  }
}

@media (max-width: 720px) {
  /* Comunicaciones: sin detalle seleccionado la caja se ajusta al contenido real. */
  .pcp-comms-layout:not(.has-selection) {
    min-height: 0 !important;
  }

  .pcp-comms-layout:not(.has-selection) .pcp-list-panel {
    min-height: 0;
  }

  .pcp-comms-layout:not(.has-selection) .pcp-message-list {
    min-height: 0;
    max-height: none;
  }

  .pcp-comms-layout:not(.has-selection) .pcp-list-empty {
    min-height: 220px;
  }

  .pcp-comms-hero {
    margin-bottom: 14px !important;
  }

  .pcp-comms-hero h2 {
    font-size: clamp(31px, 10vw, 36px) !important;
  }

  .pcp-comms {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .pcp-list-heading {
    min-height: 54px;
    padding: 0 13px;
  }

  .pcp-message {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
    min-height: 0 !important;
    padding: 12px;
  }

  .pcp-message-icon {
    width: 40px;
    height: 40px;
  }

  .pcp-message-meta {
    gap: 6px;
  }

  .pcp-message-meta time {
    max-width: 44%;
    text-overflow: ellipsis;
  }

  .pcp-detail-card {
    padding: 15px !important;
  }

  .pcp-detail-toolbar {
    gap: 9px;
  }

  .pcp-read-state {
    max-width: 100%;
    min-height: 32px;
    white-space: normal;
    line-height: 1.25;
  }
}

@media (max-width: 420px) {
  .topbar > div:not(.spacer):not(.search) {
    max-width: 116px;
  }

  .topbar .crumb {
    display: none;
  }

  .topbar h1 {
    font-size: 16px;
  }

  .tabbar {
    left: 6px;
    right: 6px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .tab {
    font-size: 9.5px;
  }

  .tab-ico {
    width: 38px;
  }
}
