/* ============================================================
   Soma-Z — Design System
   Arquivo: assets/css/soma.css
   @see branding/Guia de Branding Soma-Z.md
   ============================================================ */

/* 1. Google Fonts — Montserrat (títulos) + Open Sans (corpo) */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600;700;800&family=Open+Sans:wght@400;500;600;700&display=swap');

/* ============================================================
   2. CSS Reset + Variáveis (Design Tokens)
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Paleta Soma-Z (oficial) */
  --soma-navy:       #1A2B4C;
  --soma-sage:       #77A68B;
  --soma-lavender:   #C8BFE7;

  /* Aliases legados → nova paleta */
  --soma-purple:     #77A68B;
  --soma-blue:       #1A2B4C;
  --soma-teal:       #77A68B;
  --soma-green:      #77A68B;
  --soma-yellow:     #C8BFE7;
  --soma-orange:     #FF8A30;
  --soma-red:        #EF4444;

  /* Neutros */
  --soma-bg:         #F0F0F0;
  --soma-surface:    #FFFFFF;
  --soma-border:     #DDE3E8;
  --soma-muted-bg:   #F8F8F8;
  --soma-text:       #1A2B4C;
  --soma-text-2:     #3D5166;
  --soma-text-3:     #6B7C8F;

  /* Sombras */
  --shadow-sm:       0 1px 3px rgba(26, 43, 76, .06);
  --shadow-md:       0 4px 16px rgba(26, 43, 76, .08);
  --shadow-lg:       0 8px 32px rgba(26, 43, 76, .12);
  --shadow-card:     0 2px 8px rgba(119, 166, 139, .12);

  /* Áreas ENEM */
  --area-linguagens:  #77A68B;
  --area-humanas:     #FF8A30;
  --area-natureza:    #00C4B4;
  --area-matematica:  #1A2B4C;
  --area-redacao:     #FFC857;

  /* Ligas */
  --liga-bronze:   #CD7F32;
  --liga-prata:    #A8A9AD;
  --liga-ouro:     #FFD700;
  --liga-diamante: #B9F2FF;
  --liga-lenda:    #FF6B35;

  /* Espaçamentos */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Raios */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  /* Tipografia Soma-Z */
  --font-display: 'Montserrat', 'Segoe UI', sans-serif;
  --font-sans: 'Open Sans', 'Segoe UI', sans-serif;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* Transições */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ============================================================
   3. Dark Mode
   ============================================================ */
[data-theme="dark"] {
  --soma-bg:      #1A2B4C;
  --soma-surface: #243656;
  --soma-border:  #3D5166;
  --soma-text:    #F0F0F0;
  --soma-text-2:  #C8BFE7;
  --soma-text-3:  #9AA8B8;
  --shadow-card:  0 2px 8px rgba(0, 0, 0, .3);
}

/* ============================================================
   4. Body e Tipografia Base
   ============================================================ */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--soma-bg);
  color: var(--soma-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   5. Layout Principal
   ============================================================ */
.app-layout {
  display: block;
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  width: 260px;
  background: var(--soma-surface);
  border-right: 1px solid var(--soma-border);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  padding: 0 0 24px;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-base);
}

.main-content {
  margin-left: 260px;
  width: calc(100% - 260px);
  padding: 24px;
  min-height: 100vh;
  box-sizing: border-box;
}

.topbar {
  position: fixed;
  top: 0;
  left: 260px;
  right: 0;
  height: 64px;
  background: var(--soma-surface);
  border-bottom: 1px solid var(--soma-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 99;
  box-shadow: var(--shadow-sm);
}

.btn-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--soma-text-2);
  font-size: 20px;
  padding: 6px;
  border-radius: var(--radius-sm);
  min-height: 44px;
  min-width: 44px;
  line-height: 1;
}

.topbar-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--soma-text);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.xp-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(119, 166, 139, .14);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--soma-purple);
  cursor: default;
}

.nivel-badge {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--soma-text-3);
}

.topbar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--soma-purple);
  display: block;
}

.content-wrapper {
  margin-top: 64px;
  padding: 0;
}

/* ============================================================
   6. Sidebar Interna
   ============================================================ */
.sidebar-logo {
  padding: 8px 0 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--soma-border);
}

.sidebar-logo .brand-logo--sidebar {
  width: 100%;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  line-height: 0;
}

