:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e9f2;
  --text: #1c2333;
  --text-muted: #6b7386;
  --primary: #5b8def;
  --primary-dark: #3f6fd6;
  --pendente: #f2994a;
  --andamento: #5b8def;
  --concluida: #27ae60;
  --danger: #eb5757;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 1px 2px rgba(20, 30, 60, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131c;
    --surface: #181c29;
    --border: #262c3d;
    --text: #eef1f8;
    --text-muted: #8891a7;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #10131c;
  --surface: #181c29;
  --border: #262c3d;
  --text: #eef1f8;
  --text-muted: #8891a7;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e9f2;
  --text: #1c2333;
  --text-muted: #6b7386;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 1px 2px rgba(20, 30, 60, 0.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.theme-toggle {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
.theme-toggle:hover { background: var(--bg); }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 320px; max-width: 90vw; box-shadow: var(--shadow);
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box p { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.login-box label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; font-weight: 600; }
.login-box input {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
.login-box .btn-primary { width: 100%; margin-top: 18px; }
.login-erro { color: var(--danger); font-size: 12px; margin-top: 10px; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-header h1 { font-size: 20px; margin: 0 0 8px; }
.turmas-list { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.turma-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-muted); font-weight: 500; font-size: 14px;
}
.turma-item:hover { background: var(--bg); }
.turma-item.active { background: var(--primary); color: white; }
.turma-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; cursor: pointer; }
.turma-item-info { flex: 1; cursor: pointer; }
.turma-item-sub { font-size: 11px; opacity: 0.75; font-weight: 400; }
.turma-edit-btn {
  background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6;
  font-size: 13px; padding: 2px 4px; border-radius: 6px; flex-shrink: 0;
}
.turma-edit-btn:hover { opacity: 1; background: rgba(255,255,255,0.15); }

/* MAIN */
.main { padding: 24px 32px; overflow-y: auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.topbar-title h2 { margin: 0; font-size: 26px; }
.turma-sub { color: var(--text-muted); font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.view-toggle { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-btn { border: none; background: transparent; padding: 8px 14px; font-size: 13px; cursor: pointer; color: var(--text-muted); }
.view-btn.active { background: var(--primary); color: white; }

.btn-primary, .btn-ghost, .btn-danger {
  border: none; border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

/* STATS */
.stats { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; min-width: 140px; box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 22px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-andamento { background: var(--andamento); }
.dot-concluida { background: var(--concluida); }
.task-obs { margin-top: 6px; font-size: 11px; color: var(--pendente); }

/* TIMELINE */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; gap: 12px;
}
.timeline-item:hover { border-color: var(--primary); }
.timeline-left { display: flex; align-items: center; gap: 12px; }
.status-pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; color: white; white-space: nowrap; }
.status-pill.andamento { background: var(--andamento); }
.status-pill.concluida { background: var(--concluida); }
.status-pill.falta { background: var(--danger); }
.timeline-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.timeline-presencas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.presenca-tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.presenca-tag.ok { color: var(--concluida); background: color-mix(in srgb, var(--concluida) 15%, transparent); }
.presenca-tag.falta { color: var(--danger); background: color-mix(in srgb, var(--danger) 15%, transparent); }

/* ALUNOS */
.alunos-grid { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.aluno-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); width: 220px;
}
.aluno-card-wide { width: 280px; }
.progresso-turma-card { width: 100%; }
.aluno-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.aluno-card-head > div:nth-child(2) { flex: 1; min-width: 0; }
.aluno-edit-btn {
  background: none; border: 1px solid var(--border); cursor: pointer; color: var(--text-muted);
  font-size: 12px; padding: 4px 6px; border-radius: 6px; flex-shrink: 0;
}
.aluno-edit-btn:hover { color: var(--text); background: var(--bg); }
.aluno-card-click { cursor: pointer; }
.aluno-card-click:hover { border-color: var(--primary); }
.aluno-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; flex-shrink: 0;
}
.aluno-nome { font-weight: 600; margin-bottom: 2px; }
.aluno-sub { font-size: 12px; color: var(--text-muted); }
.aluno-atual { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.aluno-atual-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.aluno-atual-conteudo { font-size: 14px; margin-bottom: 8px; }

.empty-state { text-align: center; color: var(--text-muted); margin-top: 80px; font-size: 15px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 25, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 24px; width: 420px; max-width: 90vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-sm { width: 340px; }
.modal h3 { margin: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.btn-close {
  background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer;
  color: var(--text-muted); padding: 2px 6px; border-radius: 6px;
}
.btn-close:hover { background: var(--bg); color: var(--text); }
.modal label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; font-weight: 600; }

.presencas-list { display: flex; flex-direction: column; gap: 8px; }
.presenca-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.presenca-chip {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 13px; cursor: pointer; user-select: none; background: var(--bg); flex-shrink: 0;
}
.presenca-chip input { width: auto; margin: 0; }
.presenca-chip.presente { border-color: var(--concluida); background: color-mix(in srgb, var(--concluida) 15%, var(--bg)); }
.presenca-row .fMotivoAluno { flex: 1; min-width: 160px; padding: 7px 10px; font-size: 13px; }

.historico-aluno-lista { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; }
.historico-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px;
}
.historico-item-data { color: var(--text-muted); white-space: nowrap; }
.historico-motivo { margin-left: 8px; font-size: 12px; color: var(--text-muted); }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-inline { display: flex; gap: 8px; }
.form-row-inline input { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; align-items: center; }
.spacer { flex: 1; }

.alunos-nomes-inputs { display: flex; flex-direction: column; gap: 8px; }
.alunos-nomes-inputs input { width: 100%; }

.livros-lista { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; max-height: 200px; overflow-y: auto; }
.livro-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.livro-item button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; }
}
