/* ==============================================================
   ALTITUDE — AJUSTES RESPONSIVOS 06
   Prioridade: celular e tablet, sem alterar a identidade visual.
   Carregado por último para corrigir regras antigas e duplicadas.
   ============================================================== */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  min-width: 0;
  overflow-x: hidden !important;
}

button,
a,
input,
select,
textarea,
label {
  touch-action: manipulation;
}

button,
[role="button"],
input,
select,
textarea {
  min-height: 44px;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto;
}

/* ---------- SITE PÚBLICO ---------- */
@media (max-width: 900px) {
  .new-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 44px;
    align-items: center;
    gap: 12px;
    min-height: 66px;
    padding: 9px 14px;
  }

  .new-header .logo,
  .new-header .logo a {
    min-width: 0;
  }

  .new-header .logo img {
    width: min(136px, 44vw);
    max-height: 48px;
    object-fit: contain;
    object-position: left center;
  }

  .new-header .menu-icon {
    justify-self: end;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 7px;
  }

  .new-header .dropdown-menu {
    top: calc(100% + 2px) !important;
    right: 10px !important;
    width: min(320px, calc(100vw - 20px));
    max-height: calc(100dvh - 82px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .new-header .dropdown-menu a {
    min-height: 46px;
    display: flex;
    align-items: center;
  }

  .catalog-main,
  .legal-page {
    width: min(100% - 24px, 1200px) !important;
  }

  .catalog-hero {
    gap: 22px;
  }

  .catalog-heading,
  .section-heading,
  .page-heading {
    min-width: 0;
  }

  .catalog-tools > *,
  .hero-actions > *,
  .public-course-actions > * {
    min-width: 0;
  }

  .rodape {
    width: 100%;
    margin: 0;
  }
}

@media (max-width: 720px) {
  .catalog-main {
    width: min(100% - 20px, 1200px) !important;
    padding-bottom: 48px;
  }

  .catalog-hero {
    padding: 24px 18px !important;
  }

  .catalog-hero h1 {
    font-size: clamp(1.85rem, 9vw, 2.7rem);
  }

  .hero-actions,
  .public-course-actions {
    display: grid !important;
    grid-template-columns: 1fr;
  }

  .hero-actions a,
  .public-course-actions button,
  .catalog-primary-button,
  .catalog-secondary-button {
    width: 100%;
  }

  .workload-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .workload-box {
    min-width: 0;
    text-align: center;
  }

  .public-course-body h3 {
    min-height: 0 !important;
    overflow-wrap: break-word;
    word-break: normal;
  }

  .course-stat-grid {
    gap: 5px;
  }

  .course-stat-grid span {
    padding: 8px 3px;
  }

  .catalog-modal {
    padding: 0 !important;
    align-items: end;
  }

  .catalog-modal-sheet {
    width: 100%;
    max-height: 100dvh !important;
    border-radius: 18px 18px 0 0;
  }

  .catalog-modal-content {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  .workload-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ---------- PORTAL DO ALUNO ---------- */
@media (max-width: 980px) {
  .student-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    width: min(310px, 88vw) !important;
    height: 100dvh !important;
    max-height: 100dvh;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-105%);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 120;
  }

  .student-sidebar.open {
    transform: translateX(0) !important;
  }

  .sidebar-overlay.show {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(5, 25, 44, .52);
    backdrop-filter: blur(2px);
  }

  .student-content {
    width: 100% !important;
    max-width: 100%;
    margin-left: 0 !important;
    padding: 14px clamp(12px, 3vw, 24px) 36px !important;
  }

  .mobile-menu-button {
    display: grid !important;
    place-items: center;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
    padding: 0 !important;
    align-self: center !important;
  }

  .student-topbar {
    top: 8px;
    min-height: 68px;
    padding: 10px 12px;
  }

  .student-topbar,
  .topbar-left,
  .topbar-actions,
  .student-profile-button {
    min-width: 0;
  }

  .topbar-left {
    flex: 1 1 auto;
  }

  .topbar-left > div {
    min-width: 0;
  }

  .topbar-left strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .profile-grid,
  .support-grid,
  .dashboard-grid,
  .dashboard-grid.lower-grid {
    grid-template-columns: 1fr !important;
  }

  .student-card-area {
    width: 100%;
    max-width: 520px;
    justify-self: center;
  }
}

@media (max-width: 760px) {
  .student-content {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .student-topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center !important;
    gap: 8px;
    border-radius: 14px;
    margin-bottom: 20px;
  }

  .topbar-left {
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 9px;
  }

  .topbar-actions {
    justify-content: end !important;
  }

  .portal-search {
    display: none !important;
  }

  .student-profile-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0 !important;
    border: 0 !important;
  }

  .student-profile-button img {
    width: 42px;
    height: 42px;
  }

  .student-profile-button span {
    display: none !important;
  }

  .welcome-panel,
  .surface-card,
  .section-block,
  .certificate-card,
  .issued-certificate-card {
    border-radius: 15px;
  }

  .welcome-panel {
    padding: 24px 18px !important;
  }

  .summary-grid,
  .course-grid,
  .course-grid.compact,
  .hours-wallet-summary,
  .wallet-balance-grid {
    grid-template-columns: 1fr !important;
  }

  .card-title-row,
  .section-title,
  .page-heading,
  .certificate-card-top,
  .certificate-card-footer {
    align-items: stretch !important;
    flex-direction: column;
  }

  .section-title > span,
  .page-heading > a,
  .secondary-link {
    align-self: flex-start;
  }

  .continue-course {
    grid-template-columns: 1fr !important;
  }

  .continue-course img {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 16 / 9;
  }

  .lesson-resource {
    align-items: stretch !important;
    flex-direction: column;
  }

  .lesson-resource a,
  .lesson-resource button {
    width: 100%;
    text-align: center;
  }

  .lesson-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .lesson-actions > * {
    width: 100%;
  }

  .modal {
    padding: 0 !important;
    place-items: stretch !important;
  }

  .study-modal,
  .quiz-modal {
    width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none;
  }

  .study-header,
  .quiz-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 13px 14px !important;
    background: #fff;
  }

  .study-header h2,
  .quiz-header h2 {
    font-size: 18px !important;
    overflow-wrap: break-word;
  }

  .study-progress-row {
    padding: 9px 14px !important;
  }

  .study-body {
    display: flex !important;
    flex-direction: column;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }

  .module-sidebar {
    flex: 0 0 auto;
    width: 100%;
    height: auto !important;
    max-height: 245px !important;
    padding: 12px !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--line);
    overflow: hidden !important;
  }

  .module-list {
    max-height: 150px !important;
    overflow-y: auto !important;
  }

  .lesson-area {
    flex: 1 0 auto;
    min-height: 0;
    overflow: visible !important;
    padding: 20px 14px max(24px, env(safe-area-inset-bottom)) !important;
  }

  #quizBody {
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto;
    padding: 20px 14px !important;
  }

  .quiz-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 11px 12px max(11px, env(safe-area-inset-bottom)) !important;
  }

  .quiz-footer span {
    grid-column: 1 / -1;
    text-align: center;
  }

  .quiz-footer button {
    width: 100%;
  }

  .issued-certificate-card,
  .certificate-history-item,
  .hours-history-item {
    grid-template-columns: 1fr !important;
  }

  .issued-certificate-actions,
  .history-date,
  .hours-history-value {
    grid-column: auto !important;
    justify-content: stretch !important;
    justify-items: start !important;
    padding-left: 0 !important;
    text-align: left !important;
  }

  .issued-certificate-actions > * {
    width: 100%;
  }

  .hours-request-control {
    grid-template-columns: 1fr !important;
  }

  .hours-request-control > * {
    width: 100%;
  }

  .photo-field {
    align-items: center !important;
    flex-direction: column !important;
    text-align: center;
  }

  .upload-button {
    width: 100% !important;
  }

  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .form-grid .full {
    grid-column: auto !important;
  }

  .digital-card {
    width: 100% !important;
    max-width: 430px !important;
  }

  .digital-card-body {
    grid-template-columns: 68px minmax(0, 1fr) !important;
    gap: 12px !important;
    padding: 15px !important;
  }

  .digital-card-body > img {
    width: 68px !important;
    height: 68px !important;
  }

  .digital-card-data,
  .digital-card-data strong,
  .student-card-name,
  .student-card-ra {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    hyphens: none !important;
    white-space: normal !important;
  }

  .student-card-name {
    font-size: 14px !important;
    line-height: 1.35 !important;
  }

  .digital-card-footer {
    align-items: center !important;
    flex-wrap: wrap;
  }

  .digital-card-qr {
    margin-left: auto;
  }

  .toast,
  .gestor-toast,
  .catalog-toast {
    left: 10px !important;
    right: 10px !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    max-width: none !important;
  }
}

