/* ===== TOKENS ===== */
:root {
  --green:        #00c141;
  --green-dark:   #009933;
  --green-light:  #e6f9ed;
  --blue:         #1a3a9c;
  --blue-dark:    #0d2472;
  --blue-light:   #eef2ff;
  --teal:         #0a8a6b;

  --bg:           #f0f5ff;
  --card:         #ffffff;
  --border:       #dce8f5;
  --text:         #1a2340;
  --muted:        #5a6b8a;
  --shadow:       0 2px 12px rgba(26,58,156,.10);
  --shadow-md:    0 4px 24px rgba(26,58,156,.13);

  --radius:       14px;
  --radius-sm:    8px;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.5;
}

/* ===== AUTH ===== */
.login-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9999;
  background: rgba(10, 20, 72, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px 36px;
  max-width: 360px; width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.35);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.login-logo     { height: 56px; object-fit: contain; margin-bottom: 6px; }
.login-title    { font-size: 1.25rem; font-weight: 700; color: var(--blue-dark); }
.login-subtitle { font-size: .85rem; font-weight: 600; color: var(--teal); margin-top: -4px; }
.login-desc     { font-size: .8rem; color: var(--muted); margin: 4px 0 10px; line-height: 1.6; }
.login-btn-wrap { display: flex; justify-content: center; width: 100%; }
.login-btn-container { position: relative; width: 300px; height: 44px; }
.login-google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 100%; padding: 0 16px;
  background: #fff; color: #3c4043;
  border: 1px solid #dadce0; border-radius: 8px;
  font-family: var(--font); font-size: .95rem; font-weight: 500;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.google-btn-overlay {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0.01;
  overflow: hidden; cursor: pointer;
}
.google-btn-overlay > * { width: 100% !important; height: 100% !important; }
.login-hint     { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.login-error {
  font-size: .8rem; color: #c0392b;
  background: #fdf0ef; border: 1px solid #f5c6c2;
  border-radius: 8px; padding: 10px 14px; width: 100%;
  text-align: left; line-height: 1.5;
}

/* ===== HEADER ===== */
.header {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue) 55%, var(--teal) 85%, #00a83a 100%);
  padding: 20px 20px 56px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
/* Formas geométricas abstratas — depth sem peso */
.header::before {
  content: '';
  position: absolute;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: rgba(255,255,255,.05);
  top: -140px; right: -80px;
  pointer-events: none;
}
.header::after {
  content: '';
  position: absolute;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(0,193,65,.08);
  bottom: -70px; left: 35%;
  pointer-events: none;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 1;
}
.header-logo {
  height: 72px;
  width: auto;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.30));
  transition: transform .2s;
}
.header-logo:hover { transform: scale(1.04); }
.btn-logout {
  position: absolute; right: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: rgba(255,255,255,.15); color: #fff;
  border: 1px solid rgba(255,255,255,.3); border-radius: 50px;
  font-family: var(--font); font-size: .82rem; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* ===== MAIN ===== */
.main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ===== CARD ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
}
/* O card de filtros sobrepõe o header */
.filter-card {
  margin-top: -36px;
  position: relative;
  z-index: 10;
  box-shadow: 0 8px 32px rgba(26,58,156,.16), 0 2px 8px rgba(0,0,0,.06);
}

/* ===== NAV SUPERIOR (1ª Fase × Recursos) ===== */
.view-nav {
  display: flex;
  gap: 6px;
  margin: -52px auto 16px;
  padding: 6px;
  background: rgba(255,255,255,.92);
  border-radius: 50px;
  box-shadow: 0 4px 16px rgba(26,58,156,.18);
  position: relative;
  z-index: 11;
  width: fit-content;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.view-tab {
  padding: 9px 22px;
  border-radius: 50px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}
.view-tab:hover { color: var(--blue-dark); }
.view-tab.active {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  box-shadow: 0 2px 8px rgba(26,58,156,.30);
}
/* Quando o nav superior aparece, o filter-card abaixo não precisa mais da margem negativa */
.view-nav + .view .filter-card { margin-top: 0; }
@media (max-width: 540px) {
  .view-nav { margin-top: -42px; }
  .view-tab { padding: 8px 14px; font-size: .82rem; }
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--blue);
  margin-bottom: 18px;
}
.card-title svg { color: var(--green); }