.sidebar-logo .brand-logo--sidebar .brand-logo__main {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: 0;
  object-fit: contain;
  object-position: center center;
}

.sidebar-logo .brand-logo--sidebar .brand-logo__subtitle {
  margin: 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: .02em;
}

.sidebar-logo .logo-text {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--soma-purple);
}

.sidebar-nav {
  flex: 1;
  padding: 0 12px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  color: var(--soma-text-2);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--transition-fast);
  margin-bottom: 4px;
}

.sidebar-nav a:hover {
  background: var(--soma-muted-bg);
  color: var(--soma-purple);
}

.sidebar-nav a.active {
  background: rgba(119, 166, 139, .14);
  color: var(--soma-purple);
  font-weight: var(--weight-semibold);
}

.sidebar-nav a i {
  width: 20px;
  text-align: center;
  font-size: var(--text-base);
}

/* Links de primeiro nível e rodapé */
.sidebar-nav .sidebar-nav-top,
.sidebar-nav .sidebar-nav-footer a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  color: var(--soma-text-2);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--transition-fast);
  margin-bottom: 4px;
}

.sidebar-nav .sidebar-nav-top:hover,
.sidebar-nav .sidebar-nav-footer a:hover {
  background: var(--soma-muted-bg);
  color: var(--soma-purple);
}

.sidebar-nav .sidebar-nav-top.active,
.sidebar-nav .sidebar-nav-footer a.active {
  background: rgba(119, 166, 139, .14);
  color: var(--soma-purple);
  font-weight: var(--weight-semibold);
}

.sidebar-nav-footer {
  border-top: 1px solid var(--soma-border);
  margin: 12px 0 8px;
  padding-top: 8px;
}

/* Submenus agrupados */
.sidebar-nav-group {
  margin-bottom: 4px;
}

.sidebar-nav-group__summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--soma-text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-nav-group__summary::-webkit-details-marker {
  display: none;
}

.sidebar-nav-group__summary:hover {
  background: var(--soma-muted-bg);
  color: var(--soma-purple);
}

.sidebar-nav-group__summary.is-active {
  color: var(--soma-purple);
}

.sidebar-nav-group__summary i:first-child {
  width: 20px;
  text-align: center;
  font-size: var(--text-base);
}

.sidebar-nav-group__chevron {
  margin-left: auto;
  font-size: 10px;
  opacity: .55;
  transition: transform var(--transition-fast);
}

.sidebar-nav-group[open] .sidebar-nav-group__chevron {
  transform: rotate(180deg);
}

.sidebar-nav-sub {
  padding: 2px 0 6px 8px;
  margin-left: 20px;
  border-left: 2px solid var(--soma-border);
}

.sidebar-nav-sub__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--soma-text-3);
  text-decoration: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  transition: all var(--transition-fast);
  margin-bottom: 2px;
}

.sidebar-nav-sub__link:hover {
  background: var(--soma-muted-bg);
  color: var(--soma-purple);
}

.sidebar-nav-sub__link.active {
  background: rgba(119, 166, 139, .12);
  color: var(--soma-purple);
  font-weight: var(--weight-semibold);
}

.sidebar-nav-sub__link i {
  width: 16px;
  text-align: center;
  font-size: 12px;
}

/* ============================================================
   7. Bottom Navigation (mobile)
   ============================================================ */
.bottom-nav {
  display: none;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--soma-text-3);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: var(--weight-medium);
  transition: color var(--transition-fast);
}

.bottom-nav a.active {
  color: var(--soma-purple);
}

.bottom-nav a i {
  font-size: 20px;
}

/* ============================================================
   8. Cards
   ============================================================ */
.card {
  background: var(--soma-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  border: 1px solid var(--soma-border);
}

.card-sm {
  padding: 16px;
}

.card-lg {
  padding: 28px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--soma-text);
}

