/* ==========================================================================
   VARIÁVEIS GLOBAIS & RESET
   ========================================================================== */
:root {
  --primary-color: #4361ee;
  --primary-light: #4895ef;
  --primary-dark: #3a0ca3;
  --primary-hover: #3f37c9;
  --secondary-color: #7209b7;
  --secondary-hover: #560bad;
  --success-color: #4cc9f0;
  --success-hover: #3a86ff;
  --error-color: #f72585;
  --error-hover: #b5179e;
  --warning-color: #f8961e;
  --warning-hover: #f3722c;
  --light-bg: #f8f9fa;
  --card-bg: #ffffff;
  --border-color: #e9ecef;
  --text-color: #343a40;
  --text-light: #6c757d;
  --text-white: #ffffff;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s ease;
  --font-family: 'League Spartan', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
  color: var(--text-color);
  line-height: 1.6;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 20px;
}

/* ==========================================================================
   CLASSES UTILITÁRIAS
   ========================================================================== */
.container {
  width: 100%;
  max-width: 1200px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.manual-cadastro-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

/* ==========================================================================
   COMPONENTES PRINCIPAIS
   ========================================================================== */
header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: var(--text-white);
  padding: 20px 30px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

header h1 {
  font-size: 1.8em;
  font-weight: 700;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.header-status {
  background: rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
}

.welcome-main { padding: 40px; text-align: center; }
#school-selection-title { margin-bottom: 30px; font-size: 2.2em; font-weight: 700; color: var(--primary-dark); }
.school-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 25px; margin-bottom: 40px; }
.school-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 25px; text-align: center; cursor: pointer; transition: var(--transition); border-top: 4px solid var(--primary-color); }
.school-card:hover { transform: translateY(-8px); box-shadow: var(--shadow-hover); }
.school-card img { width: 80px; height: 80px; margin-bottom: 15px; object-fit: contain; border-radius: 50%; padding: 8px; background: var(--light-bg); }
.school-card h3 { margin-bottom: 15px; font-weight: 600; }
.school-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.no-schools { grid-column: 1 / -1; padding: 40px; color: var(--text-light); }

/* Base dos botões */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-family: var(--font-family);
    font-size: 1em;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    background-color: var(--primary-color);
    color: var(--text-white);
    vertical-align: middle; /* Garante alinhamento no fluxo de texto */
}

/* Ícones dentro de botões (centralização total) */
.btn i,
.btn svg,
.btn img {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1em;      /* mantém o ícone proporcional ao texto */
    width: auto;
    vertical-align: middle;
}

/* Estados de interação */
.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Variações de cor */
.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-white);
}
.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-success {
    background: var(--success-color);
    color: var(--text-white);
}
.btn-success:hover {
    background: var(--success-hover);
}

.btn-error {
    background: var(--error-color);
    color: var(--text-white);
}
.btn-error:hover {
    background: var(--error-hover);
}

/* Tamanhos */
.btn-small {
    padding: 6px 6px;
    font-size: 1em;
}
.btn-large {
    padding: 14px 28px;
    font-size: 1.1em;
}

/* Botão de fechar */
.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    transition: transform 0.3s;
    padding: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-close:hover {
    color: var(--error-color);
    transform: rotate(90deg);
}

.tabs { display: flex; background: var(--light-bg); border-bottom: 2px solid var(--border-color); flex-wrap: wrap; padding: 0 20px; }
.tab-link { background: none; border: none; cursor: pointer; padding: 16px 20px; transition: var(--transition); font-size: 1em; color: var(--text-light); border-bottom: 3px solid transparent; font-weight: 600; }
.tab-link:hover { color: var(--primary-color); }
.tab-link.active { border-bottom-color: var(--primary-color); color: var(--primary-color); }
main { padding: 30px; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.5s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 25px; margin-bottom: 25px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin-top: 0; margin-bottom: 15px; color: var(--primary-dark); }
.card p { margin-bottom: 15px; color: var(--text-light); }