/* Bloco de identidade dentro do card — alinhado à direita */
.card-brand {
  text-align: right;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.card-eyebrow {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.card-title-main {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 800;
  color: var(--blue-dark);
  letter-spacing: -.3px;
  line-height: 1.2;
}
.card-subtitle {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab {
  padding: 9px 22px;
  border-radius: 50px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .18s ease;
  font-family: var(--font);
}
.tab:hover {
  border-color: var(--green);
  color: var(--green-dark);
}
.tab.active {
  background: linear-gradient(135deg, var(--green), var(--teal));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,193,65,.35);
}

/* ===== FILTER GRID ===== */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filter-group label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}
.filter-group input {
  height: 42px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.filter-group input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(0,193,65,.15);
}
.filter-group input:disabled {
  background: #f7f9fc;
  color: #aab;
  cursor: not-allowed;
}

/* ===== CUSTOM SELECT PESQUISÁVEL ===== */
.sel-wrap {
  position: relative;
}
.sel-input {
  width: 100%;
  height: 42px;
  padding: 0 32px 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  cursor: pointer;
}
.sel-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(0,193,65,.15);
  cursor: text;
}
.sel-input:disabled {
  background: #f7f9fc;
  color: #aab;
  cursor: not-allowed;
}
.sel-chevron {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  transition: transform .18s;
}
.sel-wrap.open .sel-chevron {
  transform: translateY(-50%) rotate(180deg);
}
.sel-opts {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 200;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(26,58,156,.14);
  max-height: 224px;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
}
.sel-opts li {
  padding: 9px 14px;
  font-size: .875rem;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sel-opts li:hover,
.sel-opts li.hovered { background: var(--blue-light); }
.sel-opts li.selected { color: var(--green-dark); font-weight: 600; }
.sel-opts li.placeholder { color: var(--muted); font-style: italic; }
.sel-opts li.no-opts { color: var(--muted); font-style: italic; cursor: default; }
.filter-search { grid-column: 1 / -1; }

/* Busca como elemento principal */
.search-primary {
  margin-bottom: 20px;
}
.search-primary .search-wrap input {
  height: 50px;
  font-size: 1rem;
  border-width: 2px;
  border-color: var(--border);
  padding-left: 44px;
  border-radius: 12px;
}
.search-primary .search-wrap input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(0,193,65,.12);
}
.search-primary .search-wrap input::placeholder {
  color: #9aabcc;
}
.search-primary .search-icon {
  left: 14px;
  color: #9aabcc;
  width: 18px; height: 18px;
}

.search-wrap {
  position: relative;
}
.search-wrap input {
  width: 100%;
  padding-left: 38px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

/* Label de seção para os filtros secundários */
.filter-section-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== HINT + BUSCAR ===== */
.filter-actions {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.filter-hint {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  color: var(--blue);
  min-width: 0;
}
.filter-hint svg { flex-shrink: 0; }
.hint-ok    { background: var(--green-light); color: var(--green-dark); }
.hint-error { background: #fff0f0; color: #b91c1c; }

.btn-buscar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  border: none;
  border-radius: 50px;
  font-family: var(--font);
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(26,58,156,.35);
  transition: opacity .15s, transform .12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-buscar:hover    { opacity: .9; transform: translateY(-1px); }
.btn-buscar:active   { transform: translateY(0); }
.btn-buscar:disabled { opacity: .5; cursor: not-allowed; transform: none; }

@media (max-width: 640px) {
  .filter-actions { flex-direction: column; }
  .btn-buscar     { width: 100%; justify-content: center; }
}

/* ===== ESTADOS ===== */
.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--muted);
  text-align: center;
}
.state-box svg { opacity: .5; }
.state-box p { font-size: .95rem; }

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== RESULTS CARD ===== */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.results-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.results-count {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--blue);
}
.results-label { font-size: .9rem; color: var(--muted); }
.level-badge {
  background: linear-gradient(135deg, var(--green), var(--teal));
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 50px;
  letter-spacing: .3px;
}

