:root {
  --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* Identificadores (C.I., matrícula, código de turma) em monoespaçada: separa
     0 de O e 1 de l. O produto existe para evitar erro de transcrição — conferir
     um C.I. em fonte proporcional é justamente onde o erro nasce. */
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --primary: #2563eb;
  --primary-700: #1d4ed8;
  --accent: #059669;
  --accent-700: #047857;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --success-bg: #ecfdf5;
  --info-bg: #eff6ff;
  --radius: 10px;
  --radius-sm: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --ring: 0 0 0 3px rgba(37, 99, 235, .22);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--primary-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 12px;
  font-family: var(--font-mono); }

/* Identificador: C.I., matrícula, código de turma. Monoespaçado e levemente
   espaçado, para conferência caractere a caractere. */
.cod { font-family: var(--font-mono); font-size: .92em; letter-spacing: .01em;
  font-variant-numeric: tabular-nums; }
/* Valor numérico comparado entre linhas (nota, contagem). */
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }

/* App shell */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: 0 0 220px; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px; }
.sidebar .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 14px;
  color: var(--text); padding: 4px 8px 16px; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand .mark { width: 26px; height: 26px; border-radius: 8px; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
/* Filete de acento à esquerda: o item ativo se localiza de relance, sem depender
   só da diferença de tom do fundo. */
.sidebar nav a.active { background: var(--info-bg); color: var(--primary-700);
  box-shadow: inset 2px 0 0 var(--primary); font-weight: 600; }
.sidebar nav a svg { width: 18px; height: 18px; flex: 0 0 auto; }
.sidebar .foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px;
  display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); }
.sidebar .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--info-bg); color: var(--primary-700);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; flex: 0 0 auto; }
.sidebar .foot form { margin: 0; }
.sidebar .logout { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.sidebar .logout:hover { color: var(--text); }

.content { flex: 1; min-width: 0; padding: 28px 32px; }
.content-inner { max-width: 980px; margin: 0 auto; }

/* Public (login) */
.public { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; }
.public-inner { width: 100%; max-width: 400px; margin: 12vh 20px; }

/* Headings */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-sub { color: var(--muted); font-size: 14px; margin: 2px 0 0; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 22px; }
.card + .card { margin-top: 16px; }

/* Forms */
.field { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input, select, textarea { width: 100%; padding: 9px 12px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input::placeholder { color: var(--muted-2); }
input[type=file] { padding: 7px 10px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-size: 14px;
  font-weight: 600; padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; text-decoration: none; line-height: 1.2; }
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-700); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-700); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; line-height: 1.5; white-space: nowrap; }
.badge svg { width: 13px; height: 13px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--accent-700); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

/* Table */
/* A tabela é o objeto central do sistema: números alinham na vertical para a
   conferência de uma turma inteira ser feita de olho, sem ler linha a linha. */
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
/* Cabeçalho acompanha a rolagem em listas longas (turma inteira). */
thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); }
th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 12px; border-bottom: 1px solid var(--border); }
/* Linha um pouco mais compacta: em trabalho por turma, cada aluno a mais
   visível na tela é uma rolagem a menos na conferência. */
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

/* Alerts */
.alert { font-size: 14px; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 18px; border: 1px solid; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-info { background: var(--info-bg); border-color: var(--primary); color: var(--primary-700); }

/* Search */
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 0 10px; background: var(--surface); }
.search svg { width: 16px; height: 16px; color: var(--muted-2); flex: 0 0 auto; }
.search input { border: 0; padding: 9px 0; box-shadow: none; }
.search input:focus { box-shadow: none; }
.select-turma { width: auto; min-width: 170px; }
.col-check { width: 40px; text-align: center; padding-left: 12px; padding-right: 0; }
.col-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.barra-lote { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(12px);
  z-index: 60; display: none; align-items: center; gap: 12px; background: var(--text); color: #fff;
  padding: 9px 10px 9px 18px; border-radius: 999px; box-shadow: 0 12px 34px rgba(2,12,27,.28);
  opacity: 0; transition: opacity .16s ease, transform .28s cubic-bezier(.16, 1, .3, 1); }
