/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Common */
  --radius:     16px;
  --primary:    #6366f1;
  --primary-h:  #4f46e5;
  --success:    #10b981;
  --warning:    #f59e0b;
  --danger:     #ef4444;
  --secondary:  #64748b;
  
  /* Light Theme (Default) */
  --bg:         #f8fafc;
  --bg2:        #f1f5f9;
  --surface:    rgba(255,255,255,0.7);
  --border:     rgba(0,0,0,0.06);
  --text:       #0f172a;
  --text-muted: #64748b;
  --shadow:     0 10px 40px rgba(0,0,0,0.06);
  --glass-bg:   rgba(255,255,255,0.8);
}

:root[data-theme="dark"] {
  --bg:         #0f0f1a;
  --bg2:        #16162a;
  --surface:    rgba(255,255,255,0.05);
  --border:     rgba(255,255,255,0.08);
  --text:       #e2e2f0;
  --text-muted: #7b7b9a;
  --shadow:     0 4px 32px rgba(0,0,0,0.4);
  --glass-bg:   rgba(15,15,26,0.8);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(99,102,241,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 80%, rgba(139,92,246,0.08) 0%, transparent 60%);
  display: flex;
  flex-direction: column;
}

body.is-login {
  overflow: hidden;
}

.app-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

body.is-login .app-wrapper {
  height: 100vh;
  justify-content: center;
  align-items: center;
}

body.is-login .app-header {
  position: absolute;
  background: transparent;
  border-bottom: none;
  backdrop-filter: none;
  width: 100%;
}

body.is-login .main-container {
  padding: 0 24px;
  width: 100%;
}

body.is-login .panel {
  max-width: 480px;
  margin: 0 auto;
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  background: var(--glass-bg);
  position: sticky; top: 0; z-index: 100;
  transition: background 0.3s ease;
}
.header-inner {
  max-width: 900px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.1rem; font-weight: 500; color: var(--text);
}
.logo strong { color: var(--primary); font-weight: 800; }
.header-right { display: flex; align-items: center; gap: 20px; }
.header-meta { font-size: 0.82rem; color: var(--text-muted); }