/* ============================================================
   9. Botões
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition-fast);
  min-height: 44px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--soma-purple);
  color: white;
}

.btn-primary:hover {
  background: #5F8F75;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(119, 166, 139, .35);
}

.btn-secondary {
  background: rgba(119, 166, 139, .12);
  color: var(--soma-navy);
}

.btn-secondary:hover {
  background: rgba(119, 166, 139, .2);
}

.btn-success {
  background: var(--soma-teal);
  color: white;
}

.btn-danger {
  background: var(--soma-red);
  color: white;
}

.btn-outline {
  background: transparent;
  color: var(--soma-purple);
  border: 2px solid var(--soma-purple);
}

.btn-outline:hover {
  background: var(--soma-purple);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--soma-text-2);
}

.btn-ghost:hover {
  background: var(--soma-muted-bg);
  color: var(--soma-text);
}

.btn-sm {
  padding: 8px 16px;
  min-height: 36px;
  font-size: var(--text-xs);
}

.btn-lg {
  padding: 16px 28px;
  min-height: 52px;
  font-size: var(--text-base);
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* ============================================================
   10. Formulários
   ============================================================ */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--soma-text);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--soma-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--soma-text);
  background: var(--soma-surface);
  transition: border-color var(--transition-fast);
  min-height: 44px;
}

.form-control:focus {
  outline: none;
  border-color: var(--soma-purple);
  box-shadow: 0 0 0 3px rgba(119, 166, 139, .12);
}

.form-control::placeholder {
  color: var(--soma-text-3);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--soma-red);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--soma-text-3);
  margin-top: 6px;
}

/* ============================================================
   11. Badges e Tags
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.badge-purple {
  background: rgba(119, 166, 139, .12);
  color: var(--soma-purple);
}

.badge-teal {
  background: rgba(0, 196, 180, .12);
  color: var(--soma-teal);
}

.badge-yellow {
  background: rgba(255, 200, 87, .2);
  color: #B45309;
}

.badge-red {
  background: rgba(239, 68, 68, .12);
  color: var(--soma-red);
}

.badge-green {
  background: rgba(124, 217, 87, .2);
  color: #15803D;
}

/* ============================================================
   12. Alertas
   ============================================================ */
.alert {
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-left: 4px solid;
}

.alert-error {
  background: rgba(239, 68, 68, .08);
  border-color: var(--soma-red);
  color: #991B1B;
}

.alert-success {
  background: rgba(0, 196, 180, .08);
  border-color: var(--soma-teal);
  color: #065F46;
}

.alert-warning {
  background: rgba(255, 200, 87, .15);
  border-color: var(--soma-yellow);
  color: #92400E;
}

.alert-info {
  background: rgba(45, 117, 255, .08);
  border-color: var(--soma-blue);
  color: #1E40AF;
}

/* ============================================================
   13. Avatar
   ============================================================ */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--soma-purple), var(--soma-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: var(--text-xs);
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-lg);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ============================================================
   14. XP Progress Bar
   ============================================================ */
.xp-bar-wrap {
  background: var(--soma-border);
  border-radius: var(--radius-full);
  height: 8px;
  overflow: hidden;
}

.xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--soma-purple), var(--soma-blue));
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

/* ============================================================
   15. Stat Cards (métricas)
   ============================================================ */
.stat-card {
  background: var(--soma-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  border: 1px solid var(--soma-border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--soma-text);
  line-height: 1;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--soma-text-3);
  margin-top: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

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

.stats-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-grid .stat-card {
  min-width: 0;
}

.stat-number {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--soma-text);
  line-height: 1;
}

@media (max-width: 767px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .stats-grid .stat-card {
    padding: 14px;
    gap: 12px;
  }

  .stats-grid .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .stats-grid .stat-number {
    font-size: var(--text-xl);
  }
}

/* ============================================================
   15b. Modals (admin / aluno)
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.modal-overlay.is-open {
  display: flex;
}

/* Admin: sidebar fixa 260px — modal centralizado na área útil */
@media (min-width: 769px) {
  .modal-overlay.modal-overlay--admin {
    left: 260px;
    width: calc(100% - 260px);
  }
}

body.modal-open {
  overflow: hidden;
}

