/* Portal EAD — Theme V2 (clean override)
 * Objetivo: padronizar 100% o visual de todas as páginas (Estudante/Professor/Admin)
 * sem depender de CSS duplicado/antigo.
 *
 * Carrega DEPOIS do assets/estilo.css para sobrescrever o que estiver divergente.
 */

/* Tipografia */
:root{
  --font-sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* Tokens base (páginas PHP definem --cor-principal dinamicamente) */
  --brand: var(--cor-principal);
  /* Compatibilidade com CSS legado (estilo.css) */
  --cor-fundo: var(--bg);
  --cor-texto: var(--text);
  --cor-borda: var(--border);
  --cor-primaria: var(--brand);
  --cor-sidebar: var(--sidebar-bg);
  --cor-topbar: var(--surface);
  --cor-texto-invertido: #ffffff;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --line: var(--border);
  --line-2: rgba(15,23,42,.06);
  --ink: var(--text);

  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15,23,42,.10);
  --border-strong: rgba(15,23,42,.16);
  --shadow: 0 14px 42px rgba(2,6,23,.08);
  --shadow-sm: 0 10px 26px rgba(2,6,23,.06);
  --radius: 18px;
  --radius-sm: 14px;

  --sidebar-w: 280px;
  --topbar-h: 64px;

  --brand-soft: color-mix(in srgb, var(--brand) 12%, #ffffff);
  --brand-soft-2: color-mix(in srgb, var(--brand) 18%, #ffffff);
  --brand-ink: color-mix(in srgb, var(--brand) 82%, #0b1020);

  --sidebar-bg: color-mix(in srgb, #0b1020 90%, var(--brand));
  --sidebar-bg-2: color-mix(in srgb, #0b1020 76%, var(--brand));
  --sidebar-text: rgba(226,232,240,.92);
  --sidebar-muted: rgba(226,232,240,.68);

  --focus-ring: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, #ffffff);

  /* Aliases/compatibilidade (tokens usados em partes antigas do CSS) */
  --tx: var(--text);
  --bg-soft: color-mix(in srgb, var(--bg) 70%, var(--surface));
  --line-soft: color-mix(in srgb, var(--border) 70%, transparent);
  --shadow-card: var(--shadow-sm);
  --shadow-soft: var(--shadow-sm);
  --shadow-pro: var(--shadow);
  --radius-xl: 22px;
  --raio-borda: var(--radius);
  --sombras: var(--shadow);
  --surface-glass: color-mix(in srgb, var(--surface) 70%, transparent);

}

html,body{ height:100%; background-color: var(--bg); color: var(--text); }
body{
  font-family: var(--font-sans) !important;
  background: var(--bg) !important;
  color: var(--text) !important;
}

/* Links */
a{ color: var(--brand-ink); }
a:hover{ filter: brightness(.95); }

/* Layout geral */
.layout{
  display:flex !important;
  min-height:100vh;
  background: var(--bg) !important;
}

.main{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
}

.main-content{
  width:100%;
  max-width: var(--page-width, 1239px);
  margin: 0 auto;
  padding: 20px var(--page-pad-x, 16px) 36px !important;
}

/* Topbar */
.topbar{
  position: sticky;
  top: 0;
  z-index: 60;
  min-height: var(--topbar-h);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 14px;
  padding: 10px 16px;
  background: rgba(255,255,255,.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar .welcome{
  font-weight: 800;
  letter-spacing: .2px;
  color: var(--text);
}

.topbar .topbar-user{ display:flex; align-items:center; gap:12px; min-width:0; }
.topbar img.avatar{ width:40px; height:40px; border-radius:999px; object-fit:cover; border:1px solid var(--border); background: var(--surface); }

.sidebar-toggle{
  width:44px; height:44px;
  display:grid; place-items:center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor:pointer;
}
.sidebar-toggle:hover{ transform: translateY(-1px); }

/* Sidebar */
.sidebar{
  width: var(--sidebar-w) !important;
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow:auto;
  padding: 14px 12px;
}

.sidebar .logo{
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 10px 10px 16px;
  margin-bottom: 8px;
  position:relative;
}
.sidebar .logo img{ max-height: 56px; width:auto; display:block; }
.sidebar .logo span{ font-weight: 900; letter-spacing:.2px; text-align:center; }

.sidebar a{
  display:flex;
  align-items:center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--sidebar-text);
  text-decoration:none;
  font-weight: 800;
  font-size: 13px;
  margin: 6px 4px;
  border: 1px solid rgba(255,255,255,0);
  transition: .15s ease;
}
.sidebar a .menu-ico{ width:18px; text-align:center; opacity:.95; }
.sidebar a:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.12);
  transform: translateX(2px);
}
.sidebar a.ativo{
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.18);
  box-shadow: 0 10px 24px rgba(0,0,0,.18);
}
.sidebar a.ativo .menu-ico{ color: #fff; }

/* Botões */
.btn{
  border-radius: 14px !important;
  padding: 10px 14px !important;
  font-weight: 900 !important;
  letter-spacing: .2px;
  display:inline-flex;
  align-items:center;
  gap: 10px;
}
.btn-primary, .btn.btn-primary, .btn:not(.btn-secondary):not(.btn-danger){
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 78%, #111827));
  border: 1px solid rgba(255,255,255,.0);
  box-shadow: 0 14px 30px rgba(2,6,23,.16);
}
.btn-secondary, .btn.btn-secondary{
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-sm);
}
.btn-danger, .btn.btn-danger{
  background: #ef4444 !important;
  border: 1px solid rgba(239,68,68,.0) !important;
}

.btn:hover{ transform: translateY(-1px); }

/* Cards */
.card, .table-card, .form-card{
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}
.card-body{ padding: 18px !important; }

/* Cabeçalho de página */
.page-header{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap: 16px;
  margin: 8px 0 18px;
  flex-wrap:wrap;
}
.page-kicker{ font-size:12px; font-weight:900; color: var(--muted); text-transform:uppercase; letter-spacing:.6px; }
.page-title{ margin:0; font-size: 22px; font-weight: 950; letter-spacing:-.02em; }
.page-actions{ display:flex; gap:10px; flex-wrap:wrap; }

/* Formulários */
.form-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 900px){
  .form-grid{ grid-template-columns:1fr; }
}

.form-field label{ font-weight: 900; font-size: 13px; color: var(--text); display:block; margin-bottom: 8px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="time"], select, textarea{
  width:100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: .15s ease;
}
textarea{ min-height: 110px; resize: vertical; }

input:focus, select:focus, textarea:focus{
  border-color: color-mix(in srgb, var(--brand) 35%, #ffffff);
  box-shadow: var(--focus-ring);
}

.fi{ position:relative; display:block; }
.fi-ico{ position:absolute; left:12px; top:50%; transform: translateY(-50%); color: color-mix(in srgb, var(--brand) 38%, #334155); opacity:.95; }
.fi-field{ padding-left: 42px !important; }

.is-invalid input, .is-invalid select, .is-invalid textarea{
  border-color:#dc2626 !important;
  box-shadow: 0 0 0 4px rgba(220,38,38,.12) !important;
}

/* Tabelas */
table{ width:100%; border-collapse:collapse; }
thead th{
  text-align:left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td{ padding: 12px 12px; border-bottom: 1px solid rgba(15,23,42,.06); vertical-align: top; }
tbody tr:hover td{ background: rgba(2,6,23,.02); }

/* Avisos */
.notice{
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin: 10px 0 14px;
}
.notice--success{ background: rgba(34,197,94,.10); border-color: rgba(34,197,94,.25); }
.notice--danger{ background: rgba(239,68,68,.10); border-color: rgba(239,68,68,.25); }

/* Badges */
.badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 12px;
  border: 1px solid var(--border);
  background: rgba(2,6,23,.03);
}

/* Progresso */
.progress-bar{
  height: 10px;
  border-radius: 999px;
  background: rgba(2,6,23,.08);
  overflow:hidden;
}
.progress-bar > div{
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 82%, #0b1020));
}

/* Responsivo: sidebar off-canvas */
@media (max-width: 900px){
  .layout{ flex-direction:column; }
  .sidebar{
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-110%);
    transition: transform .18s ease;
    box-shadow: 0 40px 90px rgba(0,0,0,.35);
    z-index: 1000;
  }
  body.sidebar-open .sidebar{ transform: translateX(0); }
  .sidebar-backdrop{
    position: fixed;
    inset: 0;
    background: rgba(2,6,23,.42);
    z-index: 999;
    opacity: 0;
    pointer-events:none;
    transition: opacity .18s ease;
  }
  body.sidebar-open .sidebar-backdrop{ opacity: 1; pointer-events: all; }
}


/* FIX MENU LINKS MOBILE: garante que nada fique por cima do menu e que links recebam toque */
@media (max-width: 900px){
  .sidebar{ z-index: 5000 !important; pointer-events:auto !important; -webkit-overflow-scrolling: touch; }
  .sidebar a{ pointer-events:auto !important; touch-action: manipulation; }
  .sidebar-backdrop{ z-index: 4990 !important; }
}

/* =====================================================
   MOBILE/TABLET HARDENING — evita páginas "quebradas" no mobile
   (tabelas largas, modais estourando e conteúdo encostando na borda)
   ===================================================== */

@media (max-width: 1024px){
  html, body{ overflow-x: hidden; }
  img, svg, video, canvas, iframe{ max-width: 100%; }

  /* conteúdo não encosta na borda */
  .main-content{
    max-width: 100% !important;
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  /* tabelas: sempre com scroll horizontal (principal causa de "página quebrada" no mobile) */
  .table-card{ overflow-x:auto; -webkit-overflow-scrolling: touch; }
  .table-card table{ display:block; overflow-x:auto; -webkit-overflow-scrolling: touch; }

  /* modais: nunca estourar a tela (rolagem interna no corpo) */
  .sys-modal{ max-height: calc(100vh - 24px); overflow:hidden; display:flex; flex-direction:column; }
  .sys-modal-body{ overflow:auto; -webkit-overflow-scrolling: touch; }
  .sys-center{ max-height: calc(100vh - 24px); overflow:auto; }
}

/* Mobile: barra superior e botões mais compactos */
@media (max-width: 600px){
  .topbar{ padding: 10px 12px; gap: 10px; }
  .topbar .welcome{
    font-size: 12px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .btn-sair-top{ padding: 8px 12px; font-size: 12px; }
  .sidebar-toggle{ width: 42px; height: 42px; border-radius: 14px; }
}

/* Quando sidebar estiver aberta no mobile, trava scroll do fundo */
@media (max-width: 900px){
  body.sidebar-open{ overflow: hidden; touch-action: none; }
}

/* Compat: a marcação .sys-modal-head existe em vários modais */
.sys-modal-head{ display:flex; flex-direction:column; gap:2px; }


/* ==========================================================
 * Componentes padronizados (painéis) — compatíveis com A11Y
 * ========================================================== */

/* Avisos (push) */
.push-list{ display:grid; gap:14px; }
.push-item{
  border:1px solid var(--border);
  border-radius:16px;
  background: var(--surface);
  padding:14px 14px 12px;
}
.push-head{ display:flex; gap:10px; align-items:flex-start; justify-content:space-between; flex-wrap:wrap; }
.push-title{ font-weight:900; font-size:15px; margin:0; color: var(--text); }
.push-meta{ font-size:12px; color: var(--muted); display:flex; gap:10px; flex-wrap:wrap; }
.push-body{ margin-top:8px; color: var(--text); line-height:1.55; white-space:pre-line; }
.push-badges{ display:flex; gap:8px; align-items:center; }
.push-badge{
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 10px; border-radius:999px;
  background: var(--surface-2); color: var(--text);
  font-size:12px; font-weight:800;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.push-badge--new{ background: rgba(239,68,68,.14); color:#b91c1c; border-color: rgba(239,68,68,.25); }
html.a11y-contrast .push-badge--new{ color:#ffb4b4; border-color: rgba(255,255,255,.22); }
.push-actions{ margin-top:10px; display:flex; gap:10px; flex-wrap:wrap; }

/* Toast de avisos */
.push-toast{
  position:fixed; top:12px; right:12px; z-index:9999;
  width:calc(100vw - 24px); max-width:420px;
  background: var(--text); color: var(--surface);
  border-radius:18px;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
  padding:12px 12px;
  display:flex; gap:10px; align-items:flex-start;
  border: 1px solid color-mix(in srgb, var(--surface) 35%, transparent);
  opacity:0; transform:translateY(-18px);
  pointer-events:none;
  transition: all .22s ease;
}
.push-toast.is-show{ opacity:1; transform:translateY(0); pointer-events:auto; }
html.a11y-contrast .push-toast{ box-shadow:none; border-color: rgba(226,232,240,.22); }

.push-toast__icon{
  width:34px; height:34px; border-radius:12px;
  display:flex; align-items:center; justify-content:center;
  flex:0 0 34px; margin-top:2px;
  background: color-mix(in srgb, var(--surface) 14%, transparent);
}
.push-toast__title{ font-weight:900; font-size:14px; line-height:1.2; margin:0 0 4px; }
.push-toast__from{ font-size:12px; line-height:1.2; opacity:.85; margin:0 0 6px; }
.push-toast__msg{ font-size:13px; line-height:1.35; opacity:.95; white-space:pre-line; }

.push-toast__actions{ margin-top:8px; display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.push-toast__link{
  color: var(--surface);
  text-decoration:none;
  font-weight:900; font-size:12px;
  padding:6px 10px; border-radius:999px;
  background: color-mix(in srgb, var(--surface) 22%, transparent);
  border:1px solid color-mix(in srgb, var(--surface) 28%, transparent);
}
.push-toast__close{
  margin-left:auto;
  background:transparent;
  border:0;
  color: var(--surface);
  opacity:.85;
  font-size:18px; line-height:1;
  cursor:pointer;
  padding:6px 8px;
  border-radius:10px;
}
.push-toast__close:hover{
  background: color-mix(in srgb, var(--surface) 16%, transparent);
  opacity:1;
}
@media(max-width: 520px){
  .push-toast{ left:12px; right:12px; }
}

/* Botão flutuante do chat */
.chat-fab{
  position:fixed; right:16px; bottom:16px; z-index:9998;
  display:flex; align-items:center; gap:10px;
  padding:12px 14px;
  border-radius:999px;
  border:1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  cursor:pointer;
}
.chat-fab__badge{
  min-width:18px; height:18px; padding:0 6px;
  display:none; align-items:center; justify-content:center;
  border-radius:999px;
  background: rgba(239,68,68,.12);
  color:#b91c1c;
  font-size:11px; font-weight:900;
  border:1px solid rgba(239,68,68,.22);
}
.chat-fab.has-unread .chat-fab__badge{ display:inline-flex; }

/* Grade de cards (cursos / biblioteca etc) */
.grid-cards{ display:grid; gap:16px; grid-template-columns: repeat(12, 1fr); }
.grid-cards > *{ grid-column: span 12; }
@media (min-width: 780px){
  .grid-cards.cols-2 > *{ grid-column: span 6; }
  .grid-cards.cols-3 > *{ grid-column: span 4; }
}

/* Perfil */
.profile-card, .card.profile-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}
.profile-item{
  background: var(--surface-2);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 16px;
}
/* Tabelas padronizadas (funciona em auto/alto contraste) */
table{ color: var(--text); }
.table, table.table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border:1px solid var(--border);
  border-radius: 18px;
  overflow:hidden;
}
.table thead th, table.table thead th{
  background: var(--surface-2);
  color: var(--text);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
  padding: 12px 12px;
  text-transform: uppercase;
}
.table td, table.table td{
  padding: 12px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  vertical-align: top;
  background: var(--surface);
}
.table tbody tr:last-child td{ border-bottom: none; }
.table tbody tr:hover td{
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
}
.table-responsive{
  width:100%;
  overflow:auto;
  border-radius: 18px;
  -webkit-overflow-scrolling: touch;
}

/* Tabelas genéricas dentro do painel (quando não usam .table) */
.main-content table:not(.table):not(.no-style){
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border:1px solid var(--border);
  border-radius: 18px;
  overflow:hidden;
}
.main-content table:not(.table):not(.no-style) thead th{
  background: var(--surface-2);
  color: var(--text);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
  padding: 12px 12px;
  text-transform: uppercase;
}
.main-content table:not(.table):not(.no-style) td{
  padding: 12px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  vertical-align: top;
  background: var(--surface);
}
.main-content table:not(.table):not(.no-style) tbody tr:last-child td{ border-bottom: none; }
.main-content table:not(.table):not(.no-style) tbody tr:hover td{
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
}
