/* ============================================================
 * CORTEX EDU · Mobile-first layer
 * ============================================================
 * Cobre todas as telas do aluno (e admin) em devices < 1024px.
 * Princípios:
 *   - Touch targets ≥ 44px
 *   - Sidebar/menu colapsável com hamburger
 *   - Cards stacking em coluna
 *   - Tipografia escalável (clamp)
 *   - Safe area (iPhone notch / Android navigation bar)
 * ============================================================ */

/* Safe area iOS notch / android gesture bar */
:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

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

/* Touch-friendly buttons (44px Apple HIG) */
button, .btn, .btn-primary, .btn-link, .cta, a.cta, input[type="submit"], input[type="button"] {
  min-height: 44px;
  touch-action: manipulation;
}
.tag, .pill, small button {
  min-height: auto; /* tags ficam pequenas */
}

/* Inputs em mobile: zoom-prevention (font-size >= 16px) */
@media (max-width: 768px) {
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="tel"], input[type="search"],
  textarea, select {
    font-size: 16px !important;
  }
}

/* ============================================================
 * Hamburger menu (header)
 * ============================================================ */
.nav-toggle {
  display: none;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  width: 44px; height: 44px;
  align-items: center; justify-content: center;
}
.nav-toggle svg { width: 22px; height: 22px; stroke: var(--text); }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }

  /* Nav vira drawer lateral */
  .site-header-inner .nav,
  .site-header .nav {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(82vw, 320px);
    background: #fff;
    flex-direction: column;
    align-items: flex-start;
    padding: 72px 22px 32px;
    box-shadow: -10px 0 40px rgba(0,0,0,0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 9000;
    overflow-y: auto;
    gap: 4px;
  }
  .site-header-inner .nav.open,
  .site-header .nav.open {
    transform: translateX(0);
  }
  .site-header-inner .nav a,
  .site-header .nav a {
    width: 100%;
    padding: 14px 12px;
    border-radius: 10px;
    font-size: 15px;
    min-height: 44px;
  }
  .site-header-inner .nav a:hover,
  .site-header .nav a:hover {
    background: var(--bg-soft, #f8fafc);
  }

  /* Overlay escuro quando drawer aberto */
  body.nav-open::after {
    content: '';
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 8999;
    backdrop-filter: blur(2px);
  }

  /* Lock scroll quando aberto */
  body.nav-open { overflow: hidden; }
}

/* ============================================================
 * Container / spacing
 * ============================================================ */
@media (max-width: 768px) {
  .container { padding-left: max(16px, var(--safe-left)); padding-right: max(16px, var(--safe-right)); }
  .section { padding: 24px 0; }
  .section-pad { padding: 20px 0; }

  /* Cards empilham */
  .dash-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .dash-card {
    padding: 18px !important;
    border-radius: 12px;
  }

  /* Tabelas com scroll horizontal */
  .table, table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* ============================================================
 * Tipografia escalável
 * ============================================================ */
h1 { font-size: clamp(22px, 5vw, 36px); line-height: 1.2; }
h2 { font-size: clamp(18px, 4vw, 26px); line-height: 1.3; }
h3 { font-size: clamp(16px, 3.5vw, 20px); line-height: 1.4; }

/* ============================================================
 * Aluno: bottom-nav fixo em mobile (acesso rápido aos atalhos)
 * ============================================================ */
.aluno-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 6px max(8px, var(--safe-left)) calc(6px + var(--safe-bottom)) max(8px, var(--safe-right));
  z-index: 8000;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
}
.aluno-bottom-nav ul {
  display: flex; gap: 4px;
  list-style: none; margin: 0; padding: 0;
  justify-content: space-around;
}
.aluno-bottom-nav a {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  padding: 8px 6px;
  font-size: 10px;
  color: var(--muted, #64748b);
  text-decoration: none;
  border-radius: 10px;
  min-width: 56px;
  min-height: 44px;
}
.aluno-bottom-nav a.active {
  color: var(--accent, #7c3aed);
  background: rgba(124,58,237,0.08);
}
.aluno-bottom-nav a .ico { font-size: 20px; line-height: 1; }

@media (max-width: 768px) {
  body.aluno-page .aluno-bottom-nav { display: block; }
  /* Espaço extra no main pra não ser coberto pelo bottom-nav */
  body.aluno-page main {
    padding-bottom: calc(80px + var(--safe-bottom));
  }
}

/* ============================================================
 * Forms: campos full-width em mobile
 * ============================================================ */
@media (max-width: 768px) {
  .field { margin-bottom: 14px; }
  .field input, .field select, .field textarea {
    padding: 12px 14px;
    border-radius: 10px;
  }
}

/* ============================================================
 * Cards do dashboard (gamification): força 1 coluna em < 500px
 * ============================================================ */
@media (max-width: 500px) {
  .dash-grid[style*="repeat"] {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
 * Sino de notificações: panel cobre tela inteira em mobile
 * ============================================================ */
@media (max-width: 480px) {
  #notifPanel {
    position: fixed !important;
    top: 60px !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-height: calc(100vh - 100px) !important;
  }
}

/* ============================================================
 * Imagens responsivas por default
 * ============================================================ */
img, video { max-width: 100%; height: auto; }

/* ============================================================
 * Reduce motion (respeita preferência do usuário)
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * Dark mode auto (respeita preferência do usuário · landings)
 * ============================================================ */
@media (prefers-color-scheme: dark) {
  /* Por enquanto, só ajustamos a barra de status do PWA */
  meta[name="theme-color"] { color: #0a0e1a; }
}