.modal-box,
.modal-overlay > .modal {
  background: var(--soma-surface);
  color: var(--soma-text);
  border: 1px solid var(--soma-border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: min(calc(100vh - 32px), calc(100dvh - 32px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  position: relative;
  z-index: 10001;
  margin: auto;
  min-height: 0;
}

/* Formulário dentro do modal: repassa altura limitada ao corpo rolável */
.modal-box > form,
.modal-overlay > .modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.modal-box.modal--wide,
.modal-overlay > .modal.modal--wide {
  max-width: min(1240px, calc(100vw - 48px));
}

@media (min-width: 769px) {
  .modal-box.modal--wide,
  .modal-overlay.modal-overlay--admin > .modal.modal--wide {
    max-width: min(1240px, calc(100vw - 292px));
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--soma-border);
  flex-shrink: 0;
  background: var(--soma-surface);
}

.modal-header h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--soma-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--soma-border);
  border-radius: var(--radius-md);
  background: var(--soma-muted-bg);
  color: var(--soma-text);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.modal-close:hover {
  background: var(--soma-bg-2);
  color: var(--soma-text);
}

.modal-body {
  padding: 20px 22px 22px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  color: var(--soma-text);
  background: var(--soma-surface);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--soma-border);
  border-radius: 999px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--soma-text-3);
}

.modal-body .form-label {
  color: var(--soma-text);
  font-weight: var(--weight-medium);
}

.modal-body .form-control {
  background: var(--soma-surface);
  color: var(--soma-text);
  border-color: var(--soma-border);
}

.modal-body .form-group {
  margin-bottom: 16px;
}

.modal-body .form-group:last-child {
  margin-bottom: 0;
}

.modal-body textarea.form-control {
  min-height: 88px;
  max-height: 180px;
  resize: vertical;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--soma-border);
  flex-shrink: 0;
  background: var(--soma-surface);
}

.modal-footer .btn-group-ia {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-right: auto;
}

