:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #e3e5e9;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
}

.hidden { display: none !important; }

/* ---------------- LOGIN ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 20px;
}

.login-card {
  background: var(--color-surface);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
}

.login-logo {
  display: block;
  width: 88px;
  height: auto;
  margin: 0 auto 14px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  text-align: center;
  line-height: 1.3;
}

.subtitle {
  color: var(--color-text-muted);
  margin: 0 0 24px;
  font-size: 14px;
  text-align: center;
}

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
}

.login-card button[type=submit] {
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button[type=submit]:hover { background: var(--color-primary-dark); }
.login-card button[type=submit]:disabled { opacity: 0.6; cursor: default; }

.login-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.error-text {
  color: var(--color-danger);
  font-size: 13px;
  min-height: 16px;
  margin: 8px 0 0;
}

/* ---------------- APP SHELL ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #16192a;
  color: #d8dae2;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
  width: 34px;
  height: auto;
  flex-shrink: 0;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  color: #b7b9c8;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--color-primary); color: #fff; }

.sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
}

.realtime-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9ae6b4;
  margin-bottom: 10px;
}

.realtime-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34,197,94,0.6);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #9498a8;
  word-break: break-all;
}

.link-btn {
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  padding: 0;
  text-align: left;
  font-size: 12px;
}

/* "Trocar senha" não é uma ação destrutiva como "Sair" — usa uma cor
   neutra (clara, sobre o fundo escuro da barra lateral) em vez do
   vermelho padrão do .link-btn. */
.link-btn.neutral {
  color: #cbd5e1;
}
.link-btn.neutral:hover {
  color: #fff;
}

.content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
}

/* ---------------- SHARED VIEW STYLES ---------------- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.view-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.view-header .view-desc {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 0;
}

.btn {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--color-primary-dark); }
.btn.secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.btn.secondary:hover { background: #f0f0f2; }
.btn.danger { background: var(--color-danger); }
.btn.warning { background: #FFAE42; color: #3a2400; }
.btn.warning:hover { background: #f0a02f; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.toolbar input[type=search],
.toolbar select,
.toolbar input[type=date] {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--color-surface);
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  background: #fafafa;
  color: var(--color-text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge.green { background: #dcfce7; color: #15803d; }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.orange { background: #ffedd5; color: #c2410c; }
.badge.gray { background: #f1f1f4; color: #52525b; }

.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  padding: 40px 0;
  font-size: 14px;
}

.actions-cell {
  display: flex;
  gap: 6px;
}

/* ---------------- MODAL / FORM ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,17,26,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: var(--shadow-md);
}

.modal h3 { margin-top: 0; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}

.form-grid .full { grid-column: 1 / -1; }

/* Lista de sugestões do campo de busca de aluno (ex: em "Usuários e
   Perfis" → "Qual aluno é este usuário?") — um combobox simples: campo
   de texto + lista filtrada abaixo, em vez de uma <select> comum (que
   fica pesada/lenta com milhares de opções e não filtra por digitação). */
.autocomplete-lista {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e3e5e9;
  border-radius: 8px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}
.autocomplete-lista .item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.autocomplete-lista .item:hover { background: #f3f4f6; }

.form-grid label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--color-text-muted);
}

/* Campos de 1ª/2ª Nota (Frequência/Notas): tira as setinhas de
   incremento do input number — em colunas estreitas elas espremiam o
   número digitado, deixando o conteúdo escondido/cortado. */
.nota-input {
  -moz-appearance: textfield;
}
.nota-input::-webkit-outer-spin-button,
.nota-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------------- TOASTS ---------------- */
.toast-container {
  position: fixed;
  top: 18px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #1f2430;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slide-in 0.2s ease-out;
  max-width: 320px;
}

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------------- STATS / RELATÓRIOS ---------------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
}

.stat-card .stat-label {
  font-size: 12.5px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .form-grid { grid-template-columns: 1fr; }
}