.barra-lote.open { display: flex; opacity: 1; transform: translateX(-50%) translateY(0); }
.barra-lote #lote-count { font-size: 14px; font-weight: 600; white-space: nowrap; }
.barra-lote .lote-x { background: transparent; border: 0; color: rgba(255,255,255,.7);
  font-size: 15px; cursor: pointer; padding: 4px 6px; line-height: 1; }
.barra-lote .lote-x:hover { color: #fff; }

/* ---------- Painel (gráficos) ---------- */
/* Paleta validada p/ daltonismo e contraste (azul = período A, âmbar = período B) */
:root { --chart-a: #2563eb; --chart-b: #b45309; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 22px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi-card .rot { font-size: 12.5px; color: var(--muted); }
.kpi-card .val { font-size: 27px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.kpi-card .cmp { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.kpi-card .up { color: var(--accent-700); font-weight: 700; }
.kpi-card .down { color: var(--danger); font-weight: 700; }
.legenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.legenda span { display: inline-flex; align-items: center; gap: 7px; }
.legenda i { width: 16px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.bar-row .lbl { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .num { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-trilho { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--chart-a); border-radius: 4px; }
.resumo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.resumo-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow-sm); }
.resumo-card.destaque { background: var(--info-bg); border-color: var(--primary); }
.resumo-card .rc-n { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.resumo-card.destaque .rc-n { color: var(--primary-700); }
.resumo-card .rc-l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.atalhos { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.atalhos .chip { text-decoration: none; }
.atalhos .chip.ativo { background: var(--primary); color: #fff; border-color: var(--primary); }
@media (max-width: 760px) { .resumo-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Tema escuro ---------- */
[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-700: #7cb0ff;
  --accent: #10b981;
  --accent-700: #34d399;
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #1d2942;
  --text: #e6edf8;
  --muted: #93a4bd;
  --muted-2: #6b7d99;
  --border: #263248;
  --border-strong: #38455f;
  --danger: #f87171;
  --danger-bg: #2b1620;
  --warning: #fbbf24;
  --warning-bg: #2a2210;
  --success-bg: #10251d;
  --info-bg: #16243f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --ring: 0 0 0 3px rgba(59, 130, 246, .35);
  --chart-a: #3b82f6;
  --chart-b: #c2871a;
}
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
[data-theme="dark"] .sidebar .brand .mark { color: #fff; }
[data-theme="dark"] .barra-lote { background: var(--surface-2); border: 1px solid var(--border-strong); }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* Botão de alternância de tema */
.tema-toggle { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px;
  border-radius: 8px; display: inline-flex; align-items: center; line-height: 0; }
.tema-toggle:hover { background: var(--surface-2); color: var(--text); }
.tema-toggle svg { width: 17px; height: 17px; }
.tema-toggle .ico-sol { display: none; }
[data-theme="dark"] .tema-toggle .ico-sol { display: inline; }
[data-theme="dark"] .tema-toggle .ico-lua { display: none; }

/* ---------- Barra de progresso (htmx) ---------- */
#topbar { position: fixed; top: 0; left: 0; height: 3px; width: 100%; background: var(--primary);
  transform: scaleX(0); transform-origin: left;
  z-index: 100; opacity: 0; transition: transform .2s ease, opacity .35s ease; box-shadow: 0 0 8px var(--primary); }

/* ---------- Skeleton de carregamento ---------- */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel-linha { height: 12px; margin: 10px 0; }

/* ---------- Refinos ---------- */
.sidebar nav a, .btn, .chip, .tema-toggle { transition: background .14s ease, color .14s ease, border-color .14s ease; }
.tabela-alunos tbody tr { transition: background .12s ease; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:focus-visible, a:focus-visible { outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* ---------- Página inicial ---------- */
/* Cabeçalho da página inicial. Superfície plana, como qualquer outra do sistema:
   a hierarquia vem do tamanho do título e do sobrescrito em acento, não de um
   ornamento. O degradê anterior era a única peça fora do tema (cores fixas, sem
   variante escura); filete de acento lateral também não — é ornamento por ornamento. */
.home-hero { background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 30px; margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  display: flex; justify-content: space-between; align-items: center; gap: 22px; flex-wrap: wrap; }
.home-hero .hh-brand { display: inline-flex; align-items: center; gap: 8px; font-size: 11px;
  font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary-700); margin-bottom: 10px; }
.home-hero .hh-brand svg { width: 15px; height: 15px; }
.home-hero h1 { font-size: 26px; font-weight: 800; margin: 0 0 7px; letter-spacing: -.025em; line-height: 1.15; }
.home-hero p { margin: 0; color: var(--muted); font-size: 14px; max-width: 58ch; }
.home-hero .hh-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-white { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-white:hover { background: var(--primary-700); border-color: var(--primary-700); }
.btn-ghost-light { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-ghost-light:hover { background: var(--surface-2); }
.grid-2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; align-items: start; }
/* Duas colunas: seis atalhos empilhados faziam esta coluna ter o dobro da altura
   da vizinha, desequilibrando a página inteira. */
.quick-list { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
@media (max-width: 1100px) { .quick-list { grid-template-columns: 1fr; } }
.quick-list a { display: flex; align-items: center; gap: 12px; padding: 12px 12px; border-radius: 10px;
  color: var(--text); font-weight: 500; font-size: 14px; border: 1px solid transparent; }
.quick-list a:hover { background: var(--surface-2); text-decoration: none; }
.quick-list a .qi { width: 34px; height: 34px; border-radius: 9px; background: var(--info-bg); color: var(--primary-700);
  display: grid; place-items: center; flex: 0 0 auto; }
.quick-list a svg { width: 17px; height: 17px; }
.quick-list a .chev { margin-left: auto; color: var(--muted-2); }
.legal { margin-top: 24px; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 12.5px; line-height: 1.65; }
.legal strong { color: var(--text); }
.legal .legal-links { margin-top: 7px; }
.legal .legal-links a { font-weight: 600; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* Turma section (collapsible) */
.turma { margin-bottom: 22px; }
.turma > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 6px 0; user-select: none; }
.turma > summary::-webkit-details-marker { display: none; }
.turma > summary .chev { transition: transform .15s; color: var(--muted); display: inline-flex; }
.turma[open] > summary .chev { transform: rotate(90deg); }
.turma .t-curso { font-size: 16px; font-weight: 600; }

/* Aluno card (collapsible) */
.aluno { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md, 10px);
  box-shadow: var(--shadow-sm); margin-bottom: 8px; overflow: hidden; }
.aluno > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; user-select: none; }
.aluno > summary::-webkit-details-marker { display: none; }
.aluno > summary .nome { font-weight: 600; font-size: 14px; }
.aluno > summary .ci { color: var(--muted); font-size: 12px; }
.aluno > summary .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.aluno > summary .chev { color: var(--muted-2); transition: transform .15s; display: inline-flex; }
.aluno[open] > summary .chev { transform: rotate(90deg); }
.aluno .body { padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.subform { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-top: 12px; }
.subform .field { margin: 0; flex: 1; min-width: 120px; }
.docs { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.doc-title { font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.dl { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--accent-700); }
.dl svg { width: 13px; height: 13px; }

/* Saved flash */
.flash { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  color: var(--accent-700); background: var(--success-bg); padding: 4px 10px; border-radius: 999px;
  animation: fade 2.6s ease forwards; }
.flash svg { width: 13px; height: 13px; }
@keyframes fade { 0%,70% { opacity: 1; } 100% { opacity: 0; } }

/* htmx in-flight */
.htmx-request .btn { opacity: .6; pointer-events: none; }

.muted { color: var(--muted); }
.between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
/* Tabelas roláveis horizontalmente em telas estreitas */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x table { min-width: 520px; }

/* Foco visível (acessibilidade) */
a:focus-visible, summary:focus-visible, button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px;
}

footer { margin: 24px 0 0; font-size: 12px; color: var(--muted-2); }
footer a { color: var(--muted); }

/* Onboarding (comece aqui) */
.onboarding { list-style: none; padding: 0; margin: 14px 0 0; }
.onboarding li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-top: 1px solid var(--border); }
.onboarding li:first-child { border-top: 0; }
.onboarding .num { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2);
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex: 0 0 auto; }
.onboarding li.done .num { background: var(--success-bg); color: var(--accent-700); }
.onboarding li.done strong { color: var(--muted); }
.onboarding .num svg { width: 15px; height: 15px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column;
  gap: 8px; z-index: 1000; }
.toast { background: var(--text); color: #fff; padding: 11px 15px; border-radius: 10px; font-size: 14px;
  font-weight: 500; box-shadow: 0 6px 18px rgba(15, 23, 42, .22); display: flex; align-items: center; gap: 8px;
  max-width: 340px; opacity: 1; transform: translateY(0); transition: opacity .3s, transform .3s; }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #34d399; flex: 0 0 auto; }
.toast.out { opacity: 0; transform: translateY(10px); }

/* Seções do menu lateral */
.sidebar .nav-sec { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted-2); font-weight: 600; padding: 12px 11px 4px; }
.sidebar nav .nav-sec:first-child { padding-top: 2px; }

/* Cartões de número (KPIs) */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 16px 18px; }
.kpi .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi .label svg { width: 16px; height: 16px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1; }
.quick { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* Filtros (chips) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 500; cursor: pointer;
  background: var(--surface-2); color: var(--muted); border: 1px solid transparent; }
.chip:hover { color: var(--text); }
/* Neutro invertido: escuro no tema claro, claro no escuro. Usar #fff fixo
   deixava a pílula branca sobre texto branco no tema escuro. */
.chip.ativo { background: var(--text); color: var(--surface); }

/* Tabela de alunos clicável */
.tabela-alunos tbody tr { cursor: pointer; }
.tabela-alunos td { padding: 11px 14px; }

/* Drawer (painel de detalhe) */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.35); opacity: 0; visibility: hidden;
  transition: opacity .2s; z-index: 900; }
.overlay.open { opacity: 1; visibility: visible; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 470px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 30px rgba(15,23,42,.14);
  transform: translateX(100%); transition: transform .22s ease; z-index: 950; }
.drawer.open { transform: translateX(0); }
.drawer-body { height: 100vh; overflow-y: auto; padding: 18px 20px; }
.drawer .close { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px; line-height: 0; }
.drawer .close svg { width: 20px; height: 20px; }
.drawer .close:hover { color: var(--text); }

/* Abas no detalhe */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 16px 0 0; }
.tab { padding: 9px 13px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer;
  border: 0; background: none; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.ativo { color: var(--primary-700); border-bottom-color: var(--primary); }
.aba-panel { display: none; padding-top: 16px; }
.aba-panel.ativo { display: block; }

@media (max-width: 760px) {
  .sidebar .nav-sec { display: none; }
  .drawer { width: 100%; }
  .app { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; flex-direction: row; align-items: center;
    gap: 6px; padding: 8px 12px; overflow-x: auto; }
  .sidebar .brand { padding: 4px 8px; white-space: nowrap; }
  .sidebar nav { flex-direction: row; }
  .sidebar .foot { margin-top: 0; margin-left: auto; border: 0; padding-top: 0; white-space: nowrap; }
  .content { padding: 18px 16px; }
  .aluno > summary { flex-wrap: wrap; row-gap: 6px; }
  .aluno > summary .right { margin-left: 0; }
  .turma > summary { flex-wrap: wrap; }
  .page-head { align-items: stretch; }
  .search { width: 100%; }
}

/* ---------- Estado vazio ---------- */
/* Tela vazia deve ensinar o próximo passo, não só informar a ausência: é onde
   a secretaria trava sem ter a quem perguntar. */
.vazio { text-align: center; padding: 40px 24px; }
.vazio .vi { width: 42px; height: 42px; border-radius: 12px; margin: 0 auto 14px;
  background: var(--surface-2); color: var(--muted); display: grid; place-items: center; }
.vazio .vi svg { width: 21px; height: 21px; }
.vazio h3 { margin: 0 0 5px; font-size: 15px; font-weight: 600; }
.vazio p { margin: 0 auto 16px; color: var(--muted); font-size: 13.5px; max-width: 46ch; line-height: 1.55; }
.vazio .va { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Trilha de documentos (lista de alunos) ---------- */
/* Mostra quais documentos existem e quais faltam, sem abrir a ficha. */
.docs-trilha { display: inline-flex; gap: 4px; align-items: center; }
.docs-trilha .dt { width: 22px; height: 20px; border-radius: 5px; font-size: 9.5px; font-weight: 700;
  display: grid; place-items: center; letter-spacing: .02em; font-family: var(--font-mono);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted-2); }
.docs-trilha .dt.ok { background: var(--success-bg); border-color: transparent; color: var(--accent-700); }
.docs-trilha .resto { font-size: 11px; color: var(--muted); margin-left: 2px; }

/* ---------- Estados de carregamento ---------- */
/* Toda ação que fala com o servidor precisa dizer que está trabalhando. Gerar
   documentos de uma turma leva segundos: sem sinal, a tela parece travada e a
   pessoa clica de novo, disparando a operação duas vezes. */
.btn[disabled], .btn.htmx-request { pointer-events: none; }
.btn.htmx-request { position: relative; color: transparent !important; }
.btn.htmx-request svg { visibility: hidden; }
.btn.htmx-request::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: #fff; animation: girar .6s linear infinite;
}
/* Variantes claras giram na cor do próprio texto, não em branco. */
.btn-secondary.htmx-request::after, .btn-ghost.htmx-request::after { color: var(--text); }
.btn-danger.htmx-request::after { color: var(--danger); }
@keyframes girar { to { transform: rotate(360deg); } }

/* Linha da tabela enquanto o detalhe do aluno carrega. */
tbody tr.htmx-request { background: var(--surface-2); opacity: .65; }

/* ---------- Movimento ---------- */
/* Entrada suave do conteúdo: tira o "estalo" do carregamento sem atrasar nada.
   O escalonamento para na 12ª linha — além disso vira espera, não elegância. */
@keyframes surgir { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card, .kpi-card, .resumo-card { animation: surgir .22s ease both; }
.tabela-alunos tbody tr { animation: surgir .18s ease both; }
.tabela-alunos tbody tr:nth-child(1) { animation-delay: .01s }
.tabela-alunos tbody tr:nth-child(2) { animation-delay: .02s }
.tabela-alunos tbody tr:nth-child(3) { animation-delay: .03s }
.tabela-alunos tbody tr:nth-child(4) { animation-delay: .04s }
.tabela-alunos tbody tr:nth-child(5) { animation-delay: .05s }
.tabela-alunos tbody tr:nth-child(6) { animation-delay: .06s }
.tabela-alunos tbody tr:nth-child(7) { animation-delay: .07s }
.tabela-alunos tbody tr:nth-child(8) { animation-delay: .08s }
.tabela-alunos tbody tr:nth-child(9) { animation-delay: .09s }
.tabela-alunos tbody tr:nth-child(10) { animation-delay: .10s }
.tabela-alunos tbody tr:nth-child(11) { animation-delay: .11s }
.tabela-alunos tbody tr:nth-child(n+12) { animation-delay: .12s }

/* Confirmação visual de qual linha acabou de ser gerada. */
@keyframes pulso-ok { 0% { background: var(--success-bg); } 100% { background: transparent; } }
.tabela-alunos tbody tr.pulso { animation: pulso-ok 1.6s ease forwards; }

/* Contagem dos KPIs: o dígito sobe enquanto conta. */
.kpi-card .val, .resumo-card .rc-n { font-variant-numeric: tabular-nums; }

/* ---------- Diálogo de confirmação ---------- */
/* O confirm() nativo é cinza, sem contexto e não diz o que será apagado.
   Em sistema de documento oficial, exclusão precisa mostrar o estrago antes. */
/* Visível por padrão: a animação só suaviza a entrada. Se o elemento nascesse
   com opacity:0 dependendo da animação para aparecer, qualquer ambiente que não
   execute animações teria um modal invisível bloqueando a tela. */
.dlg-fundo { position: fixed; inset: 0; background: rgba(2, 12, 27, .5); z-index: 980;
  display: grid; place-items: center; padding: 20px; opacity: 1; animation: surgir .14s ease; }
.dlg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(2, 12, 27, .3); width: 100%; max-width: 420px; padding: 22px; }
.dlg h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.dlg p { margin: 0 0 8px; font-size: 14px; color: var(--muted); line-height: 1.55; }
.dlg .dlg-itens { margin: 0 0 16px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-bg); border: 1px solid #fecaca; font-size: 13px; color: var(--danger); }
[data-theme="dark"] .dlg .dlg-itens { border-color: #7f1d1d; }
.dlg .dlg-itens strong { font-family: var(--font-mono); font-weight: 600; }
.dlg .dlg-acoes { display: flex; gap: 8px; justify-content: flex-end; }
.btn-danger-solido { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger-solido:hover { background: #b91c1c; border-color: #b91c1c; }

/* ---------- Duplas de atendimento ---------- */
.esp-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin: 0; }
.quadro { display: flex; flex-direction: column; gap: 14px; }
.quadro-barra { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.qb-contas { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.qb-contas strong { color: var(--text); }
.qb-acoes { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.q-titulo { margin: 0; font-size: 15px; font-weight: 600; }

/* Aluno como peça móvel: retângulo (é ação — arrastar), nunca pílula. */
.chip-aluno { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px;
  font: inherit; text-align: left; cursor: grab; padding: 7px 10px; min-width: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .14s ease, background .14s ease, opacity .14s ease; }
.chip-aluno:hover { border-color: var(--primary); }
.chip-aluno:active { cursor: grabbing; }
.chip-aluno .ca-nome { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.chip-aluno .ca-id { font-size: 11.5px; color: var(--muted); }
.chip-aluno.arrastando { opacity: .4; }
.chip-aluno.selecionado { border-color: var(--primary); background: var(--info-bg); box-shadow: var(--ring); }
.modo-mover [data-dupla], .modo-mover [data-livre] { cursor: copy; }
.alvo { outline: 2px dashed var(--primary); outline-offset: 2px; }

.livres-lista { display: flex; flex-wrap: wrap; gap: 8px; }
.livre-item { display: inline-flex; align-items: center; gap: 6px; }
.livre-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }

.duplas-grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.dupla-cartao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 14px; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.dupla-cartao.estado-pendente { border-color: var(--warning); }
.dc-topo { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dc-codigo { font-weight: 600; font-size: 13px; }
.dc-nome { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.dc-membros { display: flex; flex-direction: column; gap: 6px; }
.dc-membros .chip-aluno { width: 100%; }
.dc-aviso { margin: 0; font-size: 12.5px; color: var(--warning); }
.dc-rodape { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dc-sala { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; margin: 0; }
.dc-sala input { width: 70px; padding: 5px 8px; font-size: 13px; font-family: var(--font-mono); }
.dc-erro { margin: 0; font-size: 12.5px; color: var(--danger); background: var(--danger-bg);
  border-radius: var(--radius-sm); padding: 6px 8px; }
.dc-hist summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.dc-hist ol { margin: 6px 0 0; padding-left: 18px; font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.dc-erro-inline { display: block; color: var(--danger); }
@media (max-width: 640px) { .duplas-grade { grid-template-columns: 1fr; } }

/* Página de erro (formulário recusado, página não encontrada) */
.erro-pagina { max-width: 560px; margin: 48px auto; display: flex; flex-direction: column; gap: 10px; }
.erro-codigo { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--danger); }
.erro-acoes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* Dados do profissional no HiPro, dentro do cartão da dupla */
.dc-hipro { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.dc-hipro-titulo { margin: 0; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.dc-hipro dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 12.5px; }
.dc-hipro dt { color: var(--muted); }
.dc-hipro dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.dc-dados { margin-top: 6px !important; max-height: 220px; overflow: auto; }

/* Bloqueios do HiPro (consultas a remanejar) no quadro de duplas */
.bloqueios p { margin: 4px 0 8px; }
.bloqueios ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.bloqueios li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
