:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secundario: #6b6b6b;
  --borde: #e0e0e0;
  --primario: #2563eb;
  --primario-texto: #ffffff;
  --verde: #22c55e;
  --amarillo: #eab308;
  --rojo: #ef4444;
  --gris-completada: #9ca3af;
  --error-bg: #fef2f2;
  --error-texto: #b91c1c;
  --radio: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #f0f0f0;
    --text-secundario: #a0a0a0;
    --borde: #333333;
    --primario: #3b82f6;
    --primario-texto: #ffffff;
    --error-bg: #3a1a1a;
    --error-texto: #fca5a5;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 2rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  gap: 0.5rem;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  border: none;
  border-radius: var(--radio);
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary {
  background: var(--primario);
  color: var(--primario-texto);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--borde);
}

.btn-icono {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
  color: var(--text-secundario);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}

.tab {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secundario);
}

.tab.active {
  background: var(--primario);
  color: var(--primario-texto);
  border-color: var(--primario);
}

main {
  padding: 0 1rem;
}

.lista-tareas {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tarea {
  background: var(--surface);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.semaforo {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.semaforo.verde { background: var(--verde); }
.semaforo.amarillo { background: var(--amarillo); }
.semaforo.rojo { background: var(--rojo); }
.semaforo.completada { background: var(--gris-completada); }

.tarea-info {
  flex: 1;
  min-width: 0;
}

.tarea-nombre {
  font-weight: 600;
  display: block;
}

.tarea-meta {
  font-size: 0.8rem;
  color: var(--text-secundario);
  display: block;
}

.tarea-nota {
  font-size: 0.85rem;
  color: var(--text-secundario);
  white-space: nowrap;
}

.tarea-acciones {
  display: flex;
  gap: 0.25rem;
}

.mensaje-vacio,
.mensaje-error {
  text-align: center;
  color: var(--text-secundario);
  padding: 1rem;
}

.mensaje-error {
  background: var(--error-bg);
  color: var(--error-texto);
  border-radius: var(--radio);
}

.texto-secundario {
  color: var(--text-secundario);
  font-size: 0.9rem;
}

/* Modales */
.modal {
  border: none;
  border-radius: var(--radio);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 420px;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.modal form,
.modal .modal-contenido {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-secundario);
}

.modal input,
.modal select,
.modal textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--borde);
  background: var(--bg);
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.form-inline {
  display: flex;
  gap: 0.5rem;
}

.form-inline input {
  flex: 1;
}

.lista-materias {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.materia-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--borde);
}

.materia-item input[type="text"] {
  flex: 1;
}

.materia-nombre {
  flex: 1;
}

@media (max-width: 480px) {
  .modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .modal form,
  .modal .modal-contenido {
    height: 100%;
  }
}