/* --- REGRAS UNIFICADAS PARA TABELAS --- */
.table-container { overflow-x: auto; border: 1px solid var(--border-color); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
thead th { background-color: var(--light-bg); padding: 14px 16px; text-align: left; font-weight: 600; color: var(--primary-dark); position: sticky; top: 0; z-index: 1; border-bottom: 2px solid var(--border-color); }
tbody tr:hover { background-color: #f8f9fa; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }

/* Coluna de Ações e Foto Corrigida */
th:last-child, td:last-child { text-align: center; }

/* Estilos para o CONTEÚDO (o div interno) da célula de ações */
.actions-cell div {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.aluno-foto-preview { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color); }
.edit-input { width: 100%; padding: 8px; border: 1px solid var(--primary-color); border-radius: var(--radius-sm); font-size: 0.95em; }

/* Estilos para o CONTEÚDO (o div interno) da célula de foto */
.foto-cell div {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-upload-overlay { cursor: pointer; font-size: 1.2em; color: var(--primary-color); transition: var(--transition); }
.btn-upload-overlay:hover { transform: scale(1.2); }

/* --- COMPONENTES ESPECÍFICOS --- */
input[type="text"] { width: 100%; padding: 12px 16px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 1em; transition: var(--transition); }
input[type="text"]:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2); }
.input-group { display: flex; gap: 10px; align-items: center; }
.file-name-display { color: var(--text-light); font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.form-group-divider { color: var(--text-light); }

#import-drop-zone { border: 2px dashed var(--border-color); border-radius: var(--radius); padding: 40px; text-align: center; cursor: pointer; background: var(--light-bg); transition: var(--transition); margin-top: 20px; }
#import-drop-zone.dragover { background: #e9ecef; border-color: var(--primary-color); }

.status-box { margin-top: 15px; padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; }
.status-box.success { background-color: #e3f9f4; border-color: #4fd1c5; color: #23857b; }
.status-box.error { background-color: #fde8ed; border-color: #f72585; color: #b5179e; }
.status-box.warning { background-color: #fff4e3; border-color: #f8961e; color: #b85e00; }
.status-box.info { background-color: #eaf0ff; border-color: #4361ee; color: #3a0ca3; }

.confirmation-container { display: flex; align-items: center; gap: 25px; margin-top: 25px; padding: 25px; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--light-bg); }
.confirmation-container:not(.hidden) { animation: fadeIn 0.5s; }
#confirmation-photo { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary-light); }
.confirmation-details h3 { margin: 0 0 8px 0; font-size: 1.6em; }
.confirmation-details p { margin: 0 0 20px 0; font-size: 1.1em; color: var(--text-light); }

.cracha-manager { display: flex; gap: 30px; }
.aluno-list { width: 30%; max-height: 500px; overflow-y: auto; border-right: 1px solid var(--border-color); padding-right: 20px; }
.aluno-list ul { list-style-type: none; }
.aluno-list li { padding: 12px 16px; cursor: pointer; border-radius: var(--radius-sm); margin-bottom: 8px; transition: var(--transition); border-left: 3px solid transparent; }
.aluno-list li:hover { background: var(--light-bg); border-left-color: var(--primary-light); }
.aluno-list li.selected { background: var(--primary-color); color: var(--text-white); font-weight: 600; border-left-color: var(--primary-dark); }
.cracha-preview { flex: 1; text-align: center; }
.cracha-preview canvas { max-width: 50%; height: auto; background: #e9ecef; display: block; margin: 0 auto 20px; border-radius: var(--radius-sm); }
.button-group {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 15px; /* Adiciona um espaço vertical acima do grupo de botões */
}

/* MODAIS */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(5px); }
.modal-overlay:not(.hidden) { animation: fadeIn 0.3s ease; }
.modal-content { background: white; border-radius: var(--radius); width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-hover); animation: modalFadeIn 0.3s ease; }
@keyframes modalFadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-content form { padding: 30px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 30px; border-bottom: 1px solid var(--border-color); }
.modal-header h2 { margin: 0; color: var(--primary-dark); }
.modal-body { padding: 30px; }
.modal-content h2, #modal-title { color: var(--primary-dark); margin-bottom: 20px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; }
.modal-actions { margin-top: 25px; display: flex; justify-content: flex-end; gap: 15px; }
.modal-lg { max-width: 800px; }
.template-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px; margin-top: 20px; padding: 10px; max-height: 50vh; overflow-y: auto; background-color: var(--light-bg); border-radius: var(--radius-sm); }
.template-item { border: 3px solid transparent; border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition); overflow: hidden; aspect-ratio: 187 / 283; background-color: #fff; }
.template-item:hover { transform: scale(1.05); box-shadow: var(--shadow-hover); }
.template-item.selected { border-color: var(--primary-color); box-shadow: 0 0 15px rgba(67, 97, 238, 0.4); transform: scale(1.05); }
.template-item img { width: 100%; height: 100%; object-fit: cover; }
.template-upload-card { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: var(--primary-color); background-color: #eaf0ff; font-weight: 600; }
.template-upload-card span { font-size: 2.5em; margin-bottom: 10px; }
#template-selector-modal .modal-content {
    max-width: 800px; /* Define um limite máximo apenas para este modal específico */
}
#template-selector-modal .modal-content {
    /* 1. Transforma o modal em um contêiner flexível vertical */
    display: flex;
    flex-direction: column;

    /* 2. Garante que o conteúdo não vaze */
    overflow: hidden; 
}

#template-selector-modal .modal-header {
    /* Garante que o header não encolha */
    flex-shrink: 0;
}

#template-selector-modal .modal-body {
    /* 3. Faz o corpo (com a galeria) crescer para ocupar todo o espaço livre */
    flex-grow: 1;

    /* 4. Adiciona a rolagem APENAS ao corpo, se necessário */
    overflow-y: auto;
}