@media (max-width: 380px) {
  .digital-card-body {
    grid-template-columns: 1fr !important;
    text-align: center;
  }

  .digital-card-body > img {
    justify-self: center;
  }

  .student-card-ra {
    justify-content: center;
  }

  .digital-card-footer {
    align-items: center !important;
    flex-direction: column;
    text-align: center;
  }

  .digital-card-qr {
    margin: 0 auto;
  }
}

/* ---------- PORTAL DO GESTOR ---------- */
@media (max-width: 980px) {
  body:has(.gestor-topbar) .container {
    display: block !important;
    width: 100%;
    min-height: 100dvh;
  }

  #gestorSidebar,
  .sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    width: min(310px, 88vw) !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    max-height: 100dvh;
    transform: translateX(-105%);
    overflow-y: auto !important;
    overscroll-behavior: contain;
    padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
    z-index: 130 !important;
  }

  #gestorSidebar.open,
  .sidebar.open {
    transform: translateX(0) !important;
  }

  .gestor-sidebar-overlay.show {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(5, 25, 44, .52);
    backdrop-filter: blur(2px);
  }

  .conteudo {
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
    padding: 0 clamp(12px, 3vw, 24px) 34px !important;
  }

  .gestor-topbar {
    top: 0;
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 9px !important;
    min-height: 68px !important;
    margin: 0 calc(clamp(12px, 3vw, 24px) * -1) 20px !important;
    padding: 10px clamp(12px, 3vw, 24px) !important;
  }

  .mobile-menu {
    display: grid !important;
    place-items: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 !important;
  }

  .gestor-topbar > div:nth-child(2),
  .gestor-topbar h1 {
    min-width: 0;
  }

  .gestor-topbar h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dashboard-kpis,
  .workflow-grid,
  .dashboard-columns,
  .ai-layout,
  .certificate-admin-kpis,
  .certificate-admin-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .grid2,
  .grid3,
  .grid-2 {
    grid-template-columns: 1fr !important;
  }

  .table-wrap,
  .tabela-wrap,
  .responsive-table,
  .card:has(table),
  .bloco:has(table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table,
  .tabela {
    width: max(760px, 100%) !important;
    min-width: 760px;
  }

  .modal {
    align-items: stretch !important;
    justify-content: stretch !important;
    padding: 0 !important;
  }

  .modal__sheet,
  #modalModulos .modal__sheet,
  #modalMateriais .modal__sheet,
  #modalProvas .modal__sheet,
  #modalEdicaoProva .modal__sheet,
  .certificate-hours-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    padding: 16px 14px max(20px, env(safe-area-inset-bottom)) !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }

  .modal__sheet > h3,
  .modal__sheet > .modal-title,
  .modal-header {
    position: sticky;
    top: -16px;
    z-index: 4;
    margin-left: -14px !important;
    margin-right: -14px !important;
    padding: 14px !important;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
  }

  .toolbar,
  .inline,
  .certificate-admin-toolbar,
  .actions,
  .ai-actions {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  .toolbar > *,
  .inline > *,
  .actions > *,
  .ai-actions > *,
  .certificate-admin-toolbar > * {
    width: 100% !important;
  }
}

