/* --- RESET BÁSICO --- */
* {
  box-sizing: border-box;
  font-family: "Segoe UI", Roboto, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
}

/* --- VARIAVEIS E CORES (TEMA CONFORTÁVEL) --- */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  /* Fundo da página Admin (Cinza Azulado Escuro) */
  --bg-light: #f1f5f9; /* Era muito branco, agora é um cinza suave */
  --bg-page: #e2e8f0; /* Fundo da página */

  /* Cards (Cinza claro, não branco puro) */
  --card-bg: #f8fafc;

  --text-dark: #1e293b;
  --text-gray: #64748b;
  --white: #ffffff;
  --error: #ef4444;

  /* Mantendo variáveis da TV */
  --tv-bg-card: #161b22;
  --tv-border: #30363d;
  --tv-highlight: #00e676;
}

body {
  background-color: var(--bg-page); /* Fundo mais escuro */
  color: var(--text-dark);
  padding-bottom: 50px;
}

/* INPUTS GERAIS */
/* Removemos o width: 100% global para não quebrar flexbox */
input,
button {
  font-size: 16px;
  outline: none;
}

/* --- LOGIN / CADASTRO --- */
body.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 20px;
}
.login-container {
  background: var(--white);
  width: 100%;
  max-width: 400px;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  text-align: center;
}
.login-header .logo-icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 10px;
}
.login-header h1 {
  font-size: 24px;
  color: var(--text-dark);
  margin-bottom: 5px;
}
.login-header p {
  color: var(--text-gray);
  font-size: 14px;
  margin-bottom: 30px;
}
.login-form {
  text-align: left;
}
.input-group {
  margin-bottom: 20px;
}
.input-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 5px;
}
.input-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  transition: border-color 0.3s;
}
.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.btn-login {
  width: 100%;
  padding: 14px;
  background-color: var(--primary);
  color: white;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s;
}
.btn-login:hover {
  background-color: var(--primary-hover);
}
.alert-error {
  background: #fee2e2;
  color: var(--error);
  padding: 10px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.login-footer {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
}
.link-tv {
  color: var(--text-gray);
  text-decoration: none;
  font-size: 14px;
}

/* --- ADMIN LAYOUT --- */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.app-header {
  background: var(--white);
  padding: 15px 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
  margin-bottom: 30px;
}
.header-content {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header-content h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
}
.back-link {
  text-decoration: none;
  color: var(--text-gray);
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-top: 20px;
}
.dash-item {
  background: white;
  padding: 20px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s;
}
.dash-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.dash-item .material-icons {
  font-size: 32px;
  margin-bottom: 10px;
}
.dash-item.primary .material-icons {
  color: var(--primary);
}
.dash-item.warning .material-icons {
  color: #f59e0b;
}
.dash-item.secondary .material-icons {
  color: #8b5cf6;
}
.dash-item.dark .material-icons {
  color: #374151;
}
.dash-item h3 {
  font-size: 16px;
  margin: 0;
}

/* Token Card */
.token-card {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: white;
  padding: 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 5px 15px rgba(37, 99, 235, 0.3);
}
.token-info h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 2px;
}
.btn-copy {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

/* --- FORMULÁRIO NOVO TREINO (CORRIGIDO) --- */
.card-form {
  background: var(--card-bg); /* Menos agressivo que white */
  border: 1px solid #cbd5e1; /* Borda suave */
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.form-section {
  margin-bottom: 25px;
}
.section-label {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 14px;
  display: block;
  margin-bottom: 8px;
}

/* ESTILO DO BOTÃO ADICIONAR CENTRALIZADO */
.add-button-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
}

.btn-add-center {
  background: #e2e8f0;
  color: #334155;
  border: 1px solid #94a3b8;
  padding: 10px 30px;
  border-radius: 50px; /* Redondinho */
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-add-center:hover {
  background: #cbd5e1;
  transform: scale(1.05);
}

/* Input com ícone */
.input-with-icon {
  position: relative;
}
.input-with-icon .material-icons {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-gray);
}
.input-with-icon input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}