#template-selector-modal .modal-actions {
    /* 5. Reseta a margem antiga e garante que ele não encolha */
    margin-top: 0;
    flex-shrink: 0;

    /* 6. Adiciona um estilo de rodapé para separá-lo visualmente */
    padding: 20px 30px;
    border-top: 1px solid var(--border-color);
    background-color: var(--light-bg);
}
/* LOADING & TOAST */
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ''; position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; margin-top: -10px; margin-left: -10px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: var(--text-white); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.toast {
    padding: 16px 24px;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-hover);
    transform: translateX(120%);
    animation: 
        slideIn 0.5s forwards,
        fadeOut 0.5s 4.5s forwards;
    min-width: 250px;
        display: flex;
    justify-content: space-between; /* Alinha a mensagem à esquerda e o botão à direita */
    align-items: center; /* Centraliza verticalmente */
    gap: 15px; /* Adiciona um espaço entre o texto e o botão */
}
.toast-close-btn {
    background: none;
    border: none;
    color: inherit; /* Herda a cor do texto do toast (branco, geralmente) */
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.toast-close-btn:hover {
    opacity: 1;
}
.toast.success { background: var(--success-hover); }
.toast.error { background: var(--error-hover); }
.toast.info { background: var(--primary-hover); }
@keyframes slideIn { to { transform: translateX(0); } }
@keyframes fadeOut { from { transform: translateX(0); } to { transform: translateX(120%); } }

/* RESPONSIVIDADE */
@media (max-width: 768px) {
  body { padding: 10px; }
  .header-content { flex-direction: column; text-align: center; }
  .tabs { flex-direction: column; padding: 0; }
  main { padding: 20px; }
  .cracha-manager { flex-direction: column; }
  .aluno-list { width: 100%; border-right: none; padding-right: 0; border-bottom: 1px solid var(--border-color); padding-bottom: 20px; max-height: 300px; }
  .confirmation-container { flex-direction: column; text-align: center; }
  .actions-cell div { flex-direction: column; align-items: stretch; gap: 5px; } /* Corrigido */
  .actions-cell .btn { width: 100%; }
}

@media (max-width: 480px) {
  body { padding: 0; }
  .container { border-radius: 0; }
  header h1 { font-size: 1.5em; }
  .school-list { grid-template-columns: 1fr; }
  .input-group { flex-direction: column; align-items: stretch; }
  .modal-actions { flex-direction: column; }
  .btn { width: 100%; }
  .modal-actions .btn { width: auto; }
  .school-actions .btn { width: auto; }
  .actions-cell .btn { width: auto; }
  .button-group .btn { width: auto; }
  .manual-cadastro-actions .btn { width: auto; }
  .table-container { border-left: none; border-right: none; border-radius: 0; }
}
/* ==========================================================================
   PAINEL DE PERSONALIZAÇÃO DE CRACHÁS
   ========================================================================== */
#cracha-editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1050; /* Z-index alto para ficar sobre outros elementos */
}

