@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --surface3: #282828;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #666;
  --text-dim: #999;
  --accent: #5E5CE6;
  --accent-hover: #7D7AFF;
  --accent-soft: rgba(94,92,230,0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,0.12);
  --success: #22c55e;
  --success-soft: rgba(34,197,94,0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245,158,11,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --bottom-nav-h: 68px;
}

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

html { font-size: 16px; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
}

/* ── LAYOUT ─────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

.top-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}

.top-bar h1 {
  font-size: 1rem; font-weight: 600; letter-spacing: -0.01em;
}

.trimestre-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.8rem; font-weight: 500; color: var(--accent);
  transition: background 0.2s;
}
.trimestre-selector:hover { background: var(--surface3); }
.trimestre-selector span { font-size: 0.65rem; color: var(--text-muted); }

.main-content {
  margin-top: var(--nav-h);
  margin-bottom: var(--bottom-nav-h);
  flex: 1;
  overflow-y: auto;
}

.page { display: none; padding: 20px; }
.page.active { display: block; }

/* ── BOTTOM NAV ─────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--bottom-nav-h);
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.2s;
  color: var(--text-muted); font-size: 0.65rem; font-weight: 500;
  border: none; background: none; flex: 1;
}
.nav-item .icon { font-size: 1.3rem; line-height: 1; }
.nav-item.active { color: var(--accent); }
.nav-item.active .icon { filter: drop-shadow(0 0 8px var(--accent)); }

/* ── ASIGNATURAS ────────────────────────── */
.asignaturas-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.asignatura-card {
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
}
.asignatura-card:active { transform: scale(0.97); }

.asignatura-card .cover {
  height: 100px;
  object-fit: cover;
  width: 100%;
  display: block;
}

.asignatura-card .cover-fallback {
  height: 100px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
}

.asignatura-card .info {
  padding: 10px 12px;
}
.asignatura-card .nombre {
  font-size: 0.8rem; font-weight: 600; line-height: 1.3;
  margin-bottom: 6px;
}
.asignatura-card .stats {
  display: flex; gap: 8px;
}
.stat-badge {
  font-size: 0.65rem; padding: 2px 8px;
  border-radius: 20px; font-weight: 500;
  background: var(--surface2); color: var(--text-dim);
  display: flex; align-items: center; gap: 3px;
}

/* ── DETALLE ASIGNATURA ─────────────────── */
.back-btn {
  display: flex; align-items: center; gap: 6px;
  color: var(--accent); font-size: 0.85rem; font-weight: 500;
  cursor: pointer; margin-bottom: 20px;
  background: none; border: none; padding: 0;
}

.asignatura-header {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  position: relative;
}
.asignatura-header img {
  width: 100%; height: 140px; object-fit: cover; display: block;
}
.asignatura-header .overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 20px 16px 14px;
}
.asignatura-header h2 { font-size: 1.1rem; font-weight: 700; }

.tabs {
  display: flex; gap: 4px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
}
.tab {
  flex: 1; padding: 7px 4px;
  border-radius: 6px; border: none; background: none;
  color: var(--text-muted); font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s; text-align: center;
}
.tab.active { background: var(--surface3); color: var(--text); }

/* ── CARDS GENÉRICAS ────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.card-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}

.card-title { font-size: 0.85rem; font-weight: 600; }
.card-sub { font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; }

.nota-num {
  font-size: 1.4rem; font-weight: 700; color: var(--accent);
  min-width: 40px; text-align: right;
}

.badge {
  font-size: 0.65rem; padding: 3px 8px;
  border-radius: 20px; font-weight: 600; white-space: nowrap;
}
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-muted { background: var(--surface2); color: var(--text-muted); }

/* ── TAREAS ─────────────────────────────── */
.tarea-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex; align-items: flex-start; gap: 12px;
}
.tarea-check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; margin-top: 1px;
}
.tarea-check.done {
  background: var(--success); border-color: var(--success);
  color: white; font-size: 0.7rem;
}
.tarea-info { flex: 1; min-width: 0; }
.tarea-titulo { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.tarea-titulo.done { text-decoration: line-through; color: var(--text-muted); }
.tarea-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── FORMULARIOS ────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%; max-width: 520px;
  max-height: 85dvh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: none;
  color: var(--text-muted); cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
}

.form-group { margin-bottom: 14px; }
.form-label { font-size: 0.75rem; color: var(--text-dim); margin-bottom: 6px; display: block; font-weight: 500; }
.form-control {
  width: 100%; padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 0.85rem; font-family: inherit;
  transition: border-color 0.2s; outline: none;
}
.form-control:focus { border-color: var(--accent); }

select.form-control { appearance: none; cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  padding: 11px 20px; border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  border: none; transition: all 0.2s; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: white; width: 100%; margin-top: 6px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger-sm {
  background: var(--danger-soft); color: var(--danger);
  padding: 5px 10px; font-size: 0.7rem; border-radius: 6px;
}

/* ── FAB ─────────────────────────────────── */
.fab {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); right: 20px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 1.5rem; border: none; cursor: pointer;
  box-shadow: 0 4px 20px rgba(94,92,230,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; z-index: 50;
}
.fab:active { transform: scale(0.93); }

/* ── HORARIO ─────────────────────────────── */
.horario-table { width: 100%; border-collapse: collapse; }
.horario-table th {
  font-size: 0.65rem; font-weight: 600; color: var(--text-muted);
  padding: 8px 4px; text-align: center;
  border-bottom: 1px solid var(--border);
}
.horario-table td {
  padding: 6px 4px; text-align: center;
  border: 1px solid var(--border);
  font-size: 0.65rem;
}
.horario-table td:first-child {
  color: var(--text-muted); font-weight: 500;
  background: var(--surface); width: 36px;
}
.horario-cell {
  background: var(--surface2); border-radius: 4px;
  min-height: 36px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.2s; padding: 2px;
  font-size: 0.6rem; line-height: 1.2; color: var(--text-dim);
}
.horario-cell.filled { color: var(--text); background: var(--accent-soft); }
.horario-cell:active { background: var(--surface3); }

/* ── NOTAS CÁLCULO ──────────────────────── */
.calc-box {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  text-align: center;
}
.calc-box .label { font-size: 0.7rem; color: var(--accent); margin-bottom: 4px; }
.calc-box .value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.calc-box .sublabel { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

/* ── TRIMESTRE MODAL ────────────────────── */
.trimestre-option {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  transition: background 0.2s;
  margin-bottom: 6px;
}
.trimestre-option:hover { background: var(--surface2); }
.trimestre-option.selected { background: var(--accent-soft); color: var(--accent); }

/* ── EMPTY STATE ─────────────────────────── */
.empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: 0.85rem;
}
.empty .icon { font-size: 2.5rem; margin-bottom: 10px; }

/* ── SECCION TITULO ─────────────────────── */
.section-title {
  font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 12px; margin-top: 20px;
}
.section-title:first-child { margin-top: 0; }

/* ── TOAST ───────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 20px;
  font-size: 0.8rem; font-weight: 500;
  opacity: 0; transition: all 0.3s; z-index: 300; white-space: nowrap;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── RESPONSIVE ──────────────────────────── */
@media (min-width: 480px) {
  .asignaturas-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .main-content { max-width: 600px; margin-left: auto; margin-right: auto; }
  .top-bar, .bottom-nav { max-width: 600px; left: 50%; transform: translateX(-50%); right: auto; width: 100%; }
  .fab { right: calc(50% - 280px); }
  .modal { border-radius: var(--radius); }
  .modal-overlay { align-items: center; }
}