/* Lista de Exercícios */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.btn-small {
  background: #e5e7eb;
  color: var(--text-dark);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.exercicio-row-styled {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 10px;
}

/* AQUI ESTÁ A CORREÇÃO MÁGICA DOS INPUTS */
.ex-inputs {
  display: flex;
  gap: 10px;
  flex: 1; /* Ocupa todo espaço disponível */
  width: 100%;
}

.ex-inputs input {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 10px;
  height: 42px; /* Altura fixa para alinhar */
}

/* Nome do exercício ocupa mais espaço */
.ex-inputs input[name="exercicios[]"] {
  flex: 3;
  width: auto; /* Remove o width 100% global */
  min-width: 0; /* Previne estouro */
}

/* Quantidade ocupa menos espaço */
.ex-inputs input[name="quantidades[]"] {
  flex: 1;
  width: auto;
  max-width: 100px;
}

.btn-icon-remove {
  background: #fee2e2;
  color: #ef4444;
  border: none;
  border-radius: 6px;
  width: 42px;
  height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon-remove:hover {
  background: #fecaca;
}

/* Botões de Ação */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 30px;
}
.btn-outline {
  flex: 1;
  background: transparent;
  border: 2px solid #e5e7eb;
  color: var(--text-gray);
  font-weight: 600;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-primary-action {
  flex: 2;
  background: var(--primary);
  color: white;
  border: none;
  font-weight: bold;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

/* --- GERENCIAR PAINEL (ESTILO MONITOR) --- */
.monitor-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  max-width: 700px;
  margin: 0 auto;
}
.monitor-screen {
  background: #0f172a;
  color: white;
  padding: 40px 20px;
  text-align: center;
  border-bottom: 4px solid #334155;
}
.screen-status {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  margin-bottom: 20px;
}
.status-on {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid #22c55e;
}
.status-off {
  background: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  border: 1px solid #64748b;
}
.current-training h2 {
  font-size: 2.5rem;
  margin: 0 0 10px 0;
  color: #fff;
}
.current-training p {
  color: #94a3b8;
  margin: 0;
}
.monitor-controls {
  padding: 30px;
  text-align: center;
}
.btn-stop {
  background: #ef4444;
  color: white;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 16px;
}
.monitor-info {
  background: #f1f5f9;
  padding: 10px 20px;
  border-radius: 50px;
  margin-top: 25px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #475569;
  font-size: 14px;
}
.monitor-info code {
  font-weight: bold;
  color: #0f172a;
  font-size: 16px;
}

/* --- HISTÓRICO --- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.history-item {
  background: white;
  padding: 20px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  border: 1px solid transparent;
}
.history-item:hover {
  border-color: var(--primary);
}
.history-info h4 {
  margin: 0 0 5px 0;
  font-size: 16px;
  color: var(--text-dark);
}
.history-info p {
  margin: 0;
  color: var(--text-gray);
  font-size: 14px;
}
.btn-reuse {
  background: var(--bg-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.btn-reuse:hover {
  background: var(--primary);
  color: white;
}

/* --- TV MODE (VISUAL EXCEL MODERNO) --- */
body.tv-mode {
  background-color: #000;
  color: white;
  height: 100vh;
  width: 100vw;
  overflow: hidden; /* Proíbe barra de rolagem global */
  margin: 0;
  padding: 0;
  display: flex;
}

/* O Container principal que divide a tela */
.tv-container {
  width: 100%;
  height: 100%;
  display: grid;
  padding: 1vh; /* Margem pequena da borda da TV */
  gap: 1vh;
  box-sizing: border-box;
  /* Variáveis padrão */
  --tv-bg-card: #111;
  --tv-border: #333;
  --tv-highlight: #00e676;
  --tv-font-size: 2vh; /* Tamanho base dinâmico */
}

/* --- LÓGICA DE LAYOUT DINÂMICO --- */

/* 1 PESSOA: Tela cheia, letras gigantes */
.layout-1 {
  grid-template-columns: 1fr;
  --tv-font-size: 4vh;
  --row-height: 8vh;
}

/* 2 PESSOAS: Divisão vertical */
.layout-2 {
  grid-template-columns: 1fr 1fr;
  --tv-font-size: 2.5vh;
  --row-height: 6vh;
}

/* 3 ou 4 PESSOAS: Grade 2x2 */
.layout-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  --tv-font-size: 2vh;
  --row-height: 5vh;
}

/* 5+ PESSOAS: Grade automática menor */
.layout-multi {
  grid-template-columns: repeat(auto-fit, minmax(30%, 1fr));
  --tv-font-size: 1.5vh;
  --row-height: 4vh;
}

/* --- CARD DO ALUNO --- */
.aluno-card {
  background: var(--tv-bg-card);
  border: 2px solid var(--tv-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Garante que nada saia do card */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* Cabeçalho do Card (Nome) */
.aluno-nome {
  background: #0f301d; /* Verde escuro fundo */
  color: var(--tv-highlight);
  margin: 0;
  padding: 1.5vh;
  text-align: center;
  font-size: calc(var(--tv-font-size) * 1.5); /* 1.5x o tamanho base */
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 2px solid var(--tv-highlight);
}

/* Área dos Exercícios (Tabela/Grade) */
.exercicios-grid {
  display: flex;
  flex-direction: column;
  flex: 1; /* Ocupa todo o resto do card */
  padding: 0;
}

/* Cada Linha de Exercício ("Bloquinho Excel") */
.exercicio-item {
  display: grid;
  grid-template-columns: 1fr auto; /* Nome ocupa tudo, qtd ocupa o final */
  align-items: center;
  padding: 0 2vh;
  border-bottom: 1px solid #333;
  font-size: var(--tv-font-size);
  height: var(--row-height); /* Altura fixa por linha para alinhar bonito */
  background: linear-gradient(90deg, #1a1a1a 0%, #111 100%);
}

/* Efeito Zebrado (Simulando planilha) */
.exercicio-item:nth-child(even) {
  background: #161616;
}

.ex-nome {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Três pontinhos se for MUITO grande */
  padding-right: 10px;
  color: #e0e0e0;
}

.ex-qtd {
  font-weight: bold;
  color: var(--tv-highlight);
  background: rgba(0, 230, 118, 0.1);
  padding: 0.5vh 1vh;
  border-radius: 4px;
  min-width: 6vh;
  text-align: center;
}

/* LOGIN DA TV (Manter igual) */
.tv-login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.login-box {
  background: #1e1e1e;
  padding: 40px;
  border-radius: 10px;
  text-align: center;
  border: 1px solid #333;
}
.login-box input {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  font-size: 1.5rem;
  text-align: center;
  text-transform: uppercase;
}
.login-box button {
  width: 100%;
  padding: 10px;
  font-size: 1.2rem;
  background: var(--tv-highlight);
  border: none;
  font-weight: bold;
  cursor: pointer;
}

/* --- ADICIONE NO FINAL DO ARQUIVO (ESTILO DO ALERTA TOAST) --- */
#toast {
  visibility: hidden;
  min-width: 250px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 50px;
  padding: 16px;
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  font-size: 17px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s, bottom 0.3s;
}

#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 50px;
  background-color: #00e676; /* Verde Neon */
  color: #000;
  font-weight: bold;
}

/* --- ATUALIZAÇÃO GERAL DOS INPUTS (FORÇAR MAIÚSCULA) --- */
input,
select,
textarea {
  text-transform: uppercase; /* Visualmente maiúsculo */
}

/* --- ATUALIZAÇÃO DA TV (FONTE GRANDE E SEGURA) --- */
/* --- TV MODE (HÍBRIDO: GRADE FIXA OU CARROSSEL) --- */
body.tv-mode {
  background-color: #000;
  color: white;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  margin: 0;
  padding: 0;
  display: flex;
}

.tv-container {
  width: 100%;
  height: 100%;
  display: grid;
  padding: 10px;
  gap: 10px;
  box-sizing: border-box;

  /* PADRÃO: 3 Colunas x 3 Linhas = 9 Cards */
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);

  --tv-bg-card: #161b22;
  --tv-border: #30363d;
  --tv-highlight: #00e676;
}

/* --- CARD DO ALUNO --- */
.aluno-card {
  background: var(--tv-bg-card);
  border: 2px solid var(--tv-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.aluno-nome {
  background: #0d1117;
  color: var(--tv-highlight);
  margin: 0;
  padding: 5px 0;
  text-align: center;
  /* Fonte ajustada para caber 9 na tela */
  font-size: clamp(18px, 2.5vh, 40px);
  font-weight: 900;
  text-transform: uppercase;
  border-bottom: 2px solid var(--tv-highlight);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

/* Área dos Exercícios */
.exercicios-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 2 Colunas internas */
  gap: 2px 10px;
  align-content: start;
  padding: 5px;
  overflow: hidden;
  flex-grow: 1;
}

.exercicio-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 5px;
  border-bottom: 1px solid #30363d;

  /* Fonte menor para caber 9 cards */
  font-size: clamp(12px, 1.8vh, 24px);
  font-weight: 600;
  color: #e6edf3;
  min-height: 2.5vh;
}

.ex-nome {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 5px;
  flex: 1;
  text-align: left;
}

.ex-qtd {
  color: var(--tv-highlight);
  font-weight: 800;
  background: rgba(0, 230, 118, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Zebrado */
.exercicio-item:nth-child(4n + 1),
.exercicio-item:nth-child(4n + 2) {
  background: #21262d;
}

/* Barra de progresso (Só aparece se tiver carrossel) */
.page-indicator {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 4px;
  background: var(--tv-highlight);
  width: 0%;
  z-index: 2000;
}

.ex-nome {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Corta com "..." se não couber na coluna */
  margin-right: 5px;
  flex: 1;
  text-align: left;
}

.ex-qtd {
  color: var(--tv-highlight);
  font-weight: 800;
  white-space: nowrap;
  background: rgba(0, 230, 118, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* --- LAYOUTS AUTOMÁTICOS --- */

/* 1 ALUNO: Pode usar tudo */
.layout-1 {
  grid-template-columns: 1fr;
}
.layout-1 .exercicios-grid {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0 20px;
  padding: 20px;
}
.layout-1 .aluno-nome {
  font-size: clamp(40px, 8vh, 100px);
}
.layout-1 .exercicio-item {
  font-size: clamp(24px, 4vh, 60px);
  padding: 10px;
}

/* 2 ALUNOS: Divide ao meio */
.layout-2 {
  grid-template-columns: 1fr 1fr;
}

/* 3-4 ALUNOS: Grade 2x2 */
.layout-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr); /* Força 2 linhas iguais */
}

/* 5+ ALUNOS (O caso do seu print): Grade automática densa */
.layout-multi {
  /* Tenta colocar 3 colunas, se não der, diminui */
  grid-template-columns: repeat(auto-fit, minmax(30%, 1fr));
  /* Força as linhas a terem o mesmo tamanho e caberem na tela */
  grid-auto-rows: 1fr;
}
/* Ajuste fino para muitos cards: reduz ainda mais o padding */
.layout-multi .exercicios-grid {
  padding: 2px 5px;
}
.layout-multi .aluno-name {
  padding: 5px 0;
}

/* LOGIN E TOAST (Manter iguais) */
.tv-login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.login-box {
  background: #1e1e1e;
  padding: 40px;
  border-radius: 10px;
  text-align: center;
  border: 1px solid #333;
}
.login-box input {
  background: #121212;
  color: #fff;
  border: 1px solid #333;
  font-size: 1.5em;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 20px;
  border-radius: 8px;
  width: 100%;
}
.login-box button {
  background: var(--tv-highlight);
  color: black;
  font-weight: bold;
  border: none;
  padding: 15px;
  width: 100%;
  border-radius: 8px;
  font-size: 1.2em;
  cursor: pointer;
}
#toast {
  visibility: hidden;
  min-width: 250px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 50px;
  padding: 16px;
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  font-size: 17px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s, bottom 0.3s;
}
#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 50px;
  background-color: #00e676;
  color: #000;
  font-weight: bold;
}