@media (max-width: 620px) {
  .conteudo {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .gestor-topbar {
    margin-left: -10px !important;
    margin-right: -10px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .gestor-topbar h1 {
    font-size: 17px !important;
  }

  .topbar-actions {
    gap: 4px !important;
  }

  .topbar-actions a {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0 !important;
    display: grid;
    place-items: center;
    overflow: hidden;
    font-size: 0 !important;
  }

  .topbar-actions a::after {
    content: "↗" !important;
    font-size: 17px !important;
  }

  .dashboard-kpis,
  .workflow-grid,
  .certificate-admin-kpis,
  .certificate-admin-summary,
  .ia-result-stats {
    grid-template-columns: 1fr !important;
  }

  .welcome-panel,
  .gestor-card,
  .card,
  .bloco {
    padding: 15px !important;
    border-radius: 13px !important;
  }

  .page-heading h2,
  .page-heading h1,
  .welcome-panel h2 {
    font-size: clamp(1.45rem, 8vw, 2rem) !important;
  }

  .modal .actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .modal .actions button,
  .modal .actions a {
    width: 100%;
  }
}

/* ---------- LOGINS, CADASTRO E VALIDAÇÕES ---------- */
@media (max-width: 760px) {
  .login-container,
  .cadastro-container,
  .auth-card,
  .validation-card,
  .certificado-container,
  .form-card {
    width: min(100% - 20px, 620px) !important;
    max-width: calc(100vw - 20px) !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .password-wrapper,
  .input-senha,
  .senha-container {
    width: 100%;
  }

  .password-wrapper input,
  .input-senha input,
  .senha-container input {
    padding-right: 48px !important;
  }

  .password-wrapper button,
  .input-senha button,
  .senha-container button,
  .toggle-password {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }

  .validation-grid,
  .certificado-dados,
  .certificate-validation-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Elementos gerados pelo ajuste JavaScript */
.responsive-table-shell {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: inherit;
}

.responsive-table-shell:focus-visible {
  outline: 3px solid rgba(82, 192, 217, .35);
  outline-offset: 2px;
}

@media (max-width: 980px) {
  html.mobile-overlay-open,
  html.mobile-overlay-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
  }
}

@media (max-width: 760px) {
  /* Neutraliza grades e linhas definidas diretamente no HTML do gestor. */
  .modal [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .modal [style*="display: flex"] {
    flex-wrap: wrap !important;
  }

  .modal [style*="text-align: right"] > button,
  .modal form > [style*="display: flex"] > button {
    width: 100% !important;
  }

  #modalModulos .modal__sheet > div:first-child,
  #modalMateriais .modal__sheet > div:first-child,
  #modalProvas .modal__sheet > div:first-child,
  #modalEdicaoProva .modal__sheet > div:first-child {
    position: sticky;
    top: -16px;
    z-index: 6;
    margin: -16px -14px 14px !important;
    padding: 14px !important;
    background: #fff !important;
  }
}

/* ==============================================================
   ATUALIZAÇÃO 10 — TABLETS, GESTÃO SIMPLIFICADA E SIDEBAR
   ============================================================== */
@media (max-width: 1120px) {
  body:has(.gestor-topbar) #gestorSidebar,
  body:has(.gestor-topbar) .sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    width: min(310px, 88vw) !important;
    height: 100dvh !important;
    margin: 0 !important;
    transform: translateX(-105%) !important;
    transition: transform .22s ease !important;
    z-index: 130 !important;
  }
  body:has(.gestor-topbar) #gestorSidebar.open,
  body:has(.gestor-topbar) .sidebar.open {
    transform: translateX(0) !important;
  }
  body:has(.gestor-topbar) .conteudo {
    width: 100% !important;
    margin-left: 0 !important;
    padding: 0 clamp(12px, 3vw, 24px) 34px !important;
  }
  body:has(.gestor-topbar) .mobile-menu { display: grid !important; }
  .course-builder-modal,
  .simple-exam-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }
  .course-builder-grid,
  .simple-exam-layout {
    max-height: none;
    min-height: 0;
    height: calc(100dvh - 207px);
  }
}

@media (max-width: 820px) {
  .builder-steps {
    display: flex;
    overflow-x: auto;
    padding: 10px 14px;
    scroll-snap-type: x proximity;
  }
  .builder-steps span {
    flex: 0 0 auto;
    min-width: 145px;
    scroll-snap-align: start;
  }
  .course-builder-grid,
  .simple-exam-layout {
    display: block !important;
    height: calc(100dvh - 205px);
    overflow-y: auto;
  }
  .builder-create-panel,
  .builder-list-panel,
  .simple-exam-create,
  .simple-exam-list {
    overflow: visible;
    border: 0;
  }
  .builder-create-panel,
  .simple-exam-create {
    border-bottom: 1px solid #dce6ef;
  }
  .builder-help-card { display: none; }
  .builder-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
  }
  .course-action-cell { min-width: 220px; }
}

