/* ============================================================
   NOTAS ALUMNOS — Estilos principales
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --text-muted:#64748b;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --green:     #16a34a;
  --green-bg:  #dcfce7;
  --yellow:    #ca8a04;
  --yellow-bg: #fef9c3;
  --red:       #dc2626;
  --red-bg:    #fee2e2;
  --gray:      #94a3b8;
  --gray-bg:   #f1f5f9;
  --radius:    12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem 4rem;
}

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  text-align: center;
  margin-bottom: 2.5rem;
  max-width: 640px;
  width: 100%;
}
.app-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
}
.app-header p {
  margin-top: .5rem;
  color: var(--text-muted);
  font-size: .95rem;
}

/* ── Tarjeta base ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 640px;
}

/* ── Formulario ──────────────────────────────────────────── */
.search-card { margin-bottom: 1.5rem; }

.form-group { display: flex; gap: .75rem; flex-wrap: wrap; }

.input-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.input-wrapper svg {
  position: absolute;
  left: .875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#dniInput {
  width: 100%;
  padding: .75rem .875rem .75rem 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  background: var(--surface);
}
#dniInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
#dniInput.error { border-color: var(--red); }

.btn-search {
  padding: .75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.btn-search:hover  { background: var(--accent-h); }
.btn-search:active { transform: scale(.97); }
.btn-search:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.select-trimestre {
  width: 100%;
  margin-top: .75rem;
  padding: .6rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
}
.select-trimestre:focus { border-color: var(--accent); }

.input-hint {
  margin-top: .5rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.error-msg {
  color: var(--red);
  font-size: .85rem;
  margin-top: .4rem;
  display: none;
}
.error-msg.visible { display: block; }

/* ── Loading ─────────────────────────────────────────────── */
.loading {
  display: none;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 2rem;
  color: var(--text-muted);
}
.loading.visible { display: flex; }

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Resultado alumno ────────────────────────────────────── */
#results { display: none; }
#results.visible { display: block; }

.student-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.student-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.student-info h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}
.student-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .35rem;
}
.meta-badge {
  font-size: .78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem .65rem;
  color: var(--text-muted);
}
.trimestre-badge {
  font-size: .78rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: .2rem .65rem;
  color: var(--accent);
  font-weight: 600;
}

/* ── Tabla de notas ──────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
thead { background: var(--bg); }
th {
  text-align: left;
  padding: .75rem 1rem;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

.nota-val {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  padding: .2rem .45rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: .85rem;
  background: var(--gray-bg);
  color: var(--text);
}
.nota-sin { color: var(--gray); font-style: italic; font-size: .8rem; font-weight: 400; }

.concepto-tag {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Badges de estado ────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-aprobado { background: var(--green-bg);  color: var(--green);  }
.badge-regular  { background: var(--yellow-bg); color: var(--yellow); }
.badge-libre    { background: var(--red-bg);    color: var(--red);    }
.badge-sin      { background: var(--gray-bg);   color: var(--gray);   }
.badge-pendiente { background: #dbeafe; color: #1d4ed8; }

.nc-verde       { background: #16a34a; color: #fff; }
.nc-verde-claro { background: #65a30d; color: #fff; }
.nc-amarillo    { background: #ca8a04; color: #fff; }
.nc-naranja     { background: #ea580c; color: #fff; }
.nc-rojo        { background: #dc2626; color: #fff; }

/* ── Resumen ─────────────────────────────────────────────── */
.summary {
  display: flex;
  gap: .75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.summary-item {
  flex: 1;
  min-width: 90px;
  text-align: center;
  padding: .75rem .5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.summary-item .s-count {
  font-size: 1.5rem;
  font-weight: 700;
  display: block;
}
.summary-item .s-label {
  font-size: .72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.si-aprobado { background: var(--green-bg);  border-color: #bbf7d0; }
.si-aprobado .s-count { color: var(--green); }
.si-regular  { background: var(--yellow-bg); border-color: #fef08a; }
.si-regular  .s-count { color: var(--yellow); }
.si-libre    { background: var(--red-bg);    border-color: #fecaca; }
.si-libre    .s-count { color: var(--red); }

/* ── Error global ────────────────────────────────────────── */
.alert {
  display: none;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  font-size: .9rem;
  margin-bottom: 1.5rem;
  max-width: 640px;
  width: 100%;
  align-items: flex-start;
  gap: .75rem;
}
.alert.visible { display: flex; }
.alert-error   { background: var(--red-bg);    border: 1px solid #fecaca; color: var(--red); }
.alert-warning { background: var(--yellow-bg); border: 1px solid #fde68a; color: #92400e; }

/* ── Footer ──────────────────────────────────────────────── */
.app-footer {
  margin-top: 3rem;
  color: var(--text-muted);
  font-size: .8rem;
  text-align: center;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: .25rem;
}
.topbar-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.btn-logout {
  padding: .45rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s, color .15s;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

.empty-msg { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-size: .9rem; }

/* ── Layout de pantalla ancha ────────────────────────────── */
.layout-wrap {
  width: 100%;
  max-width: 1400px;
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout-wrap { grid-template-columns: 200px 1fr; }
}
.layout-wrap .topbar  { grid-column: 1 / -1; }
.layout-wrap .alert   { grid-column: 1 / -1; max-width: none; }
.layout-wrap .card    { max-width: none; }

.sidebar-card {
  position: sticky;
  top: 1.25rem;
}
.sidebar-card .student-header {
  flex-direction: column;
  gap: .75rem;
}
.sidebar-card .summary {
  margin-top: 1.25rem;
  flex-direction: column;
  gap: .6rem;
}
.sidebar-card .summary-item {
  flex: none;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  text-align: left;
  padding: .6rem .85rem;
}
.sidebar-card .summary-item .s-count {
  font-size: 1.25rem;
  min-width: 2rem;
  text-align: center;
}
.sidebar-card .summary-item .s-label {
  font-size: .8rem;
}

.main-card { min-width: 0; }
.main-card .table-wrapper { border: none; border-radius: 0; margin: -2rem; }
.main-card table { font-size: .82rem; table-layout: auto; }
.main-card th, .main-card td { padding: .55rem .7rem; }
.main-card th:first-child, .main-card td:first-child { min-width: 130px; }
.main-card th:not(:first-child) { text-align: center; white-space: nowrap; }
.main-card td:not(:first-child) { text-align: center; white-space: nowrap; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .layout-wrap { grid-template-columns: 1fr; }
  .sidebar-card { position: static; }
  .sidebar-card .student-header { flex-direction: row; }
  .sidebar-card .summary { flex-direction: row; flex-wrap: wrap; }
  .sidebar-card .summary-item { flex: 1; min-width: 80px; flex-direction: column; text-align: center; gap: 0; padding: .6rem .5rem; }
  .sidebar-card .summary-item .s-count { min-width: 0; }
  .main-card .table-wrapper { margin: -1.5rem; }
  .main-card th, .main-card td { padding: .5rem .55rem; }
  .main-card table { font-size: .78rem; }
}

@media (max-width: 480px) {
  body { padding: 1rem .5rem 3rem; }
  .card { padding: 1.25rem .75rem; }
  .main-card .table-wrapper { margin: -.75rem; }
  .main-card th, .main-card td { padding: .45rem .4rem; }
  .main-card table { font-size: .74rem; }
  .nota-val { min-width: 1.8rem; font-size: .78rem; }
}