#cracha-editor-modal .editor-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    width: 90%;
    height: 90%;
    max-width: 1400px;
    display: grid;
    grid-template-columns: 1fr 350px; /* Coluna de preview e coluna de controles */
    grid-template-rows: 60px 1fr 80px; /* Header, Content, Footer */
    grid-template-areas:
        "header header"
        "preview controls"
        "footer footer";
    overflow: hidden;
}

#cracha-editor-modal .editor-header {
    grid-area: header;
    padding: 0 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--light-bg);
}

#cracha-editor-modal .editor-header h2 {
    color: var(--primary-dark);
}

#cracha-editor-modal #preview-cracha {
    grid-area: preview;
    background-color: #e9ecef;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: auto;
}

#cracha-editor-modal #preview-canvas {
    max-width: 100%;
    max-height: 100%;
    height: auto;
    box-shadow: var(--shadow);
}

#cracha-editor-modal #editor-controles {
    grid-area: controls;
    padding: 20px;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
}

#cracha-editor-modal .control-group {
    margin-bottom: 20px;
}

#cracha-editor-modal .control-group h4 {
    margin-bottom: 10px;
    color: var(--primary-dark);
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 5px;
}

#cracha-editor-modal .control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.9em;
}

#cracha-editor-modal .control-group input[type="number"],
#cracha-editor-modal .control-group input[type="text"],
#cracha-editor-modal .control-group input[type="color"],
#cracha-editor-modal .control-group select {
    width: 100%;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

#cracha-editor-modal .editor-footer {
    grid-area: footer;
    padding: 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
    border-top: 1px solid var(--border-color);
    background-color: var(--light-bg);
}
body.modal-open {
    overflow: hidden;
}

/* 4. Melhora a interação e o alinhamento da célula de foto */
.foto-cell > div {
    position: relative; /* Essencial para posicionar o ícone de upload sobre a foto */
    display: flex;
    justify-content: center;
    align-items: center;
    margin: auto; /* Centraliza o contêiner da foto na célula */
    width: 50px;
    height: 50px;
}

/* 5. Estiliza a miniatura da foto do aluno */
.aluno-foto-preview {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Garante que a foto preencha o espaço sem distorcer */
    border-radius: 6px;
    background-color: #e9ecef; /* Cor de fundo caso a imagem não carregue */
}

.btn-upload-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 20px;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.btn-upload-overlay:hover {
    opacity: 1;
}

/* força o link ou ícone dentro a não quebrar o alinhamento */
.btn-upload-overlay a,
.btn-upload-overlay i {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
}
/* Mostra o ícone de upload ao passar o mouse sobre a área da foto */
.foto-cell > div:hover .btn-upload-overlay {
    opacity: 1;
}
.confirmation-container img {
    width: 300px;  /* <--- AQUI ESTÁ O TAMANHO (Mude para o desejado) */
    height: 300px; /* <--- AQUI ESTÁ O TAMANHO (Mude para o desejado) */
    border-radius: 50%; 
    object-fit: cover; 
    border: 3px solid var(--primary-light);
}
.header-content img {
     height: 30px;
}