.student-info { display: flex; align-items: center; gap: 12px; text-align: right; }
.student-text { display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
.student-photo {
  width: 42px; height: 42px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--border); background-color: var(--bg2); flex-shrink: 0;
}
.student-name { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.student-course { font-size: 0.72rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }

/* Theme Toggle */
.theme-toggle {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.theme-toggle:hover {
  background: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }

:root[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
:root[data-theme="dark"] .theme-toggle .moon-icon { display: none; }

/* ── Main container ──────────────────────────────────────────────────────── */
.main-container {
  max-width: 900px; margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ── Glass panel ─────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel-icon { font-size: 2.8rem; margin-bottom: 16px; }
.panel-title { font-size: 1.7rem; font-weight: 700; margin-bottom: 8px; }
.panel-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 32px; line-height: 1.6; }

/* ── Login form ──────────────────────────────────────────────────────────── */
.login-form { display: flex; flex-direction: column; gap: 18px; }

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

input[type="text"], input[type="password"] {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit; font-size: 0.95rem;
  padding: 12px 16px;
  transition: border-color .2s, box-shadow .2s, background 0.3s ease;
  outline: none; width: 100%;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 48px; }
.show-pass {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px; transition: color .2s;
}
.show-pass:hover { color: var(--text); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border: none; border-radius: 10px;
  color: white; cursor: pointer;
  font-family: inherit; font-size: 1rem; font-weight: 600;
  padding: 14px 24px; margin-top: 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .15s, box-shadow .15s, opacity .2s;
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(99,102,241,0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); cursor: pointer;
  font-family: inherit; font-size: 0.9rem; font-weight: 500;
  padding: 10px 20px;
  transition: background .2s, border-color .2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }

.login-footer {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.security-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.official-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.2s;
}
.official-link:hover {
  background: rgba(99,102,241,0.1);
}

/* ── Progress panel ──────────────────────────────────────────────────────── */
.progress-header {
  display: flex; align-items: center; gap: 16px; margin-bottom: 24px;
}
.progress-header h2 { font-size: 1.2rem; font-weight: 600; }

.spinner {
  width: 28px; height: 28px; flex-shrink: 0;
  border: 3px solid rgba(99,102,241,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-log {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 300px; overflow-y: auto;
  font-size: 0.875rem;
}
.log-item {
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  color: var(--text-muted);
  animation: fadeIn .3s ease;
}
.log-item.error { border-left-color: var(--danger); color: #fca5a5; }
.log-item.done  { border-left-color: var(--success); color: #6ee7b7; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Summary cards ───────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.summary-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 18px;
  display: flex; flex-direction: column; gap: 4px;
  transition: transform .2s, box-shadow .2s;
}
.summary-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.summary-card .card-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.summary-card .card-value { font-size: 2rem; font-weight: 800; }
.summary-card .card-value.success { color: var(--success); }
.summary-card .card-value.warning { color: var(--warning); }
.summary-card .card-value.danger  { color: var(--danger); }
.summary-card .card-value.primary { color: var(--primary); }

/* ── Evaluation Selector ──────────────────────────────────────────────────── */
.eval-selector-container {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}
.eval-tabs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  display: flex;
  gap: 4px;
}
.eval-tab {
  background: none; border: none;
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.eval-tab:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.eval-tab.active { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(99,102,241,0.3); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.filter-bar input {
  flex: 1; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-family: inherit; font-size: 0.9rem;
  padding: 10px 16px; outline: none;
  transition: border-color .2s;
}
.filter-bar input:focus { border-color: var(--primary); }

.filter-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-muted);
  cursor: pointer; font-family: inherit; font-size: 0.82rem; font-weight: 500;
  padding: 7px 14px; transition: all .2s;
}
.tab:hover  { color: var(--text); border-color: rgba(255,255,255,0.2); }
.tab.active { background: var(--primary); border-color: var(--primary); color: white; }

/* ── Subjects list ───────────────────────────────────────────────────────── */
.subjects-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }

.subject-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  transition: box-shadow .2s;
}
.subject-card:hover { box-shadow: var(--shadow); }

.subject-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; cursor: pointer; gap: 12px;
  user-select: none; transition: background .2s;
}
.subject-header:hover { background: rgba(255,255,255,0.04); }

.subject-left { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }

.grade-badge {
  min-width: 54px; height: 54px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; font-weight: 800; flex-shrink: 0;
}
.grade-badge.success { background: rgba(16,185,129,0.15); color: var(--success); border: 1.5px solid rgba(16,185,129,0.3); }
.grade-badge.warning { background: rgba(245,158,11,0.15); color: var(--warning); border: 1.5px solid rgba(245,158,11,0.3); }
.grade-badge.danger  { background: rgba(239,68,68,0.15);  color: var(--danger);  border: 1.5px solid rgba(239,68,68,0.3); }
.grade-badge.secondary { background: rgba(107,114,128,0.15); color: var(--secondary); border: 1.5px solid rgba(107,114,128,0.3); }

.subject-info { flex: 1; min-width: 0; }
.subject-name { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.subject-right { display: flex; align-items: center; gap: 12px; }

.nivel-tag {
  font-size: 0.72rem; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; white-space: nowrap;
}
.nivel-tag.success { background: rgba(16,185,129,0.15); color: var(--success); }
.nivel-tag.warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.nivel-tag.danger  { background: rgba(239,68,68,0.15);  color: var(--danger); }
.nivel-tag.secondary { background: rgba(107,114,128,0.15); color: var(--secondary); }

.chevron { color: var(--text-muted); transition: transform .25s; flex-shrink: 0; }
.subject-card.open .chevron { transform: rotate(90deg); }

/* ── Subject detail ──────────────────────────────────────────────────────── */
.subject-detail {
  border-top: 1px solid var(--border);
  padding: 0 20px;
  max-height: 0; overflow: hidden;
  transition: max-height .35s ease, padding .25s;
}
.subject-card.open .subject-detail {
  max-height: 2000px;
  padding: 20px 20px 24px;
}

.detail-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.detail-tab {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted); cursor: pointer;
  font-family: inherit; font-size: 0.78rem; font-weight: 500;
  padding: 5px 12px; transition: all .2s;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active { background: rgba(99,102,241,0.2); border-color: var(--primary); color: var(--primary); }

.detail-section { display: none; }
.detail-section.active { display: block; }

/* Criteria table */
.criteria-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.criteria-table th {
  text-align: left; padding: 8px 10px; color: var(--text-muted);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.criteria-table td { padding: 9px 10px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.criteria-table tr:last-child td { border-bottom: none; }
.criteria-table tr:hover td { background: rgba(255,255,255,0.03); }

.peso-bar-wrap { display: flex; align-items: center; gap: 8px; }
.peso-bar { height: 6px; border-radius: 3px; background: rgba(99,102,241,0.6); }
.peso-text { font-size: 0.78rem; color: var(--text-muted); min-width: 30px; }

.nivel-pill {
  display: inline-block; font-size: 0.7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 20px; white-space: nowrap;
}
.nivel-pill.Completamente, .nivel-pill.Completament   { background: rgba(16,185,129,0.2); color: #34d399; }
.nivel-pill.Mayoritariamente, .nivel-pill.Majoritàriament { background: rgba(99,102,241,0.2); color: #a5b4fc; }
.nivel-pill.Suficientemente, .nivel-pill.Suficientment { background: rgba(245,158,11,0.2); color: #fcd34d; }
.nivel-pill.Poco, .nivel-pill.Poc                     { background: rgba(239,68,68,0.15); color: #fca5a5; }
.nivel-pill.Nada, .nivel-pill.Gens                    { background: rgba(107,114,128,0.2); color: #9ca3af; }

/* Partial grades list */
.periodo-group { margin-bottom: 16px; }
.periodo-title { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.tarea-item {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.03); margin-bottom: 8px; font-size: 0.85rem;
  border: 1px solid var(--border);
}
.tarea-header { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 12px; }
.tarea-desc { flex: 1; min-width: 0; line-height: 1.5; color: var(--text); font-weight: 500; }
.tarea-weight { 
  font-size: 0.68rem; font-weight: 700; background: var(--primary); color: white; 
  padding: 2px 6px; border-radius: 4px; opacity: 0.9;
}
.tarea-fecha { font-size: 0.72rem; color: var(--text-muted); }
.tarea-nota {
  font-weight: 800; font-size: 1.1rem; min-width: 40px; text-align: right;
}
.tarea-nota.s { color: var(--success); }
.tarea-nota.w { color: var(--warning); }
.tarea-nota.d { color: var(--danger); }

.tarea-footer { display: flex; justify-content: flex-end; width: 100%; margin-top: 2px; }

/* ── Valoraciones Globales ───────────────────────────────────────────────── */
.valoraciones-globales {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.valoracion-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.valoracion-card h4 {
  margin-bottom: 15px;
  color: var(--text1);
}
.val-header {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  gap: 4px;
}
.val-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--primary);
}
.val-author {
  font-size: 0.8rem;
  color: var(--text2);
}
.val-text {
  color: var(--text1);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Results actions ─────────────────────────────────────────────────────── */
.results-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-container { padding: 24px 16px 60px; }
  .panel { padding: 32px 20px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .subject-right .nivel-tag { display: none; }
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  body { background: white; color: black; }
  .app-header, .filter-bar, .results-actions, .chevron, .detail-tabs { display: none; }
  .subject-detail { max-height: none !important; padding: 16px !important; }
  .subject-card { border: 1px solid #ddd; break-inside: avoid; margin-bottom: 12px; }
}

/* ── Notification Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: -150px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  padding: 16px 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 1000;
  transition: bottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text);
  max-width: 90%;
  width: 400px;
}
.toast.show { bottom: 24px; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.5rem; transition: color 0.2s; }
.toast-close:hover { color: var(--text); }
.toast-content { flex: 1; font-size: 0.95rem; }
.toast-content strong { color: var(--primary); }

/* ── Extra Mobile Responsiveness ─────────────────────────────────────────── */
@media (max-width: 650px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .user-badge {
    flex: 1;
    font-size: 0.85rem;
  }
  .user-course {
    display: none; /* Hide course on small screens to save space */
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-tabs {
    overflow-x: auto;
    padding-bottom: 4px; /* for scrollbar */
    justify-content: flex-start;
  }
  .subject-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .grade-badge.large {
    align-self: flex-end;
    margin-top: -30px;
  }
}