@media (max-width: 768px) {
  .modal-box {
    max-height: calc(100vh - 16px);
  }
  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Questões — LaTeX e ilustrações */
.soma-questao-editor-hint {
  background: var(--soma-bg-2, #f5f7fb);
  border: 1px dashed var(--soma-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .78rem;
  color: var(--soma-text-3);
  line-height: 1.55;
}
.soma-questao-editor-hint code {
  background: rgba(119, 166, 139, .08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .76rem;
}
.soma-questao-rich, .soma-questao-preview {
  line-height: 1.65;
  word-break: break-word;
}
.soma-questao-rich table.soma-questao-tabela,
.soma-questao-rich table,
.soma-questao-preview table.soma-questao-tabela,
.soma-questao-preview table {
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  margin: 12px 0;
  font-size: 14px;
}
.soma-questao-rich table th,
.soma-questao-rich table td,
.soma-questao-preview table th,
.soma-questao-preview table td {
  border: 1px solid var(--soma-border, #cbd5e1);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.soma-questao-rich table thead th,
.soma-questao-preview table thead th {
  background: var(--soma-muted-bg, #f1f5f9);
  font-weight: 600;
}
.soma-questao-fig, .soma-questao-fig img {
  max-width: 100%;
  height: auto;
}
.soma-questao-fig,
figure.soma-figura-centro {
  margin: 10px 0;
  text-align: center;
  display: block;
}
figure.soma-figura-centro img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}
.soma-questao-fig--compact img,
.soma-questao-compact .soma-questao-fig img,
.soma-questao-compact .soma-figura-enem img,
.soma-questao-compact img {
  max-width: min(100%, 300px);
  max-height: 200px;
  width: auto;
  object-fit: contain;
  border-radius: 6px;
}
.soma-questao-fig figcaption {
  font-size: .75rem;
  color: var(--soma-text-3);
  margin-top: 6px;
}
.soma-enem-cabecalho {
  font-size: .78rem;
  color: var(--soma-text-3);
  margin: 0 0 10px;
  padding: 6px 10px;
  background: var(--soma-muted-bg);
  border-radius: 6px;
  border-left: 3px solid var(--soma-purple);
  line-height: 1.45;
}
.soma-enem-cabecalho a {
  color: var(--soma-purple);
  font-weight: 600;
  text-decoration: none;
}
.soma-questao-compact .soma-questao-fig,
.soma-questao-compact .soma-figura-enem {
  text-align: left;
}
.soma-enem-alternativa {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  margin: 8px 0;
}
.soma-enem-alternativa > strong {
  flex-shrink: 0;
  min-width: 1.4em;
}
.soma-enem-alternativa .soma-questao-rich {
  flex: 1;
  text-align: left;
}
.soma-enem-alternativa .soma-questao-fig,
.soma-enem-alternativa .soma-figura-enem {
  text-align: left;
  margin: 4px 0;
}
.soma-figura-pendente {
  margin: 12px 0;
  text-align: center;
}
.soma-figura-pendente__inner {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 18px 22px;
  border: 2px dashed var(--soma-border);
  border-radius: 12px;
  background: var(--soma-muted-bg);
  color: var(--soma-text-2);
  font-size: .82rem;
  line-height: 1.45;
}
.soma-figura-pendente__icon {
  font-size: 1.5rem;
  line-height: 1;
}
.soma-figura-pendente__desc {
  color: var(--soma-text);
  font-weight: 500;
}
.soma-figura-pendente small {
  color: var(--soma-text-3);
  font-size: .72rem;
}
.soma-questao-fig-placeholder {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px dashed var(--soma-border);
  border-radius: 8px;
  background: var(--soma-muted-bg);
  font-size: .8rem;
  color: var(--soma-text-3);
}

/* ============================================================
   16. Auth (login / registro)
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--soma-navy) 0%, #243656 55%, var(--soma-sage) 100%);
  padding: 20px;
}

.auth-card {
  background: white;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  padding: 40px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .brand-logo__main {
  height: 48px;
  width: auto;
  max-width: 100%;
}

.auth-logo .logo-sub {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--soma-text-2);
  margin-top: 10px;
}

.auth-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--soma-text);
  margin-bottom: 8px;
}

.auth-sub {
  font-size: var(--text-sm);
  color: var(--soma-text-2);
  margin-bottom: 28px;
}

/* ============================================================
   17. Divisor e Utilitários
   ============================================================ */
.divider {
  border: none;
  border-top: 1px solid var(--soma-border);
  margin: 24px 0;
}

.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }

.text-muted   { color: var(--soma-text-3); }
.text-primary { color: var(--soma-purple); }

.d-flex        { display: flex; }
.align-center  { align-items: center; }
.justify-between { justify-content: space-between; }

.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mt-6 { margin-top: 24px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-6 { margin-bottom: 24px; }

/* ============================================================
   18. Loading Spinner
   ============================================================ */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--soma-border);
  border-top-color: var(--soma-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ============================================================
   19. Overlay para Sidebar Mobile
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 99;
}

/* ============================================================
   21. Grid
   ============================================================ */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================================
   20. Responsividade
   ============================================================ */
@media (max-width: 768px) {
  /* Sidebar */
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Overlay sidebar */
  .sidebar-overlay.active {
    display: block;
  }

  /* Layout */
  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 16px;
    padding-bottom: 80px;
    overflow-x: hidden;
  }

  .topbar {
    left: 0;
    height: 56px;
    padding: 0 16px;
  }

  .btn-hamburger { display: flex; }
  .nivel-badge   { display: none; }

  .content-wrapper {
    margin-top: 56px;
  }

  /* Bottom Nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--soma-surface);
    border-top: 1px solid var(--soma-border);
    z-index: 100;
    box-shadow: 0 -4px 16px rgba(15, 27, 61, .06);
  }

  /* Auth card */
  .auth-card {
    padding: 28px;
  }

  /* Grid adaptações */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stats-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

  /* Ocultar elementos desktop */
  .hide-mobile { display: none; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none; }
  .bottom-nav   { display: none; }
}

/* ============================================================
   Brand — Logotipo Soma-Z
   ============================================================ */
.brand-logo {
  gap: 10px;
  align-items: center;
}
.brand-logo__icon {
  border-radius: var(--radius-sm);
  object-fit: contain;
  flex-shrink: 0;
}
.brand-logo__main {
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.brand-logo--sidebar {
  display: flex;
  width: 100%;
}
.brand-logo--sidebar .brand-logo__main {
  width: 100%;
  height: auto;
  object-fit: contain;
}
.brand-logo--sidebar .brand-logo__icon { width: 32px; height: 32px; }
.brand-logo--navbar .brand-logo__main { height: 36px; }
.brand-logo--auth { flex-direction: column; gap: 0; }
.brand-logo--auth .brand-logo__main { height: 48px; }
.brand-logo__subtitle {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--soma-text-3);
  line-height: 1.2;
  margin-left: 4px;
}

h1, h2, h3, h4, h5, h6,
.topbar-title,
.auth-title,
.sidebar-logo .logo-text {
  font-family: var(--font-display);
}