@media (max-width: 620px) {
  .course-builder-header {
    position: sticky;
    top: 0;
    z-index: 8;
    padding: 14px;
  }
  .course-builder-header h3 { font-size: 18px; }
  .course-builder-header p:not(.builder-eyebrow) { display: none; }
  .builder-steps { padding: 8px 10px; }
  .builder-steps span { min-width: 128px; padding: 7px 8px; }
  .builder-create-panel,
  .builder-list-panel,
  .simple-exam-create,
  .simple-exam-list { padding: 15px 12px; }
  .builder-two-fields,
  .builder-title-order { grid-template-columns: 1fr !important; }
  .builder-list-heading { align-items: stretch; flex-direction: column; }
  .builder-list-heading > button { width: 100%; }
  .builder-module-top { grid-template-columns: 34px minmax(0, 1fr); }
  .builder-status { grid-column: 2; justify-self: start; }
  .builder-progress-row { align-items: stretch; flex-direction: column; gap: 5px; }
  .builder-module-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .builder-module-actions button { width: 100%; min-height: 44px; }
  .builder-module-actions button.primary { grid-column: 1 / -1; }
  .builder-footer { align-items: stretch; flex-direction: column; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
  .builder-footer button { width: 100%; }
  .builder-footer p { display: none; }
  .simple-exam-card { align-items: stretch; flex-direction: column; }
  .simple-exam-card > div:last-child { display: grid; grid-template-columns: 1fr; }
  .simple-exam-card button { width: 100%; min-height: 44px; }
  .course-more-actions > div { position: fixed; left: 12px; right: 12px; bottom: 12px; top: auto; width: auto; z-index: 250; }
}