/* Download button */
.btn-download {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--green), var(--teal));
  color: #fff;
  border: none;
  border-radius: 50px;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,193,65,.30);
  transition: opacity .15s, transform .12s;
}
.btn-download:hover { opacity: .9; transform: translateY(-1px); }
.btn-download:active { transform: translateY(0); }
.btn-xlsx { background: linear-gradient(135deg, #1d6f42, #107c41); box-shadow: 0 3px 10px rgba(16,124,65,.30); }
.download-group { display: flex; gap: 8px; }

/* ===== TABLE ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  min-width: 780px;
}
.results-table thead {
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}
.results-table th {
  padding: 11px 12px;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.results-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.results-table tbody tr:last-child td { border-bottom: none; }
.results-table tbody tr:hover { background: var(--blue-light); }
.results-table tbody tr:nth-child(even) { background: #fafbff; }
.results-table tbody tr:nth-child(even):hover { background: var(--blue-light); }

.col-rank  { width: 44px; text-align: center; }
.col-media { text-align: center; }
.col-pct   { text-align: center; }
.col-turma { width: 60px; text-align: center; }

.td-rank {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  font-size: .8rem;
}
.col-cgm  { width: 110px; }
.td-cgm   { font-family: monospace; font-size: .85em; color: var(--muted); }
.td-name  { font-weight: 600; }
.td-school { font-size: .82rem; max-width: 220px; }
.td-city   { font-size: .82rem; white-space: nowrap; }
.td-nre    { font-size: .75rem; color: var(--muted); max-width: 180px; line-height: 1.3; }
.td-media {
  text-align: center;
  font-weight: 700;
  color: var(--blue);
}
.td-pct {
  text-align: center;
  font-size: .82rem;
  white-space: nowrap;
}
.td-turma { text-align: center; font-size: .82rem; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.pg-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.pg-btn:hover { border-color: var(--green); color: var(--green-dark); }
.pg-btn.active {
  background: linear-gradient(135deg, var(--green), var(--teal));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,193,65,.30);
}
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.pg-info {
  font-size: .82rem;
  color: var(--muted);
  padding: 0 6px;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 20px;
  font-size: .78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #fff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .header { padding: 12px 16px 44px; }
  .header-logo { height: 50px; }
  .filter-card { margin-top: -24px; }
  .card-title-main { font-size: 1rem; }
  .card-brand { margin-bottom: 16px; padding-bottom: 14px; }
  .card { padding: 16px; }
  .filter-grid { grid-template-columns: 1fr; }
  .filter-search { grid-column: 1; }
  .search-primary .search-wrap input { height: 46px; font-size: .92rem; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .btn-download { width: 100%; justify-content: center; }
}

/* ===== RECURSOS — toolbar e tabela ===== */
.recursos-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}
.recursos-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.rec-select {
  height: 42px;
  padding: 0 32px 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-family: var(--font);
  font-size: .88rem;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1l5 5 5-5' stroke='%235a6b8a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.rec-select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(0,193,65,.15);
}
@media (max-width: 720px) {
  .recursos-toolbar { grid-template-columns: 1fr; }
}

.rec-summary {
  margin-left: 12px;
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
}

.recursos-table { min-width: 1100px; }
.recursos-table .td-name  { font-weight: 600; }
.recursos-table .td-cgm   { font-family: monospace; font-size: .82em; color: var(--muted); white-space: nowrap; }
.recursos-table .td-school small { display: block; font-size: .72rem; color: var(--muted); margin-top: 2px; }
.recursos-table .td-nota-pr  { text-align: center; font-weight: 600; color: var(--blue); }
.recursos-table .td-pct-pr   { text-align: center; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.recursos-table .td-media-rec {
  text-align: center;
  font-weight: 800;
  color: var(--green-dark);
  font-size: .95rem;
}
.recursos-table .nivel-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 50px;
  background: var(--blue-light);
  color: var(--blue-dark);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .5px;
}
.recursos-table .status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 50px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  white-space: nowrap;
}
.recursos-table .status-pill.classificado {
  background: var(--green-light);
  color: var(--green-dark);
}
.recursos-table .status-pill.nao-classificado {
  background: #fff3e0;
  color: #c25700;
}
.recursos-table .cgm-warn {
  display: inline-block;
  margin-left: 4px;
  font-size: .68rem;
  color: #c25700;
  font-weight: 600;
}
.recursos-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

/* ===== RESULTADO FINAL — destaque de notas alteradas via recurso ===== */
.results-table td.changed {
  background: linear-gradient(0deg, rgba(0,193,65,.08), rgba(0,193,65,.08));
}
.results-table tr.recurso-row .td-name::after {
  content: "RECURSO";
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 50px;
  background: var(--green-light);
  color: var(--green-dark);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .5px;
  vertical-align: middle;
}
.grade-old {
  color: var(--muted);
  text-decoration: line-through;
  font-weight: 500;
  font-size: .9em;
  margin-right: 4px;
}
.grade-sep {
  color: var(--muted);
  margin: 0 2px;
}
.grade-new {
  color: var(--green-dark);
  font-weight: 700;
}
